These are chat archives for jdubray/sam

2nd
Sep 2016
Anthony
@tribals
Sep 02 2016 12:34
hi there, again! ))
is there in SAM actions that do not performs re-rendering of model?
Kelyak
@kelyak
Sep 02 2016 12:50
If I'm not wrong, if you need to launch a new action without re-rendering the view you must go through the loop once more with the help of the nap function
Jean-Jacques Dubray
@jdubray
Sep 02 2016 12:50
no in general, that should not be the case. An action's purpose is simply to convert an event into a proposal for the model. It should not have any side effect on its own.
@kelyak yes, good point, the state representation could have no changes but trigger an action via nap()
Anthony
@tribals
Sep 02 2016 13:16
let's consider a real example, my app i working on. I'm tryingo to make "an alert". Something that informs user that operation has been success, or not. Let's consider the action 'edit'. The user updates entity, fires action, action proposes data to model, model verifies data, accepts or rejects them, then performs api request, if success, setups alert, then renders himself. The view renders alert and model, THEN alert need to be cleared, because if other model item will be edited, the alert will be shonw again, which is wrong. So, there is action that clears alert, and called from nap() after 'edit' action. But, this recycle reactive loop again, and cause re-rendering the same action, because action 'clearAlert' only clears alert, and do not proposes any other data to model. And, finaly the same model item rendered again, without alert, which causes alert apears and immediatelly disapears. So, user do not see it completely
what i made wrong?
Kelyak
@kelyak
Sep 02 2016 13:20
maybe just a timeout in the nap before calling the action, or in the action itself ? (not sure that it's the best solution but it's the first that came to my mind)
Anthony
@tribals
Sep 02 2016 13:21
no, it is the user responsibility, does he want see alert, or not, and he can close it, or leave on the page
may be, there should be the beforeActionPredicate? in general action initiates state change, so when transition from 'edit' action to any other, there must be before hook, which clears alert?
'edit' state, not action
Jean-Jacques Dubray
@jdubray
Sep 02 2016 13:26
Small DOM manipulations outside the reactive loop are allowed.
Anthony
@tribals
Sep 02 2016 13:27
yeah, this is what i trying to avoid with help of SAM
Jean-Jacques Dubray
@jdubray
Sep 02 2016 13:28
One way to do it is to express the state representation as a function that you pass to the view component, that way it is still controlled by the state function
you can still do it via the reactive loop, I'll try to build an example this morning, but it is not possible to remove 100% of DOM manipulations, even react cannot do it.
Anthony
@tribals
Sep 02 2016 13:38
but, i don't need DOM manupulation, the alert is stored in model, so i need to change model from something other than action, which conflicts with main purpose of any architect pattern: decoupling of parts of system
i need show an alert, then revome it from model so that it will not be rendered in next action
Riccardo
@riccardoferretti
Sep 02 2016 13:55
@tribals not sure if I understand, what do you mean by “THEN alert needs to be cleared”? how does that happen? Automatically (like a notification), or after the user clicks on the X, or both, … also I wouldn’t phrase the nap in terms of the action performed, because it is instead tied to the state (probably that’s what you meant, but just wanted to clarify)
Anthony
@tribals
Sep 02 2016 13:58
I mean, alert need to be cleared from model (where it stored), so, when next action renders, alert will not be shonw again. How alert exactly be cleared from screen is no mater. User can close it, or leave, but when user performs next action, there will be no alert on the screen (which means there will be no alert soterd in model)
Riccardo
@riccardoferretti
Sep 02 2016 14:01
sounds good, what happens next? (I am still trying to fully understand the example)
Anthony
@tribals
Sep 02 2016 14:01
next after what?
i can share sources of my app
they are messy, because i just started learning SAM
Riccardo
@riccardoferretti
Sep 02 2016 14:02
there is clearAlert action, no matter how it’s triggered, that will remove the alert
Anthony
@tribals
Sep 02 2016 14:03
yes
Riccardo
@riccardoferretti
Sep 02 2016 14:03
and you are worried that the alert will show up again on the next render?
Anthony
@tribals
Sep 02 2016 14:03
yes
Riccardo
@riccardoferretti
Sep 02 2016 14:04
what logic decides whether to add the alert to the model?
(happy to look at the code too)
Anthony
@tribals
Sep 02 2016 14:09
the model itself, when model processes data from action, say, 'edit'. It performs api request then according to request result, it sets up alert (success/error)
just serve src's content with any web server, say python3 -m http.server
Jean-Jacques Dubray
@jdubray
Sep 02 2016 15:51
@tribals I often use an "autoreset" approach, where the model sets:
if (data.alarmRequested) {
      ....
}  else {
     model.alarmRequested = false;
}
Anthony
@tribals
Sep 02 2016 15:54
sounds great
Fred Daoud
@foxdonut
Sep 02 2016 20:27
@tribals if you are still interested, I am working on an example with a modal dialog that you may find helpful.