These are chat archives for jdubray/sam

2nd
Nov 2016
Jean-Jacques Dubray
@metapgmr_twitter
Nov 02 2016 14:29
As I said, it is often the case that when you trigger an action you know the end-state and therefore the automatic action that would ensue. However, this behavior cannot be generalized, that is a key issue with the way we write software today. The reason you would want to use nap() would be when the broad context of the model would decide whether you accept "loading" or not. In that case, you would have to use nap(). It would be inelegant to gather context in the action and make the decision there. It would be a poor coupling that leads to spaghetti code and defects.
As long as you understand why you writing some code one way, there is nothing wrong with it. The problem is when you have no choice than writing it in a non-sustainable way.
Edward Mulraney
@edmulraney
Nov 02 2016 15:10
is there any risk in presenting multiple times in on function?
Jean-Jacques Dubray
@metapgmr_twitter
Nov 02 2016 15:14
The only risk would be that you are in an application state that would not allow that action/proposal to be triggered and that would not be trapped. The proposal would go through, even be accepted, yet, the action was not allowed in the first place.
What I like about TLA+ is that the concept of an action is as soft or as strong as you need it to be. You can put your validation logic in the model or in the action. You have a deliberate choice to make. When you have just an action/controller, that's when things quickly get out of hand.
Edward Mulraney
@edmulraney
Nov 02 2016 15:25
i originally thought application could get into unknown state by dispatching multiple actions but you always have the latest state at the time of presenting, so it surely cant be an issue?
Jean-Jacques Dubray
@metapgmr_twitter
Nov 02 2016 15:32
yes exactly, you just have to make sure that the present method is synchronized/isolated. What I like about the SAM pattern is that it gives you just enough structure to reason about these questions, but it's not a strict burden that you have follow no matter what, say like Sagas/Reducer
Edward Mulraney
@edmulraney
Nov 02 2016 17:43
something feels wrong about doing this multi present in an action but i cant work out what
i guess its because of the fact that your state representation is now out of date
Jean-Jacques Dubray
@metapgmr_twitter
Nov 02 2016 17:48
In theory it is not, the reactive loop will complete for every present call, your view should update
Edward Mulraney
@edmulraney
Nov 02 2016 17:49
true
Jean-Jacques Dubray
@metapgmr_twitter
Nov 02 2016 17:49
It simply means that you are 100% sure that the state machine should allow presenting the API call results. It's not too shocking.
You can't do that at long range, it quite healthy, you are informing the model of an ancillary piece of state.
Edward Mulraney
@edmulraney
Nov 02 2016 17:58
should actions be allowed to have side effects?
devin ivy
@devinivy
Nov 02 2016 18:01
actions do have side-effects in SAM
Edward Mulraney
@edmulraney
Nov 02 2016 18:07
yes exactly
tbh you cant avoid it
and if they're isolated to actions then its fairly easy to reason about your side-effects
Jean-Jacques Dubray
@metapgmr_twitter
Nov 02 2016 18:19
The problem is not "side-effects", the problem is random assignments in lieu of proper mutation. By shifting the paradigm from assignment to mutation, you no longer have to fear side-effects. The Elm/Redux machinery is targeting the wrong problem.
There are four fundamental concepts in programming:
You cannot create a programming model that ignores any one of them.
Fred Daoud
@foxdonut
Nov 02 2016 19:19
The problem is not "side-effects", the problem is random assignments in lieu of proper mutation. By shifting the paradigm from assignment to mutation, you no longer have to fear side-effects.
I love that about SAM. The model, and only the model, is in charge of mutation. It's a lot easier to manage your application that way.
The Elm/Redux machinery is targeting the wrong problem.
Exactly. Instead of trying to wrangle an async AJAX call, with response (or error handling), within the reactive loop itself, it is separate. You don't tell the model (or SAM) "I need to make an AJAX call". The model doesn't care. You make your AJAX call, and after you get the response, or handle the error, then you present to the model accordingly.
Jean-Jacques Dubray
@metapgmr_twitter
Nov 02 2016 20:13
:thumbsup:
Rick Medina
@rickmed
Nov 02 2016 20:34
@metapgmr_twitter how should we model long running logic? eg: cancel an api request, drag and drop, etc...
Jean-Jacques Dubray
@metapgmr_twitter
Nov 02 2016 21:20
Any kind of orchestration should in general happen via nap()
The Fishing Game provides an example for Drag and Drop (draw Rectangle) and the use of nap() on mouseUp: https://github.com/jdubray/sam-samples/tree/master/js-rectangle
Rick Medina
@rickmed
Nov 02 2016 21:22
is it ok if there are two atoms for state? one for ui (drag and drop, cancellation, etc) and another for data?
Jean-Jacques Dubray
@metapgmr_twitter
Nov 02 2016 21:23
yes, parent/child SAM instances work well, SAM is very composable, though it's better not to abuse it.
Rick Medina
@rickmed
Nov 02 2016 21:30
@metapgmr_twitter got it. I think I finally get SAM now! if you don't mind the question: does sam tries to specifically solve problems in the front end (maybe vs other frameworks?) or is it just an implementation of tla to the front end?
Jean-Jacques Dubray
@metapgmr_twitter
Nov 02 2016 21:31
It's actually not just front-end. You can also use SAM to manage complex stateful API orchestrations on the server.
no front-end there.
Zach Dahl
@schtauffen
Nov 02 2016 23:05
so i've added an async example to my toy sam implementation. its not quite complete (not utilizing nap and instead adding .then/.caught in model :/) but it gets the general architecture across:
https://github.com/schtauffen/jackalope check examples/cancellable-requests
Jean-Jacques Dubray
@metapgmr_twitter
Nov 02 2016 23:54

Some comments:

return function (action) {

the argument of the present method is a proposal

Jsync.on.start(

seems like a clear violation of the SAM principles (isolation / synchronization of the processing of proposals).