These are chat archives for jdubray/sam

3rd
Dec 2018
Jean-Jacques Dubray
@jdubray
Dec 03 2018 04:12
@nerdo The state representation should always reflect what happened during the mutation. The model itself should not be concerned about the consumers of the state representation. In particular SAM would support different state representations for different consumers (Mobile, Web, Voice...).
Dannel Albert
@nerdo
Dec 03 2018 16:55
I understand what you're saying. I guess I was trying to figure out how I could avoid needing to compute/keep track of transient state in the model. I am thinking of the http://sam.js.org/#actions example on sam.js.org where getPostalAddress() might be an asynchronous call. I suppose it could do the async call and then present a change to the model that would keep track of the async call so that the view would know something is happening behind the scenes, but then I feel like it'd be more like a redux-style thunk/saga. It could be considered part of the control state, but then I ask myself if I serialize the state, would I want to include or exclude it, and it's clear to me that it's transient. Am I off base in thinking there's a simpler way to track transient things like making an API call?
Jean-Jacques Dubray
@jdubray
Dec 03 2018 18:30

@nerdo You are correct, transient state should be avoided. But in the case of a spinner you are limited when the view is functional. HTML does not have a good way of dealing that case. SAM's actions are thunks, and that's a bit my issue with React, I believe they tend to direct the developers with a subpar programming model (where a Redux action is by default an event). Redux's default programming model tend to clump together proposal, mutation and state representation in the reducer, which I believe is the wrong thing to do. I don't believe anyone should use Sagas since they fragment the state tree.

It could be considered part of the control state, but then I ask myself if I serialize the state, would I want to include or exclude it, and it's clear to me that it's transient.

Exactly, that's the kind of question that we need to ask, that's why in the sample I pointed out, I don't use a transient control state, I just assume that when a proposal comes, the spinner is no longer needed, but that obviously will not cover more complex cases where different proposals might come before the data is fetched (different widgets working concurrently).

Am I off base

no, not at all. You should also consider a component model where this control state can be easier to reason about. I don't want to give the impression that control state management is a lot easier with SAM, all I have been arguing is that SAM helps you manage control state more easily in a functional HTML architecture. In other words, you don't have to transform you entire programming model into a FSM (which would be a disaster). SAM let's you weave control state management as needed, but I can't argue that it makes it simpler, if that makes sense.

Dannel Albert
@nerdo
Dec 03 2018 18:39
@jdubray Thanks for your response. It's funny, I used to love redux-saga, until I realized that when I returned to code I wrote using it, it wasn't as easy as I originally thought it would be to maintain because I wasn't 100% sure where things were happening and that it was because it fragments the state tree as you mentioned. As far as SAM goes, things are a little clearer in my mind now. Now I just need to spend some time actually writing some code using the pattern... I'm sure I'll be back with more questions :)
Jean-Jacques Dubray
@jdubray
Dec 03 2018 18:44
I tried to talk to Dan a couple of years ago about clarifying these points but he declined, not sure why because Redux has all the pieces, it's just focusing on the wrong pieces IMHO and I believe that's why people are not as happy as they should with it. For me single-state-tree is non negotiable, it brings so much value.
That's why I didn't understand why Dan was pushing Sagas at the time.
Dannel Albert
@nerdo
Dec 03 2018 18:46
He thought he had the solution, or maybe he was trying to solve a slightly different problem. I still feel like the saga concept has value. It's just not a one-size-fits-all solution
Jean-Jacques Dubray
@jdubray
Dec 03 2018 18:48
NAP should help change your mind, though you might still prefer Sagas. As long as you can reason properly from a state perspective, every solution works, it's just when you are not careful, some of your state ends up being trapped in the Saga and you can't have it available anywhere else, that's when things become ugly.
Dannel Albert
@nerdo
Dec 03 2018 19:15
:thumbsup: