View¶
A view instance is automatically created when one is specified on an action,
after the action returns a value. The return value is used as the model and
passed to the Print()
method of the View()
instance. Like
injectables and controllers, the view can also inject dependencies through the
constructor.
-
class
View
()¶ interface, exported from
ommander-mv
To be used as the view of an Action.
-
View.
print
(model)¶ Prints the given model.
Arguments: - model (any) – The model to print. When used as the view of an Action this will be passed the return value of that action.
-
Note
You do not need to include views in ContextInitialization.providers
when initializing the context. Just reference the view in the Action()
decorators that use them.
Example¶
export class View {
constructor ({ printerService }) {
this.printer = printerService
}
print (accounts) {
accounts.forEach(account => {
this.printerService.printHeader(account.name)
this.printerService.printYellow(account.balance)
this.printerService.printGreen(account.clearedBalance)
this.printerService.printRed(account.unclearedBalance)
})
}
}