These are chat archives for jdubray/sam

May 2017
May 05 2017 12:16
Hi! Please tell me how to correctly implement View function in the SAM pattern in the case when make changes in DOM - not re-render.
For example, in the case of a scrolling custom gridview or table. After all, according to the rules of the SAM,
the View is computed and the corresponding function should not contain side effects. Thank you
Jean-Jacques Dubray
May 05 2017 12:45
@Kiselb One way you could do it is by packaging the DOM manipulations into a function that is passed to the view components. The Fishing Game provides an example.
One of the elements of the state representation is one of these functions (draw which returns a function):
               var stateRepresentation = {
                    rect: draw(model.rect.startX, model.rect.startY, model.rect.w, model.rect.h,model.color),
                    fishes: model.selectedFishes

                view.display(stateRepresentation) ;
The view component then calls the rect function while passing some context such that the state function is somewhat decoupled from the view components and view structure:
net(net, fishes) {
         // draw the net
        net.rect(this.ctx,this.canvas) ;
        if (fishes>0) {
                var _fishes = (fishes>1)? ' fishes!' : ' fish' ;
                net.caught.innerHTML = " you caught "+fishes+_fishes ;
            } else {
                net.caught.innerHTML = "" ;
Jean-Jacques Dubray
May 05 2017 12:50
The context would be model independent of course.