toStream
Provide a shorthand for creating a stream on properties and/or events.
DefineMap.toStream( propAndOrEvent[,event] )
Creates a stream that gets updated whenever the property value changes or event is triggered.
import DefineMap from "can-define/map/map";
import canStream from "can-stream-kefir";
import canDefineStream from "can-define-stream";
const Person = DefineMap.extend( {
name: "string",
lastValidName: {
stream: function() {
return this.toStream( ".name" ).filter( function( name ) { // using propName
return name.indexOf( " " ) >= 0;
} );
}
}
} );
canDefineStream( canStream )( Person );
const me = new Person( { name: "James" } );
me.on( "lastValidName", function( lastValid ) {} );
me.name = "JamesAtherton"; //lastValidName -> undefined
me.name = "James Atherton"; //lastValidName -> James Atherton
Parameters
- prop
{String}
:A property name prepended by a dot '.prop'
- event
{String}
:An event name 'event'
- propAndEvent
{String}
:A property name prepended by a dot follow by an event name seperated by a space '.prop event'