SAM pattern, the origin of Meiosis
artydev
Posted on October 14, 2020
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)
💖 💪 🙅 🚩
artydev
Posted on October 14, 2020
Join Our Newsletter. No Spam, Only the good stuff.
Sign up to receive the latest update from our blog.