These are chat archives for jdubray/sam

Apr 2018
Hamza OuaƔad
Apr 20 2018 02:04
What up what up
new arrival here
I've just discovered the SAM pattern recently and I have some questions about it
Hamza OuaƔad
Apr 20 2018 02:14

There is a quote in the website that I am not quite comfortable with

SAM was originally designed to solve the strong coupling that MVC creates between the Front-End structure and the Back-End APIs.

Don't you think that the SAM pattern is just another MVC,
and it is clear that the "MVC" referred to in this quote has to do with the old monolithic way of building web applications, (ruby on rails way...)

so MVC, is not to be confused with that, Ruby on Rails has just implemented MVC in that way... does not mean that MVC is exactly that. Don't you think?

I think SAM is just another MVC (as is Redux in a way), and if we are to think of it in an implemention of React and Mobx, it would be like this:

  • React is the V in the MVC, it is what presents our data (no news here) (assume react is just React.render, and we are talking stateless components)
  • Mobx observables are the M in the MVC, it is our data, our state
  • Acceptors are the C in the MVC, it is what allows, validates, controls and propogates mutations to our data/state (and implicitly including actions whose result in basically the mutations we are controlling)

I think there are real great concepts that the SAM pattern tries to advance, and they could be translated to the following points:

  • Actions are pure functions proposing changes (Action creators)
  • Models as data holders / state holders (State Stores)
  • Acceptors to control data mutations (Reducer)
  • State as a pure function mapping models to our "presentable" state (mapStateToProps)
If we somehow try to think of them in terms of a Reducer pattern
Which prompts me to my next question, isn't really the SAM pattern just like the reducer pattern, I understand that it was said in the website that there is a fundamental difference between the two just because in the reducer pattern (a.k.a redux) the actions are objects
Well, that's just an implementation detail
We still "propose" mutations with { type: action_Type, value: }
so I really fail to spot the difference between the two in that regard, as far as concepts go. However, of course, we will always expect the implementation details to be different.
The MVC pattern is just another derivative of the SoC patterns, and The Reducer pattern as well as the SAM pattern separate the view from the data by isolating and controlling data mutations/state mutations and actually mapping the state to the components via a pure function as proposed in the SAM model
So, I am agnostic towards the claims the SAM pattern advances in the website
Hamza OuaƔad
Apr 20 2018 02:20
Also, I would love to learn more about the next action predicate and also have some useful use case ( multiple action predicates are better handled with a FSM?)
Thanks guys!