These are chat archives for canjs/canjs

18th
Nov 2016
Gerard Finnerty
@halcyonandon
Nov 18 2016 00:43
@justinbmeyer I was reading http://forums.donejs.com/t/canjs-roadmap-discussion/75 and it got me wondering, have you guys ever discussed rendering canjs to canvas? Like Flipboard react-canvas... https://github.com/Flipboard/react-canvas
Justin Meyer
@justinbmeyer
Nov 18 2016 04:10
@halcyonandon I've thought about it ... but haven't had a canvas based project in a while
btw, everyone ... for this API
var saltShaker = new SaltShaker();

saltShaker.fill();  

saltShaker.shake() //-> "salt"
saltShaker.shake() //-> "salt"  
saltShaker.shake() //-> null   

saltShaker.empty   //-> true
It can be implemented like this imperatively:
SaltShaker = can.DefineMap.extend({
    saltCount: {type: "number", value: 0},
    fill: function(){
        this.saltCount = 2;
    },
    shake: function(){
        var hasSalt = this.saltCount
        this.saltCount = hasSalt ? this.saltCount - 1 : 0;
        return hasSalt ? "salt" : null
    },
    get empty() {
        return ! this.saltCount
    }
});
or like this declaratively with the can-define-stream
var SaltShaker = can.DefineMap.extend({
    saltCount: {
        stream: function() {
            console.log("YES")
          return this.stream("fill")
                    .merge(this.stream("shake"))
                    .scan(function(prev, ev){
                if(ev.type === "fill") {
                    return 2;
                } else {
                    return prev > 0 ? prev - 1 :  0;
                }
            },0);
        }
    },
    fill: function() {
        this.dispatch("fill");
    },
    shake: function() {
        var hadSalt = this.saltCount;
        this.dispatch("shake");
        return hadSalt ? "salt" : null;
    },
    get empty() {
        return !this.saltCount;
    }
});
Justin Meyer
@justinbmeyer
Nov 18 2016 16:26
DoneJS Contributors Meeting: https://www.youtube.com/watch?v=Lt9Ctdo9PAw
Frank Lemanschik
@frank-dspeed
Nov 18 2016 16:55
The answer to the sync problem google couchbase snync gateway :)