toStreamFromProperty
Create a stream based on a property
DefineMap.toStreamFromProperty( property )
Creates a stream from a property that gets updated whenever the property value changes.
import DefineMap from "can-define/map/map";
import canDefineStreamKefir from "can-define-stream-kefir";
const Person = DefineMap.extend( {
name: "string",
lastValidName: {
stream: function() {
return this.toStreamFromProperty( ".name" ).filter( function( name ) { // using propName
return name.indexOf( " " ) >= 0;
} );
}
}
} );
canDefineStreamKefir( 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
- property
{String}
:A property name prepended by a dot. '.prop'