@candywings/pure-mvc
v1.1.2
Published
PureMVC is a lightweight framework for creating applications based upon the classic Model-View-Controller design meta-pattern
Downloads
36
Readme
pure MVC
how to install
npm i @candywings/pure-mvc@latest
About
Based on standard Model-View-Controller architecture with extended functionality in TypeScript.
Added functionalities.
- Mediator have
sleep():void
andwake():void
functions, which give ability to stop and start mediator from listening notifications dynamically. - Mediator have
subscribeToNotifications(...notificationNames: string[]):void
andunsubscribeToNotification(notificationName: string):void
functions, which give ability to dynamically subscribe and unsubscribe listening notifications.listenNotificationInterests: string[]
now is agetter
not afunction
. - Now it's allowed to have same mediator-view pairs, so for every mediator instance unique id will be generated, which is available in mediator in
id: number | string
property. - Now mediator has
setMediatorId(id: number| string):void
function to set id manually to sync mediator with object inVO
andgetMediatorId(): number | string
to get it; - Now
facade.retrieveMediator(mediatorName: string, id?: number| string):Mediator
function has optional second propertyid: number | string
. It's for cases where you have multiple instances of same mediator-view pairs. UsingretrieveMediator
function without givingid: number | string
argument, it will return first mediator from mediators with given name. - Now
Facade
has methodshasMediatorWithName(mediatorName: string):boolean
, which will check if there is at least one mediator with given name, and methodretrieveMediators(mediatorName:string): Mediator[]
, which will return all mediators with given name. - Now facade has new function
getMediatorsCount(mediatorName: string): number
which returns count of Mediator with same name. It's for cases, when you want to write you own logic based on Mediator count. - Mediator have
index:number
property which shows the index in the same name mediators' list. - Same notification can call multiple commands. Functions are added to remove commands from notification's call queue. To remove single command from call queue call
removeCommand(notificationName:string, command:SimpleCommand):void
on facade, and to remove all commands from notification's queue callremoveCommands(notificationName: string):void
on facade. - To register command to work once use
registerCommandOnce(notificationName, command):void
on facade. It will be called only once, then it will be removed from commands queue. - Added
Guard
for command, it can be used to make checks before command willexecute
, it has reference toFacade
too.Guard
hasabstract approve(notificationName: string, ...args: any[]):boolean | Promise<boolean>
function which must be overridden. Async usage ofapprove
function is possible. - Added
addGuard(...guardClassRefs: Guard[]):void
,Guard
classes (not their instances) need to be given as arguments. - Added
onAnyGuardApproved(notificationName: string, ...args: any[]):void
,onAnyGuardDenied(notificationName, ...args: any[]):void
andonAllGuardsDenied(notificationName, ...args: any[]):void
functions for handling guards approving cases. - Command has protected method
prepare():void
, which is provided to add guards. - Command execution is being done in following sequence,
prepare -> checkGuards -> execute || onAnyGuardDenied && onAllGuardDenied
- MacroCommands now can add
exclusiveSubCommands
, so if on of added subCommands is approved, others won't event checked. To addexclusiveSubCommand
calladdExclusiveSubCommand(command, ...guards)
. Note thatexclusiveSubCommand
's check is checking subCommand's self guards too. Even if you've added duplicate guards, exclusiveSubCommand checker will check only unique guards. - Added
registerMediators
andremoveMediators
functions. - Mediator has new method
subscribeToNotification
not to usesubscribeToNotifications
when subcribing to one notification.