These are chat archives for jdubray/sam

14th
Apr 2016
Jean-Jacques Dubray
@jdubray
Apr 14 2016 00:10
@devinivy yes, this is what I call "wiring", you really have to do distinguish between programming model (reducer versus propose/accept), wiring (streams, functions, promises,...) and architecture (where the elements of the pattern can run).
I feel that SAM offers the most flexible set of choices, but I am biased...
Jean-Jacques Dubray
@jdubray
Apr 14 2016 03:32
From the Netflix presentation: "we moved away from this highly observable model", "no sense of ownership", "no one way to driving effects"
blob
David Fall
@509dave16
Apr 14 2016 03:56
@jdubray Thank you for your article regarding moving away from MVC: http://www.infoq.com/articles/no-more-mvc-frameworks! I have recently learned React and Firebase with which I built a simple local/cross browser Tic Tac Toe app. I wanted to clean up my component state management, so I spent the last 3 days learning Redux. But then I saw how complicated Redux became when handling Asynchronous Code and API calls. I'm going to try and apply the SAM pattern instead and hopefully something amazing will come out :) ! Your pattern seems to be indispensable, since it's application is not limited.
Jean-Jacques Dubray
@jdubray
Apr 14 2016 03:57
thank you for your feedback! It is my expectation that it will be simpler. Let me know if you have any question, happy to help.
David Fall
@509dave16
Apr 14 2016 03:59
@jdubray Will do. I'm bound to hit some road blocks as I transition/rewrite the codebase.
weepy
@weepy
Apr 14 2016 06:08
Sounds like a great case study @509dave16 !
iwangheng
@iwangheng
Apr 14 2016 06:13
if i want use some existing componet write by jquery,angular or react with SAM , is there a easy way?
Jean-Jacques Dubray
@jdubray
Apr 14 2016 07:24
@iwangheng It depends, you can use SAM in a "headless way" where the components would drive Requests/Responses
Jean-Jacques Dubray
@jdubray
Apr 14 2016 07:48
@509dave16 you may want to take a look at the Time Travel dev tool that @gunar wrote
https://www.npmjs.com/package/sam-devtools
Robert Blixt
@devghost
Apr 14 2016 11:17
Noob here... are there any good examples on how to test with SAM? Took a shoot at it (http://codepen.io/devghost/pen/eZWxmo) but I'm guessing it's not the recommended way.
*shot
David Fall
@509dave16
Apr 14 2016 15:35
@weepy Yeah. It seems very simple, but keeping two clients in sync and allowing/disallowing actions makes it a little tricky. Definitely going to need to define all the possible states and there corresponding actions to keep everything orderly.
@jdubray I will take a look. Bound to be useful. Thanks for the piece of advice!
Jean-Jacques Dubray
@jdubray
Apr 14 2016 21:09
@509dave16 the SAFE middleware supports checking for allowed actions. It also supports a mode where multiple actions (long running) can be triggered and have only one being presented to the model (action hang back) https://www.npmjs.com/package/sam-safe
@devghost let me take a look
David Fall
@509dave16
Apr 14 2016 21:14
@jdubray Cool. I will look into incorporating that middleware.
David Fall
@509dave16
Apr 14 2016 21:23
@jdubray Would you consider the 'dataset' presented to the Model as conveying some intent? Since Actions don't directly mutate the Model, which is the Model's responsibility, indicating to the Model that CRUD actions should be performed involves declarative property names on the 'dataset'. From the 'crud-blog' sample, the following property on the dataset is used: "data.deletedItemId".
devin ivy
@devinivy
Apr 14 2016 21:27
i am also wondering about this. why not switch on an action type rather than looking at the shape of an object?
action.type === 'delete_item' versus typeof data.deleteItem !== undefined
David Fall
@509dave16
Apr 14 2016 21:28
It seems to me that anytime you make a Model, you would want document the schema of the 'dataset' parameter. Then anyone who is writing Actions knows what data to present to the Model.
@devinivy Thanks for the example! There seems to be quite a few ways you could indicate a CRUD operation. However 'deleteItem' and 'deleteItemId' are very concrete. I like that you pointed out:action.type === 'delete_item', which is less concrete, more dynamic, and makes the Model more concise when dealing with multiple Resources that might need to be manipulated. This also looks very similar to Redux.
devin ivy
@devinivy
Apr 14 2016 21:36
placing a string in a type property is part of a larger sort of standard some refer to as "flux standard actions" or FSAs. i suppose it's sort of the (very relaxed) protocol of many flux libraries :)
i'm personally trying to figure out how to use this library (posted here a couple days ago) to have "better" actions. https://github.com/paldepind/union-type
David Fall
@509dave16
Apr 14 2016 22:44

@devinivy 'union-type' appears to be a good choice for building action creators without using 'strings' as the 'type' in the Action object, but instead 'Types' I guess. However it's unfortunate that you have to do this when calling a curried <Type>.caseOn or <Type>.case : advancePlayer(Action.Up(), player);. I guess you could always do something like

const actions = { Up : Action.Up(), etc.. };
advancePalyer(actions.Up, player);

or have it exported using ES6 syntax const Up = Action.Up(); export Up; or CommonJS.