These are chat archives for jdubray/sam

29th
Sep 2017
Jean-Jacques Dubray
@jdubray
Sep 29 2017 02:05
I have seen the future...
Rob Siera
@robsiera
Sep 29 2017 07:14
1/ model is calling a model.render() which points to safe.render(). state.render() is never used.
2/ damn, with "These days, I tend to organize the view as a "theme" with a single entry point." I'm loosing you again. Need to do some more digging.
Rob Siera
@robsiera
Sep 29 2017 07:32
some searching in gitter history clarified some stuff. But regarding 1/, it would be nice if you could confirm my observation that state.render() is never used in your SAFE component.
Jean-Jacques Dubray
@jdubray
Sep 29 2017 10:40
@robsiera SAFE is a micro-container so it's purpose is to rewire the standard pattern implementation to augment it with its functionality.
I confirm that "render" was reimplemented in safe.js to support the SAFE services:
safe.render = (model,next, takeSnapShot) => {
    takeSnapShot = takeSnapShot || true ;
    if (takeSnapShot && safe.saveSnapshot) {
        // Store snapshot in TimeTravel
        safe.saveSnapshot(model,null) ;
    }
    safe.allowedActions = safe.state.representation(model,next) || [] ;
    safe.unblock() ;
    safe.lastStep = safe.newStep(safe.stepCount++, safe.allowedActions) ;
    safe.sessionManager.dehydrateSession(model) ;
    safe.state.nextAction(model) ;
} ;
Jean-Jacques Dubray
@jdubray
Sep 29 2017 10:47
As I mentioned earlier, state.js was the standard SAM implementation and the purpose of SAFE was to be a container for any standard SAM implementation.
I don't want to constrain people in a single implementation. Some solutions need a control state structures, others are more "page" oriented.
This implementation of the "bootstrap clean blog" supports page navigation: https://github.com/jdubray/startbootstrap-clean-blog
The theme.js file supports a simple "page" implementation:
page(params) {
        if (params.menuItem === 'home') {
            return this.home(params.home) ;
        } else {
            if (this[params.menuItem] !== undefined) {
                return this[params.menuItem](params[params.menuItem]) ;
            } else {
                return this.fullPage(params[params.menuItem]) ; 
            }
        }
    }
Jean-Jacques Dubray
@jdubray
Sep 29 2017 10:52
Alternatively you could achieve result with control states in the state function, but it seems easier to move that in the view (theme).
It's just one line of code: return this[params.menuItem](params[params.menuItem]) ;
Rob Siera
@robsiera
Sep 29 2017 12:00
:+1: