can-define-stream
module
Define property values using streams. can-stream is used internally to provide the stream functionality.
undefined
The can-define-stream module doesn't export anything. Instead it changes
can-define to support the stream behavior and
can-define/map/map and can-define/list/list to have a stream method that's
a shorthand for toStream.
require("can-define-stream");
var DefineMap = require("can-define/map/map");
var Person = DefineMap.extend({
first: "string",
last: "string"
get fullName() {
return this.first + " " + this.last;
},
fullNameChangeCount: {
stream: function(setStream) {
return this.stream(".fullName").scan(function(last){
return last + 1;
},0)
}
}
});
var me = new Person({first: "Justin", last: "Meyer"});
me.on("fullNameChangeCount", function(ev, newVal){
console.log(newVal);
});
me.fullNameChangeCount //-> 0
me.first = "Obaid"
//-> console.logs 1
me.last = "Ahmed"
//-> console.logs 2