Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Activity
  • Jan 11 02:08
    dependabot[bot] labeled #120
  • Jan 11 02:08
    dependabot[bot] opened #120
  • Jan 11 02:08

    dependabot[bot] on npm_and_yarn

    Bump ms from 0.7.0 to 2.0.0 in … (compare)

  • Jan 07 16:19
    dependabot[bot] labeled #119
  • Jan 07 16:19
    dependabot[bot] opened #119
  • Jan 07 16:19

    dependabot[bot] on npm_and_yarn

    Bump json5 from 1.0.1 to 1.0.2 … (compare)

  • Jan 03 18:14

    dependabot[bot] on npm_and_yarn

    (compare)

  • Jan 03 18:14
    dependabot[bot] closed #115
  • Jan 03 18:14
    dependabot[bot] commented #115
  • Jan 03 18:14
    dependabot[bot] labeled #118
  • Jan 03 18:14
    dependabot[bot] opened #118
  • Jan 03 18:14

    dependabot[bot] on npm_and_yarn

    Bump json5 from 0.5.1 to 2.2.3 … (compare)

  • Jan 03 15:18

    dependabot[bot] on npm_and_yarn

    (compare)

  • Jan 03 15:18
    dependabot[bot] closed #114
  • Jan 03 15:18
    dependabot[bot] commented #114
  • Jan 03 15:18
    dependabot[bot] labeled #117
  • Jan 03 15:17
    dependabot[bot] opened #117
  • Jan 03 15:17

    dependabot[bot] on npm_and_yarn

    Bump json5, config and gulp-bab… (compare)

  • Jan 01 17:58
    dependabot[bot] labeled #116
  • Jan 01 17:58
    dependabot[bot] opened #116
Jean-Jacques Dubray
@jdubray
I created a sample with a canvas a while back https://glitch.com/edit/#!/plain-frog?path=views%2Findex.html%3A1%3A0, it's not using any library, just raw wiring of the pattern, perhaps it can help.
The part I am not sure I understand is: do you know the significant parameters in advance or is that based on the state? You should have a flag in the model (that gets reset as you enter the model) and trigger that flag each time a significant parameter changes, that way you have a stateless model interaction and no action in the rendering.
Paolo
@zawinul
Thank you very much for your prompt reply. The ability to send an action from the rendering definitely solves my problem. I am using your sam-lib in asynchrounous mode so I think I cannot assume that the render function is called immediately after an action writes a flag as there may be other actions in between. So the flag should remain in the model between actions. For this reason I think I need a feedback action from the rendering to tell the model "ok you can reset the flag".
Jean-Jacques Dubray
@jdubray
That sounds reasonable!
The wiring of the pattern can be use case dependent, there are cases when assuming a synchronous behavior is acceptable, others, when that doesn't work and some when rendering needs to carefully be positioned. It doesn't change the behavior/structure of the pattern.
Jean-Jacques Dubray
@jdubray
Introduction to the Theory of Programming Languages: full book now freely available
The full text of Bertrand Meyer's Introduction to the Theory of Programming Languages book (second printing, 1991) is now available. https://bertrandmeyer.com/2022/09/28/introduction-theory-programming-languages-full-book-now-freely-available/
JohnGurin
@JohnGurin
👍
Jean-Jacques Dubray
@metapgmr_twitter
TLA+ @ Microsoft https://youtu.be/azx6cX-BlCs
Jean-Jacques Dubray
@metapgmr_twitter
Resumable Web sites https://youtu.be/umASDvjaKTY
^^ a Java Web framework
Jean-Jacques Dubray
@metapgmr_twitter
Daniel Neveux
@dagatsoin
I am testing the GPT chat for the last day. I just managed to make it but. Guess how ? I told it about the SAM pattern.
*bug
Jean-Jacques Dubray
@metapgmr_twitter
Lol! I must admit gpt is quite amazing both for code and text
Jean-Jacques Dubray
@metapgmr_twitter
Well, so far it doesn't know about SAM, it confuses it with songle action multiple methods (sigh). Its interesting though from a training perspective. Looks like SAM us just noise.
Daniel Neveux
@dagatsoin
It wrote a good definition of the pattern in my case. But it did not implement SAM very well. Note it tried with pure React, which is not the simplest usecase.
Jean-Jacques Dubray
@metapgmr_twitter
:+1:
Jean-Jacques Dubray
@metapgmr_twitter
image.png
sandsunsky
@sandsunsky:matrix.org
[m]
hello everyone
is there a way to add more than one component with sam-lib
?
sandsunsky
@sandsunsky:matrix.org
[m]
or should i only have one high level component and then add more in the theme.js
Jean-Jacques Dubray
@metapgmr_twitter
No, you can add as many components as you'd like. You would then get a separate set of intents, associated to each component
Jean-Jacques Dubray
@metapgmr_twitter

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.

sandsunsky
@sandsunsky:matrix.org
[m]
Thanks for sending that detailed explanation through Jean-Jacques
Jean-Jacques Dubray
@metapgmr_twitter
:+1: any time!
sandsunsky
@sandsunsky:matrix.org
[m]
when I have this
everything works
but if i change intents to todoIntents
this happens
i guess its somewhere in addComponent
sandsunsky
@sandsunsky:matrix.org
[m]
anything called intents only exists in those two places in my project
Jean-Jacques Dubray
@metapgmr_twitter
Sorry I forgot how to destructure. You need to change the name:
const { intents: todoIntents } = addComponent(todo)
Then you can use todoIntents
sandsunsky
@sandsunsky:matrix.org
[m]
Awesome that makes sense
sandsunsky
@sandsunsky:matrix.org
[m]
My knowledge of javascript is very limited so some of it is done uglier than it needs to be but i got it to work
I'm not even sure if I need more than one base component but I learned alot figuring it out
instead of that one function