Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Activity
  • 03:03
    dependabot[bot] labeled #109
  • 03:03
    dependabot[bot] opened #109
  • 03:03

    dependabot[bot] on npm_and_yarn

    Bump qs from 6.5.2 to 6.5.3 in … (compare)

  • Dec 08 23:59
    dependabot[bot] labeled #108
  • Dec 08 23:59
    dependabot[bot] opened #108
  • Dec 08 23:59

    dependabot[bot] on npm_and_yarn

    Bump qs and express in /svelte … (compare)

  • Dec 07 11:55
    dependabot[bot] labeled #107
  • Dec 07 11:55
    dependabot[bot] opened #107
  • Dec 07 11:55

    dependabot[bot] on npm_and_yarn

    Bump qs from 6.5.2 to 6.5.3 in … (compare)

  • Dec 07 07:35
    dependabot[bot] labeled #106
  • Dec 07 07:35
    dependabot[bot] opened #106
  • Dec 07 07:35

    dependabot[bot] on npm_and_yarn

    Bump express from 4.16.1 to 4.1… (compare)

  • Dec 07 00:42
    dependabot[bot] labeled #105
  • Dec 07 00:42
    dependabot[bot] opened #105
  • Dec 07 00:42

    dependabot[bot] on npm_and_yarn

    Bump express in /angular4-Boots… (compare)

  • Dec 06 22:53

    dependabot[bot] on npm_and_yarn

    (compare)

  • Dec 06 22:53
    dependabot[bot] closed #103
  • Dec 06 22:53
    dependabot[bot] commented #103
  • Dec 06 22:52
    dependabot[bot] labeled #104
  • Dec 06 22:52
    dependabot[bot] opened #104
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
in theme.js
i have two
sandsunsky
@sandsunsky:matrix.org
[m]
do you reckon if im making a website
I should just keep one
like you have it in the todomvc-app-lit-html example
like this
sandsunsky
@sandsunsky:matrix.org
[m]
Jean-Jacques Dubray
@metapgmr_twitter
It really depends how big is your application and how modular you want it to be (e.g. microfrontends). One is a good start, especially if you are the only one working on it. In your function that assigns the intents to the window object, you may want to use a (component) label maybe such that you can assign different intent arrays export default function(component, intents)
you could then:
switch(component) {
     case 'MAIN': Object.assign(window, { ...


}
image.png
chatGPT knows about the SAM pattern today! Not a great summary, but a start!
sandsunsky
@sandsunsky:matrix.org
[m]
better than id expect it to do
sandsunsky
@sandsunsky:matrix.org
[m]
does this
mean you shouldn't wait for websocket to send you something
rather you should be asking periodly if its got something new to send you?