dependabot[bot] on npm_and_yarn
Bump ms from 0.7.0 to 2.0.0 in … (compare)
dependabot[bot] on npm_and_yarn
Bump json5 from 1.0.1 to 1.0.2 … (compare)
dependabot[bot] on npm_and_yarn
dependabot[bot] on npm_and_yarn
Bump json5 from 0.5.1 to 2.2.3 … (compare)
dependabot[bot] on npm_and_yarn
dependabot[bot] on npm_and_yarn
Bump json5, config and gulp-bab… (compare)
So for instance:
import { addInitialState, addComponent, setRender } from 'sam-pattern'
addInitialState({
counter: 0
})
const { oddIntents } = addComponent({
actions: [
() => ({ incByOdd: 1 }),
['INC_BY_3', () => ({ incByOdd: 3})]
],
acceptors: [
model => proposal => model.counter += proposal.incByOdd || 0
]
})
const { evenIntents } = addComponent({
actions: [
() => ({ incByEven: 2 }),
['INC_BY_4', () => ({ incByEven: 4})]
],
acceptors: [
model => proposal => model.counter += proposal.incByEven || 0
]
})
The thing to remember though is that components can interfere with each other like in the. In this example, this is not a very realistic acceptor because it's not guarded so it will be executed regardless of the fields in the proposal. That's why I cannot use the same proposal field otherwise each acceptor will be executed and we will count twice. That being said, in that particular example, the acceptors' array can be empty. Components are just a way to partition the model into more manageable pieces, but the component model is not scoped. If you want something scoped, you need to create separate SAM instances (eg parent/child).
I could have also written it that way:
```
import { addInitialState, addComponent, setRender } from 'sam-pattern'
addInitialState({
counter: 0
})
const { oddIntents } = addComponent({
actions: [
() => ({ incBy: 1 }),
['INC_BY_3', () => ({ incBy: 3})]
],
acceptors: [
model => proposal => model.counter += proposal.incBy || 0
]
})
const { evenIntents } = addComponent({
actions: [
() => ({ incBy: 2 }),
['INC_BY_4', () => ({ incBy: 4})]
],
acceptors: []
})
But in that case you have to know that the second component will trigger the first component's acceptor.
const { intents: todoIntents } = addComponent(todo)
todoIntents