First define your component:
- value types and defaults for each key
- 'channels', actions that potentially modify state or perform i/o. triggered by button presses, mouse movements, etc
var Value = require('observ')
var Component = require('../lib/component.js')
var Wallet = require('../wallet/index.js')
var Identity = require('../identity/index.js')
var render = require('./render.js')
module.exports = Component({
// simple values, arrays
currentView: { type: Value, default: 'wallet' },
// other components
wallet: { type: Wallet, default: null },
currentIdentity: { type: Identity, default: null },
channels: {
confirmSendEthereum: confirmSendEthereum,
otherControllerAction: otherControllerAction,
},
}, render)
function confirmSendEthereum(state) {
// manipulate state or do i/o here
}
function otherControllerAction(state) {
// manipulate state or do i/o here
}
Then build your template:
- template takes a state pojo and returns vdom
- setup state pojo for sub-components
var h = require('virtual-dom/virtual-hyperscript')
var stateExtend = require('../lib/stateExtend')
var Wallet = require('../wallet/index.js')
module.exports = function render(state) {
// optional: mixin and overwrite wallet internal state with our higher state
var walletState = stateExtend(state.wallet, {
identity: state.currentIdentity,
channels: {
sendEthereum: state.channels.confirmSendEthereum,
}
})
// render state into vdom
return h('div.my-app', [
// render some elements and text
h('span', 'current-view: '+state.currentView),
// render sub-component
Wallet.render(walletState),
])
}
Any and all secret sauce is here: