These are chat archives for jdubray/sam

21st
Dec 2016
Jean-Jacques Dubray
@jdubray
Dec 21 2016 00:35
@edmulraney I talk about "standard" redux because that's what most developers would want to use before they trying something different. Without a formal foundation to understand the difference (just tips & tricks or best practice), there are just too many reason to shoot yourself in the foot.
The (SAM) model and actions are coupled because most developers would implement them together in the reducer without a clear boundary between the two.
The Clock / Leap second is a great example to consider because you have an event (the tick) that translate into a model (the clock) update.
When you implement that example with Redux 101, it looks simple and beautiful. When you need to implement the Leap Second, you need to change semantics because you don't have an action decoupled from the Model. It doesn't sound much but I feel this is nigh and day when you are writing 10s or 100s of thousands of lines of code.
Jean-Jacques Dubray
@jdubray
Dec 21 2016 00:42
Incidentally, the Daily Savings Time fits nicely with the state representation as it does not change the time clock or relies on a different number of ticks. So right there, with one of the simples example possible you can see SAM in action, while in Redux 101 would make it difficult to implement, you'd have to bring advanced Redux concept to implement it properly.
Why not yank Redux 101 and directly lead people towards the right path (thunks/action-creators and selectors)?
devin ivy
@devinivy
Dec 21 2016 01:32
@jdubray you have written many examples! but i do think that simple examples like this that illustrate your points, which seem subtle to many folks, would be useful! seeing the leap second in both "standard" redux and SAM would be cool.
Edward Mulraney
@edmulraney
Dec 21 2016 09:04
i agree - im finding it hard to visualise the problem with the leap second example. also a "standard redux" doesn't exist, there isn't supposed to be a standard, maybe you mean without any packages other than redux? it's kind of a pointless example if you compare against that because there are very few use cases of using redux (a purely syncronous lib) without some kind of async mechanism.. the go-to one being redux-thunk
its quite easy to set redux up to fail against an arbritrary standard when redux makes no claims about achieving said standard
Edward Mulraney
@edmulraney
Dec 21 2016 09:09
btw i dont care for blindly defending redux, despite how i often discuss it... im more interested in understanding if redux genuinely falls short of achieving some functionality which youre achieving in your SAM pattern
@foxdonut have you played with ant design yet?
Fred Daoud
@foxdonut
Dec 21 2016 12:18
@edmulraney not yet, but I plan to!
@jdubray your examples are great for understanding the concepts :thumbsup: do you have any examples to explain the need for nap(), the use cases for nap()?
Jean-Jacques Dubray
@jdubray
Dec 21 2016 14:16
@foxdonut it would be used to implement an alarm clock. The alarm state would trigger an action which in general would present its proposal to a completely different SAM instance (different from the SAM clock's instance).
Jean-Jacques Dubray
@jdubray
Dec 21 2016 14:27

@edmulraney The problem I was referring to is how do you design a clock that is aligned with the earth rotation (a very practical/real problem). To simplify, let's assume that:

  • you have access to a function p() that gives you the instant position of the earth
  • the "tick" is coming every second from a Caesium-133 atomic clock similar to the one (once again) invented by the Brittons in 1955.
    alt

How would you implement such a clock?

How would you implement the Daily Savings Time capability?
How would you implement sending an alarm each time a deviation from the earth position is accounted for?

I'll do it in SAM, you'll do it in Redux (any library allowed), then we compare notes?

Jean-Jacques Dubray
@jdubray
Dec 21 2016 14:36
@foxdonut what do you think about that question/example? would it be representative enough?
Fred Daoud
@foxdonut
Dec 21 2016 14:39
@jdubray interesting... it's a good example, but what about within a single SAM instance? I don't question the need for nap(), and "automatically trigger an action based on the current state of the application" is fine with me, but I was hoping for practical examples of where it's useful, since yours serve well to illustrate.
Jean-Jacques Dubray
@jdubray
Dec 21 2016 14:42
In the projects that I am working on, I use nap() all the time to correct the idiosyncracies of HTML (say you want to wire a date picker to an input field) but you probably would not consider that a proper SAM use case since I don't loop back via the model.
The fishing game had a nice nap() example, I am not sure how I would factor it otherwise.
Fred Daoud
@foxdonut
Dec 21 2016 14:46
cool
indeed for HTML I would call it something other than nap(), personally.
I've used nap() for validation, and for loading data within a tab the first time the user selects it.
Vincent Jo
@chiwoojo
Dec 21 2016 17:21
I felt that in redux there is a standard that was proposed which is that actions are synchronous.. the whole library is built that way and I'm tutorials where Dan teaches you the intro to redux there are no async actions which leads to confusion
Zach Dahl
@schtauffen
Dec 21 2016 18:25
@chiwoojo that is my preferred way to use redux: actions are synchronous. You then use a middleware (thunk, sagas, observable) to handle any asynchronous work
Fred Daoud
@foxdonut
Dec 21 2016 18:32
Any thoughts on using function-tree for the async work?
[
  dispatch(AUTHENTICATING),
  authenticateUser, {
    error: [
      dispatch(AUTHENTICATED_ERROR)
    ],
    success: [
      dispatch(AUTHENTICATED_SUCCESS),
      dispatch(ASSIGNMENTS_LOADING),
      getAssignments, {
        error: [
          dispatch(ASSIGNMENTS_LOADED_ERROR)
        ],
        success: [
          dispatch(ASSIGNMENTS_LOADED_SUCCESS)
        ]
      }
    ]
  }
]
Zach Dahl
@schtauffen
Dec 21 2016 19:05
I think function-tree would work nice assuming it gets wired the same way: middleware matches synchronous actions in order to kick off trees which then dispatch synchronous actions.
thunks actually don't fit in my "ideal" redux setup since they put async flow inside the action itself
(however, this is more inline with what SAM proposes)
devin ivy
@devinivy
Dec 21 2016 19:20
i think the function tree is very neat, but doesn't necessarily account for JJ's concern. ahhh cerebral :)