can-stream-kefir
Convert observable values into streams. Kefir is used to provide the stream functionality.
Object
The can-stream-kefir
module exports methods useful for converting observable values like can-computes
or can-define/map/map properties into streams.
import canStream from "can-stream-kefir";
import DefineMap from "can-define/map/map";
const me = new DefineMap( { name: "Justin" } );
const nameStream = canStream.toStream( me, ".name" );
nameStream.onValue( function( name ) {
// name -> "Obaid";
} );
me.name = "Obaid";
Usage
The toStream method takes a compute and returns a Kefir stream instance.
var canStream = require("can-stream-kefir");
canStream.toStream(compute) //-> stream
For example:
Converting a compute to a stream
import canCompute from "can-compute";
import canStream from "can-stream-kefir";
const compute = canCompute( 0 );
const stream = canStream.toStream( compute );
stream.onValue( function( newVal ) {
console.log( newVal );
} );
compute( 1 );
//-> console.logs 1