These are chat archives for jdubray/sam

29th
Dec 2017
Łukasz Lityński
@hex13
Dec 29 2017 08:11
what they are proposed, it's a coupling to the browser API - document.body and CustomEvent which are not available on NodeJS, so solution couldn't be universal (without mocking/polifilling). Very idea of using DOM elements as dispatchers is interesting but seriously... implementing proper dispatcher/event emitter can be done 50-100 lines of code or even less (e.g. https://github.com/developit/mitt - 61 lines of code, but most of them are comments https://github.com/developit/mitt/blob/master/src/index.js ) so why bother to use DOM API at all? (I mean nice Proof of Concept, I myself wasn't even aware of CustomEvent, but it seems so much overhead)
david kaye
@dfkaye_twitter
Dec 29 2017 08:38
Author mentioned use of EventEmitter on the node.js side late in the post. Custom Events have been around for a long time - we used them in a test-driven situation 10 years ago - but they're much easier to use now (far fewer constructor params). I like that he takes both custom elements and events for a spin. I wonder whether the overall pattern could be improved with a model step between action and render. And as for the side-effect he adds at the end, would Sam pattern's next-action-predicate work here instead?
david kaye
@dfkaye_twitter
Dec 29 2017 08:43
Another project that showed up in the timeline today: refactoring frameworks into vanilla.js
Jean-Jacques Dubray
@jdubray
Dec 29 2017 09:02
@hex13 SAM being just a pattern, there is no reason why you would not be able to implement it in any framework of your choice. We are generally discussing at the level of best practice for a framework (such as React/Redux or ELM, of Vue/Vuex). For instance, an article came up recently explaining that the best place to implement API calls are in a componentDidMount method, which I would argue it possibly the worst.
boris sabadach
@bsabadach
Dec 29 2017 09:05
Hi everyone, I’m Boris
Jean-Jacques Dubray
@jdubray
Dec 29 2017 09:05
Immutability brings you pretty much nothing other than testability. I don't know anyone logical who would use a test-first architecture over the clarity of implementing your app logic. When you dig a bit on functional programming, you see that you trade this absolute purity for ugly Monads which seem to be pretty much anything you want it to be.
@bsabadach welcome! Bonjour!
boris sabadach
@bsabadach
Dec 29 2017 09:05
Merci!
I have a question for you @jdubray
Jean-Jacques Dubray
@jdubray
Dec 29 2017 09:07
@bsabadach please
boris sabadach
@bsabadach
Dec 29 2017 09:07
you seem to prefer separate your application in « blocks » rather than component, what’s the difference?
RayoGundead
@RayoGundead
Dec 29 2017 09:07
is the model initiated at start somewhere or would there be initial proposal ?
I'm stuck at this one part
Jean-Jacques Dubray
@jdubray
Dec 29 2017 09:08
@bsabadach the building blocks are 100% standalone and decouple from each other.
boris sabadach
@bsabadach
Dec 29 2017 09:08
just like components!
Jean-Jacques Dubray
@jdubray
Dec 29 2017 09:09
@RayoGundead you can start the first reactive loop step at the model level (but an "init" action would work too)
@bsabadach I find that components tend to couple too many concerns.
I mean react, angular components...
There are 4-5 types of building blocks in SAM:
  • functional view components ( V = f(props))
  • Actions
  • Acceptors (Model)
  • Reactors (State)
  • NAPs
But in general people don't like my implementation style, which I respect.
These building blocks are 100% isomorphic and can be executed on the browser or server, or a combination of both, or even a 3rd party using an OAuth token for instance.
boris sabadach
@bsabadach
Dec 29 2017 09:14
Yes I understand I read this chat for a couple of months. I was thinking about components in « atomic design » semantic. Whene you work with a designer that applies this technique, he usually buils a esign
design system of UI components
Jean-Jacques Dubray
@jdubray
Dec 29 2017 09:16
I may not be working on complex enough solutions, but I tend to never come across a "reuable" view (application) components, the reusable components are more the date pickers, data tables, charts, and so on
I use the JQuery libraries for these components.
RayoGundead
@RayoGundead
Dec 29 2017 09:17
@jdubray I've seen examples of actions provided by state state.actions().action(data) that's why I doubted at first if it's possible to come up with an "init" action
Jean-Jacques Dubray
@jdubray
Dec 29 2017 09:18
The way I build my solution (since I don't have the luxury of a designer) is to buy a template. I am currently working on this one
boris sabadach
@bsabadach
Dec 29 2017 09:18
ok so we talk about the same thing . But you seem to agrgate theses components in a strange manner: the " theme » (which doesn’t mean the same thing in front end world)
Jean-Jacques Dubray
@jdubray
Dec 29 2017 09:19
then I am able to decompose the template into a series of pure functions (as you mentioned aggregated as a theme). That works really well, infinitely flexible.
I call it "theme" because in theory I can use different templates with the same SAM back-end.
@RayoGundead you can wire the pattern any way you want, I am not an experienced JavaScript developers and may not provide the best "wiring" of the pattern.
boris sabadach
@bsabadach
Dec 29 2017 09:21
But you update the whole theme in just ONE state.representation! The whole application depends on ust one model state?
Jean-Jacques Dubray
@jdubray
Dec 29 2017 09:21
correct!
I cheat a little bit since I allow some optimatization to avoid a "rendering page" effect
Again, people don't like my approach and prefer a virtual DOM, which I respect
RayoGundead
@RayoGundead
Dec 29 2017 09:23
sounds like manually writing what vdiff+patch generates
Jean-Jacques Dubray
@jdubray
Dec 29 2017 09:23
@RayoGundead yes, but it's not really a burden, from practical experience.
RayoGundead
@RayoGundead
Dec 29 2017 09:24
if you think about it, it's actually better than virtual dom
boris sabadach
@bsabadach
Dec 29 2017 09:25
This is the main thing I don’t agree with that because in fact your whole application depends on on model tree. This is just want I don’t like in Redux. Modularity is killed. An application should be a n aggregation of use cases modules. Each module should independent form the others, and could be thrown away without any refactoring
RayoGundead
@RayoGundead
Dec 29 2017 09:25
@jdubray that might be what the guy that did svelte thought too
Jean-Jacques Dubray
@jdubray
Dec 29 2017 09:27
@bsabadach I can show you that this is very modular, the problem with redux is that you have a big fat reducer. In SAM you reason very simply in terms of events/props. Extensible data structure (aka JSON) does the hard work for you.
@RayoGundead I wrote a simple "hash-dom" algorithm that automates what I was doing manually.
RayoGundead
@RayoGundead
Dec 29 2017 09:28
it's the one using template tags
Jean-Jacques Dubray
@jdubray
Dec 29 2017 09:29
@bsabadach you never have to think (too much, if at all) at the level of the entire tree.
RayoGundead
@RayoGundead
Dec 29 2017 09:29
@bsabadach I think the state functions are for that
Jean-Jacques Dubray
@jdubray
Dec 29 2017 09:29
@RayoGundead here is the hash-dom sample
boris sabadach
@bsabadach
Dec 29 2017 09:31
But your state functions mirrors jsut one model => only one model tree? Just like the creator of mobs said when should think in domain store. Each application have several domain store so several "control states"
RayoGundead
@RayoGundead
Dec 29 2017 09:32
at the moment, I stuck at a single model, and state functions wired to model via pubsub
Łukasz Lityński
@hex13
Dec 29 2017 09:32
immutability can help with some other things, like deciding when data changed - detecting changes is trivial, just a !== b
Jean-Jacques Dubray
@jdubray
Dec 29 2017 09:33
@bsabadach I worked with "extensible data structures" since the very early days of XML (my first paper on it)
when you take advantage of XDS you don't need to think as "one model tree".
RayoGundead
@RayoGundead
Dec 29 2017 09:33
the state functions don't throw all of the model tree into the view...
... do they?
Jean-Jacques Dubray
@jdubray
Dec 29 2017 09:34
That's why I don't understand people wanting to use static types. With an XDS paradigm, you have an infinite number of micro processing pipelines, you rarely if ever need to think about the entire tree.
Of course you have the occasional collision (or two), but that's really nothing to deal with
@RayoGundead exactly, you have the flexibility to dice and redice your model based on the current (control) state of the application. This is very very flexible.
SAM also encourages a many-to-many relationship between actions-acceptors-reactors, that's very healthy.
RayoGundead
@RayoGundead
Dec 29 2017 09:37
this is actually my way to stop thinking about the whole model tree
Łukasz Lityński
@hex13
Dec 29 2017 09:37
one big state tree doesn't have to be scaried if you have a way for selecting some state slices and for working on slices of state
RayoGundead
@RayoGundead
Dec 29 2017 09:37
the state function is starting to look more like a selector
Jean-Jacques Dubray
@jdubray
Dec 29 2017 09:37
@hex13 please, the whole point of SAM is to isolate "mutations" and make a clear distinction between mutation and assignment. Immutability amounts to using a bazooka to kill a fly, totally the wrong thing to do (in the context of managing mutation)
Łukasz Lityński
@hex13
Dec 29 2017 09:38
why? immutability can be done as implementation detail
Jean-Jacques Dubray
@jdubray
Dec 29 2017 09:39
@RayoGundead It's main function is to adapt the model to the view props. Again you want 100% decoupling between view and model. That is SAM's goal, that has huge implications on back-end API footprint.
Łukasz Lityński
@hex13
Dec 29 2017 09:40
I mean Mobx-like way of doing things, you write foo.bar = 123 and this is not a mutation but setter calling
boris sabadach
@bsabadach
Dec 29 2017 09:40
I think I don’t get what you say. I don’t talk about immutability. Nowadays with micro services front end applications gather data from diffrent domain. For instance the "search domain » have it’s own API, it’s own persistence support, while CRUD operation belongs to another domain. You can’t gather all these domains in one tree. You end up with a bloated thing like redux, which again kills modularity
Jean-Jacques Dubray
@jdubray
Dec 29 2017 09:41
@hex13 it's totally unecessary, it is just the wrong thing to do. Again, look at what a Monad is and think about the mess that "immutability" brings into the programming model. It's ludicrous. Typicall Software Engineering sugar, you attract developers with a 6th grade concept (pure function/immutability) and then you chain them to years if inneficient programming.
@bsabadach happy to take it offline and do a skype session if you'd like. The problem with Redux are:
  • they confuse events with actions, what they call an action is an event,
  • they use immutability for whatever reason
you have no room whatsoever for API calls, you are on your own to stitch the API calls where you can
React is too reactive, it has no good option itself to make API calls.
Łukasz Lityński
@hex13
Dec 29 2017 09:44
but immutability can be done behind scenes
Jean-Jacques Dubray
@jdubray
Dec 29 2017 09:44
@bsabadach I don't talk about immutability either, this is a thread with @hex13
@hex13 what you need is synchronization of the mutations, not immutability. Immutability is a very poor way to achieve that result.
boris sabadach
@bsabadach
Dec 29 2017 09:45
I agree with you about redux: I will add single state tree which probably Facebook needs but 80% of business app don't
Jean-Jacques Dubray
@jdubray
Dec 29 2017 09:45
@bsabadach :+1:
@bsabadach again, I'd be happy to set up a skype session, it's best to look at some sample code and talk, it's more difficult to do it with a chat.
Łukasz Lityński
@hex13
Dec 29 2017 09:47
maybe poor way, but it's no harm
I'm mean something like this: function inc(state, action) { state.value += action.payload }
Jean-Jacques Dubray
@jdubray
Dec 29 2017 09:48
@hex13 again, let's leave the 6th grade concepts behind and try to answer some real hard question like:
  • what is an action?
  • what is a mutation?
    Puting an "immutability" wrapper on these questions is at best naive.
Łukasz Lityński
@hex13
Dec 29 2017 09:49
for me mutation is just one form of "event"
which can occur
Jean-Jacques Dubray
@jdubray
Dec 29 2017 09:49
@hex13 I get it, Turing and Church were genius, they could think about "computation" at a time that no one could even conceptualize what a computer was
but... that was nearly 100 years ago. We can learn a thing or two since they came up with Lambda-Calculus.
Łukasz Lityński
@hex13
Dec 29 2017 09:51
action... not sure about the term, I'm in total confusion about what action should be
Jean-Jacques Dubray
@jdubray
Dec 29 2017 09:51
We can admit that there are more than one theory about computation and then start comparing them and decide on the pros/cons.
@hex13 that's my point, as an industry, it's pretty sad that we don't have a standard definition of what an action it.
boris sabadach
@bsabadach
Dec 29 2017 09:51
@jdubray it could be cool, I’m working on a POC at the moment with no framework , SAM pattern and snabbdom-jsx, so It would be better to talk when something working will achieved
Łukasz Lityński
@hex13
Dec 29 2017 09:52
for me immutability is more like optimization, maybe it's not needed, but can help if pros > cons
Jean-Jacques Dubray
@jdubray
Dec 29 2017 09:52
@bsabadach any time!
Łukasz Lityński
@hex13
Dec 29 2017 09:52
in Redux immutability is broken because people have to manage it by themselves by writing Object.assign / ... / or wiring Immutable.js
boris sabadach
@bsabadach
Dec 29 2017 09:53
@hex13 I agree with you. Action is not a design pattern . The Command is. So when there is no design pattern for a conce
concept nobody agree upon
Łukasz Lityński
@hex13
Dec 29 2017 09:55
I wonder from where/when "action" word came to C.S.
Jean-Jacques Dubray
@jdubray
Dec 29 2017 09:55
@hex13 then you have to consider temporal logic. You can't write code without temporal logic, except for the most trivial code. I don't know of any programming language which has some semantics that support temporal logic.
@hex13 @bsabadach TLA+ (being the temporal logic of actions) has a very precise definition of action.
Łukasz Lityński
@hex13
Dec 29 2017 09:55
overally these concepts - actions, events, commands, signals, messages are so similar but everybody can implement them in different way and assign them different role in app
there are also requests and notifications
Jean-Jacques Dubray
@jdubray
Dec 29 2017 09:56
@hex13 it's time to clean it up, we cannot make progress as an industry without clean semantics.
@hex13 @bsabadach when you look at SAM for instance, and compare it to CQRS you realize that Queries and Commands are both actions (there is a "mutation" of the application state for both (yes even queries)). When I make a query my "application state" has changed since I can see the results on the screen.
RayoGundead
@RayoGundead
Dec 29 2017 09:58

the whole point of SAM is to isolate "mutations"

first impression I had was it looked like Redux but with a single store made up of custom middlewares and an default identity function reducer, and with actions pulled out to their own functions, and subscribers.

If I understand this correctly, so it means that mutations are pushed all the way to the model, and proposals are fed to the present function containing the acceptors, and since the present function is the one export, it is also the one that knows when the state changes have been done and so be the one that knows when to call the state function it calls the state function, and the state functions receive the current model and adapts it for view which the state function calls, and actions are what the view and/or state function calls and is suppose to make a proposal based on the data passed to it and pass to the present function.

Łukasz Lityński
@hex13
Dec 29 2017 09:59
"the whole point of SAM is to isolate "mutations" -- this got me to the point that I literally thought that SAM is proposing immutability
Jean-Jacques Dubray
@jdubray
Dec 29 2017 09:59
@RayoGundead yes, exactly. I agree that at a high level it looks very similar, but in reality they are nearly opposite conceptually.
Łukasz Lityński
@hex13
Dec 29 2017 09:59
because if you isolate mutations (which is a great idea BTW)
then immutability is trivial to achieve
RayoGundead
@RayoGundead
Dec 29 2017 10:00
I can see why it's the opposite
Jean-Jacques Dubray
@jdubray
Dec 29 2017 10:00
@hex13 yes, if you want you can use an immutable implementation of the model, but at the same time, you realize you don't need it anymore!!
Łukasz Lityński
@hex13
Dec 29 2017 10:00
state library having list of mutations in array, can do copy-on-write clone of previous state
Jean-Jacques Dubray
@jdubray
Dec 29 2017 10:01
I am a back-end guy, my starting point was about calling APIs. I tried React in 2015 and could not find a good way to position an API call (and I don't think anyone has since).
I started to work on SAM in the first half of 2015, then publish the first post in June 2015
before Redux
Then Redux came out, and you still could not position API calls properly.
boris sabadach
@bsabadach
Dec 29 2017 10:04
Jean-Jacques Dubray
@jdubray
Dec 29 2017 10:04
Unless you decompose your programming model with precision you'll never be able to position API calls properly.
Łukasz Lityński
@hex13
Dec 29 2017 10:05
" you realize that Queries and Commands are both actions (there is a "mutation" of the application state for both (yes even queries)). When I make a query my "application state" has changed since I can see the results on the screen." - I don't understand this.
Jean-Jacques Dubray
@jdubray
Dec 29 2017 10:06
@bsabadach thank you for sharing, I had not seen it. I can see right away where SAM changes the game (decoupling model/view props, easy to reason flow, zero boilerplate...)
@hex13 when you make a query (API call), the result set is added to application state, which is then rendered. A mutation has occored to add the result set to the application state.
Łukasz Lityński
@hex13
Dec 29 2017 10:08
it reminds me of "In physics, the observer effect is the fact that simply observing a situation or phenomenon necessarily changes that phenomenon. This is often the result of instruments that, by necessity, alter the state of what they measure in some manner. "
Jean-Jacques Dubray
@jdubray
Dec 29 2017 10:09
@hex13 for me, it just means that we have to be very careful and very precise with all these concepts. Concepts are attractive, I get it, but we also need to spend time articulating them precisely.
boris sabadach
@bsabadach
Dec 29 2017 10:10
Make API calls in angular or react could be done in an acceptable way. Implement a store as a Repository design pattern, plug this store with a remote resource ajax proxy and put a reference of the store in a container component. That’s the least that can be done
Łukasz Lityński
@hex13
Dec 29 2017 10:11
but then repository would change its own internal state?
boris sabadach
@bsabadach
Dec 29 2017 10:15
yes, it has a reference to the loaded model and all mutations should be done thru repository API. Model is read only.
Jean-Jacques Dubray
@jdubray
Dec 29 2017 10:15
@bsabadach I am not execited about that approach because it's kind of a two-way binding to the model (if I understand correctly). I prefer SAM's flow where the API calls are aligned with actions and mutations.
I makes it difficult to deal with cancellations for instance, which are all but trivial with SAM.
Łukasz Lityński
@hex13
Dec 29 2017 10:17
how does SAM handle cancellations?
boris sabadach
@bsabadach
Dec 29 2017 10:18
Yes but you when you end up in a company where angular 1.2 is used and you have 1000 loc in controllers that do EVERYTHING, you know you have to find a way
Łukasz Lityński
@hex13
Dec 29 2017 10:19
in 2019 Redux will be a new Angular 1.2
people write legacy code in every framework
after sufficiently long time
boris sabadach
@bsabadach
Dec 29 2017 10:21
@jdubray cancellation was possible for forms . Everytime the model should be edited a copy of it was presented to the form.
Jean-Jacques Dubray
@jdubray
Dec 29 2017 10:21
@hex13 because SAM has a strong temporal logic structure, you can implement a strategy like I did for SAM-SAFE
Łukasz Lityński
@hex13
Dec 29 2017 10:21
that's why I'm waiting for viable mainstream alternative to Redux (I'm thinking about doing it myself too), because if don't want to be put in Redux legacy code in 2019
Jean-Jacques Dubray
@jdubray
Dec 29 2017 10:22
SAM-SAFE just keeps track of the step number an action instance is associated with
Łukasz Lityński
@hex13
Dec 29 2017 10:22
(Redux especially because of this boilerplate and indirections)
SAM-SAFE? I'll look into this
Jean-Jacques Dubray
@jdubray
Dec 29 2017 10:23
You can detect if an action presents its proposal in the wrong step and decide what to do with it (ignore it -cancel, process it but don't render, ...)
When you look at Dr. Lamport work you will see that counters are ubiquitous. He himself noted that in one of his presentations.
boris sabadach
@bsabadach
Dec 29 2017 10:24
@hex13 it doesn’t depends on the FW. You always need to apply design patterns and decouple things when the application is growing. Angular 1.* doesn’t have a model layer, just like react, just like Vue. It’s up to u to make your own or use Redux or another
Jean-Jacques Dubray
@jdubray
Dec 29 2017 10:25
When you think of it, what is a "counter" in the context of temporal logic?
A counter is a temporal relation, just like you can use counters for relations in data models.
Łukasz Lityński
@hex13
Dec 29 2017 10:28
how do counters help with cancellation?
Jean-Jacques Dubray
@jdubray
Dec 29 2017 10:30
@hex13 Since the mutation happens within a well defined step, we can count them, and we can then identify the temporal relationship of a proposal to the current application state.
I need to step out for a little bit. Happy to continue the discussion another day.
Łukasz Lityński
@hex13
Dec 29 2017 10:41
ok
Daniel Neveux
@dagatsoin
Dec 29 2017 11:20
my 2cts on the temporal logic. I wrote a paper (draft) on the implementation of a Lag Compensation system for multiplayer game using Sam Safe like. (it already works on the paper :p )
All of that to say thx to @jdubray and also that SAM is the only pattern I know which could easily implementing step.
Jean-Jacques Dubray
@jdubray
Dec 29 2017 12:29
@dagatsoin thank you! Please share the link when you publish it.