The author of this famous pattern is Jean-Jacques Dubray. He wrote an introduction here SAM
You can see it in action here : SAMdemo
let actions = {
countBy(step) {
step = step || 1
model.accept({incrementBy:step})
}
}
let model = {
counter: 1,
accept(proposal) {
this.counter += (proposal.incrementBy > 0) ? proposal.incrementBy : 0
state.render(this)
}
}
let state = {
render(model) {
if (!this.nextAction(model)) {
console.log(model.counter)
}
},
nextAction(model) {
if (model.counter % 2 == 0) {
actions.countBy(1)
return true
} else {
return false
}
}
}
actions.countBy(2)
Top comments (0)