These are chat archives for jdubray/sam

8th
Mar 2018
Jean-Jacques Dubray
@jdubray
Mar 08 2018 10:37
@victornoel you maybe interested in this video: using redux with ng2
Victor Noël
@victornoel
Mar 08 2018 11:41
is there something specific to look for or is it just presenting redux in the context of angular?
(I watched 2mn and I didn't see anything particularly new to me : )
Paolo Furini
@pfurini
Mar 08 2018 12:20
re full backend API platforms, I'm currently evaluating kuzzle.io and cloudboost.io, as they seem to be the more mature/robust. The latter is way more feature complete, but not as open for extensions as the former. kuzzle has a complete plugin system, that's able (in theory) to extend every aspect of the framework, especially adding own API endpoints beside the provided ones. But it lacks a lot of features that cloudboost already provides (like a complete storage api, and ready-made SDKs for every major client technology)
Both are easily extendable from single machine MVPs to a production cluster.. but if you're looking for an almost complete replacement of Firebase to run on premise, cloudboost is the best bet IMHO. On the other side, if you have very specific requirements for your APIs (need custom server processing, custom endpoints, etc.) take a look at kuzzle, it is a good starting point (both are node based, not my tech of choice, but I know the majority here are node devs ;) )
Paolo Furini
@pfurini
Mar 08 2018 12:54
Update: surely cloudboost has lot of features, but the codebase is messy at least! The server code is assembled like in a POC, with hard coded checks (lot of IFS), and the javascript client is a monolith based on jquery.. definitely, good for fast MVPs, but don't know if I'd use it in prod (even if it seems well supported by the devs/company)
Victor Noël
@victornoel
Mar 08 2018 13:15
@jdubray actually, I would be interested to see an example of an application doing something similar as in the video you shared but with SAM, because I'm unable to think of a way to model this…
Victor Noël
@victornoel
Mar 08 2018 13:27
@jdubray also I had a question: if the NAP happens in the state, it means that it doesn't have access to the primed versus non-primed variables of the model, i.e., it does not know what changed, only what is: how do you trigger actions that depends on the state only if it changed? Is the answer to have some caching mechanism to handle that situation instead of trying to detect it in the NAP?
Paolo Furini
@pfurini
Mar 08 2018 13:42
@victornoel I don't get it.. NAP in state functions shouldn't be triggered only based on the state representation at hand (that is the local state)? For example when you realize you miss some pieces to feed the views, then you trigger a NAP to query them..
Victor Noël
@victornoel
Mar 08 2018 13:45
@pfurini yes, I may be asking my question with incorrect assumptions…
@pfurini my question stems from this use case: I have a graph visible in my app, I have an input that determines the query needed to retrieve the data for the graph. my model contains both the data for the graph as well as the content of the input. I was expecting to use the NAP to trigger the retrieval of the graph data if I didn't have it, but of course, I want to do that only when the input changes, not everytime my model changes…
I guess the model should consider that since the input has changed, the graph data is incorrect so it removes from the model and then the state, seeing that the graph data is missing, triggers an action to retrieve it
would that be correct?
Paolo Furini
@pfurini
Mar 08 2018 13:57
@victornoel I think you should think in one-way-reactive-flow terms to solve this ;)
Victor Noël
@victornoel
Mar 08 2018 13:58
I don't understand what you mean…
Paolo Furini
@pfurini
Mar 08 2018 14:19
first solution that came to my mind: the "input change" is an event stream for which you could react by invoking an action, whose payload is the new user filter. The action presents the new filter to the model. Easy path: the model accepts the change BECAUSE it's not the same as the old value AND the filter format is indeed valid against the target grammar, then converts the user filter to a low level query against the datasource and (optionally) dispatch a NAP with the new query, that in turns call the underlying API and presents the new data to the model, and the model accepts it and dispatch relevant state function, that in turn updates the chart
this is only one of the possible ways to tackle this.. there are tons of possible variations, based on the actual constraints of your UI, the level of abstraction (and reusability) of your actions, etc.
Victor Noël
@victornoel
Mar 08 2018 14:21
this we agree. but the nap is in the state, it doesn't know about "it's not the same as the old value" so from its point of view, it has to render based on the model datastructure as a whole, not a diff event
Paolo Furini
@pfurini
Mar 08 2018 14:22
I use NAPs wherever I see fit.. in the sample flow I mentioned the NAP is called by the model
Victor Noël
@victornoel
Mar 08 2018 14:22
ah… but I understood the NAP should only be done by the state
that's the source of all my questions :)
Paolo Furini
@pfurini
Mar 08 2018 14:27
that's why I wrote (optionally) before NAP.. the way I architect my code and use actions from a DI injected "ActionProvider", I do not see any harm in using actions like lego bricks, but maybe that's not "officially" supported by the SAM pattern
Paolo Furini
@pfurini
Mar 08 2018 14:35
maybe (well, I'm pretty sure) my terminology is not exact in SAM terms.. for SAM a NAP is not a synonym of an action, and it is a mechanism used in state functions.
Paolo Furini
@pfurini
Mar 08 2018 14:49

okay, this is a quote from jdubary:

nap is outside the step itself, the step is Action->Model->State representatio. nap represents "automatic actions", i.e. given a state/status of the system an action is expected to occur. The reality is you might find that you want to order the next action(s) and rendering could logically happen between two next actions. I prefer the automatic actions to happen afterwards because I put a bit of JQuery code (data picker initialization) in the nap().

devin ivy
@devinivy
Mar 08 2018 14:52
the way i see it, nap() acknowledges that there are states in a program that are valid but transient. nap() helps push the program towards a more stable/permanent state.
just like you said above, detecting "missing" information and triggering whatever action to try and find it.
i think that's a decent example!
Paolo Furini
@pfurini
Mar 08 2018 15:12
yes that's right.. again quoting jdubray, they are pure functions of the model, and there should be only one nap executed at a time, before or after the rendering phase, that could be considered a special nap case.. they are used to dispatch "automatic actions". So given that the input of nap is the model itself, you could use the nap to trigger a "refresh data" intent (action), based on a flag on the model, for example "filterChanged"
Jean-Jacques Dubray
@jdubray
Mar 08 2018 15:56
@devinivy as usual great insight.
@victornoel nap can only be evaluated on the (new) current state. At that point the model has mutated and there are no longer any primed variables. This concept is well aligned with finite state machine (and the "always" operator of TLA+). It's really about modeling an automatic transition once you reach a particular (control) state. The control state should be computed from a formula from the current (application) state.
nap implements some logic that would not fit well in the view or the model. In theory the state representation should be able to tell which is current control state so that nap can be effected readily.
devin ivy
@devinivy
Mar 08 2018 16:03

@jdubray thanks :relaxed:

one practical issue i can imagine implementing nap() is avoiding infinite loops...

i find it a little awkward that nap() calls an action without any insights as to whether or not the next step will cause the same next-action again.
Jean-Jacques Dubray
@jdubray
Mar 08 2018 16:08
@devinivy ... like every other piece of code. It would be a temporal breach, can't do that.
devin ivy
@devinivy
Mar 08 2018 16:09
that makes sense to me! it's a little awkward nonetheless.
Jean-Jacques Dubray
@jdubray
Mar 08 2018 16:10
Speaking of temporal breaches, it looks like there is a new crazy trend: automatic fetchers... https://twitter.com/mweststrate/status/971497360852471808
Jean-Jacques Dubray
@jdubray
Mar 08 2018 16:27
@pfurini the temporality between render and nap is debatable. If you use nap to implement synchronous/blocking next-action (i.e. you don't want to render), then nap should act as a predicate and return true/false to trigger render or not. Render being a next-action too, but not directed at the system, only the consumers of the state representation. If you implement synchronous/blocking next-actions in the model (which is ok from a temporal perspective, it's just an approximation/optimization), then you don't have to worry about what comes first, nap or render.