These are chat archives for jdubray/sam

10th
Mar 2017
Jean-Jacques Dubray
@jdubray
Mar 10 2017 15:04
@majo44 I "kind of" like the proxy approach. I would not use it myself but it seems to work well to "wire" elements of a pattern like SAM (I know you didn't try to implement SAM exactly). When it comes to middleware, I like the approach that express is taking (next). One of the drawback of the proxy approach is the lack of functional (de)composition for the actions. Just to be clear in SAM, actions cannot be composed, but a given action can be decomposed on composable functions which together form the proposal to the model. What I mean by "actions cannot be composed" is that logically an action cannot trigger another action, it can only present a proposal to the model, it is then nap() that would decide what is the next action.
majo44
@majo44
Mar 10 2017 16:30

Thanks a lot @jdubray . Proxy approach is very very flexible and provides a lot of options for "decorate" data flow , where you can in very canonical way:
express data mutations flow, eg:

    // middleware which makes your state immutable
    let immutableMiddleware = {
        set: function (model, p, v) {
            if (p == 'state') {
                model[p] = Immutable.fromJS(v);
            } else {
                model[p] = v;
            }
            return true;
        }
    };

or side effects eg.

  // middleware which logs updates on state
  let loggingMiddleware = {
            set: function (model, p, v) {
                if (p == 'state') {
                    let old = t[p];
                    model[p] = v;
                    log('state updated' , old, v);
                } else {
                   model[p] = v;
                }
                return true;
            }
        }

or even:

// middleware which sync the browser url with the state
var routerMiddleware = {
    set: function(model, p, v) {
        var oldValue = model[p];
        model[p] = v;
        if (p == 'route') {
            if (v !== oldValue) {
                window.history.pushState({}, '', v);
            }
        }
        return true;
    }
};
Jean-Jacques Dubray
@jdubray
Mar 10 2017 17:27
Yes I understand, as I said, I kind of like it. I guess it's like everything, once you get used to it, it works well for you. I also mentioned before that I tend to keep a clear separation between programming model, wiring and architecture. Proxies don't interfere with SAM's programming model, so it's definitely a viable way to wire the pattern.
I'll mention it, the wiring section of SAM's home page.