- `self._view` is the HTML view renderered by `yo-yo` in the `render` function.
- `render()` this function should be called:
* At the first rendering (make sure that the returned node element is put on the DOM).
- `render()` this function should be called at the first rendering (make sure that the returned node element is put on the DOM), and should *not* by called again from outside the component.
- `update()` call this function to update the DOM when the state of the component has changed (this function must be called after the initial call to `render()`).
- for all functions / properties, prefixing by underscore (`_`) means the scope is private, and they should **not** be accessed not changed from outside the component.
- constructor arguments: There is no fixed rule whether it is preferrable to use multiples arguments or a single option *{}* argument (or both).
We recommend:
- use a specific slot for **obligatory** arguments and/or for complex arguments (meaning not boolean, not string, etc...).
- put arguments in an option *{}* for non critical and for optionnal arguments.
- if a component has more than 4/5 parameters, it is recommended to find a way to group some in one or more *opt* arguments.
* When some property has changed in order to update the view.
- `self.state` contains state properties of the module. These properties are either given from the parent through `òpts` or computed during the life of the object.
- `update(state)` allow the parent to easily update some of the state properties.
- for all functions / properties, prefixing by underscore (`_`) means the scope is private.
- look them up, discuss them, update them.
## Module Definition (example)
@ -53,21 +52,14 @@ var css = csjs`
`
class UserCard {
constructor (opts = {}) {
constructor (api, events, opts = {}) {
var self = this
self.event = new EventManager()
self._api = opts.api
self.opts = opts
self._api = api
self._consumedEvents = events
self._view = undefined
self.state = {
title: opts.title,
name: opts.name,
surname: opts.surname,
totalSpend: 0,
_nickname: opts.nickname,
_funds: self._api.getUserFunds()
}
var events = opts.events
events.funds.register('fundsChanged', function (amount) {
if (amount <self.state._funds)self.state.totalSpend+=self.state._funds-amount