These are chat archives for jdubray/sam

18th
Mar 2017
Michael Solovyov
@msolovyov
Mar 18 2017 19:18
Anyone run into issues where their model.present is too large and unweildy, how did you restructure?
Jean-Jacques Dubray
@jdubray
Mar 18 2017 22:43
I created a component model
The SAM components have Actions and Acceptors (updates)
var menu = {

    updates: [

        { 
            name: "setMenuItem",
            order: 0,
            update: function(model,data) {
             // change menu item
                if (data.menuItem) {
                    model.data.popped = data.popped || false ;
                    model.data.menuItem = data.menuItem ;
                    model.data.header.menu.map((item) => item.active = (item.href === data.menuItem)) ;
                    model.update.p = true ;
                    model.update.h = true ;
                    model.update.f = true ;
                    if (model.data.home.blog.blogid) { delete model.data.home.blog.blogid ; }
                }
            }
        }

    ],

    actions: [

        { 
            name: "setMenuItem",
            implementation: function(data, present, model) {
                data = data || { menuItem : "home" } ;
                data.__action = 'setMenuItem' ;
                if (model) { 
                    model.present(data) ;
                } else {
                    present(data) ;
                }
                return false ;
            }
        }
    ]

}
They are simply mounted to the model at initialization time, though it could also be dynamic.
The idea though is to keep actions and acceptors decoupled from view components.
The view components are implemented in the theme and should either listen to (Angular2) or invoked with their properties, in return they should publish events that trigger actions which can be mounted via intents.
Jean-Jacques Dubray
@jdubray
Mar 18 2017 22:49
@msolovyov I don't believe it is wise to create view components (properties,events) with actions and model/acceptor.
If you need more details or have a better approach, let me know.
Any implementation should support a many-to-many relationship between actions and acceptors:
  • one action could trigger (unwittingly) one or more acceptors
  • many actions could trigger the same acceptor
Michael Solovyov
@msolovyov
Mar 18 2017 22:54
I'm only talking about the model.present method. http://sam.js.org/#model
Michael Solovyov
@msolovyov
Mar 18 2017 22:59
My model that houses the data and the present method is separate from any components. Actions prepare a data object that gets passed to model.present
Jean-Jacques Dubray
@jdubray
Mar 18 2017 22:59
yes, this the updates in the component, you don't need actions.
That would allow to code and test independent accpetors/updates and assemble them at instantiation time.
a "component" would only be an array of acceptors, you could have any number of "components"
Michael Solovyov
@msolovyov
Mar 18 2017 23:20
Do you have an example of an array of acceptors?
Jean-Jacques Dubray
@jdubray
Mar 18 2017 23:28
The example above is implemented with arrays, you can just keep actions as an empty array.
Michael Solovyov
@msolovyov
Mar 18 2017 23:31
Where is the present method?
This is what it looks like:
present(data,next) {
        data = data || {} ;

        this.applyFilters(data) ;

        this.CRUD(data) ;    

        this.postProcessing() ;

        if (this.update.render) { this.state.render(model,next) ; }
    }
for instance:
CRUD(data) {

        // CRUD
        let self = this ;
        this.components.updates.forEach( (_) => {
            _.update(self,data)
        }) ;

    },
that's where the acceptors are iterated over
Michael Solovyov
@msolovyov
Mar 18 2017 23:43
Great , thank you!