Skip to content

canjs/can-rx

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

18 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

can.rx

can.rx is a CanJS plugin that lets you create RxJS Observables from CanJS event handlers, as well as feed Observable streams back into CanJS observables. The result is a delicious, canned-bacon-flavored mix of FRP and CanJS-style declarative MVC.

can.rx implements the can.eventstream interface and adds a few methods to RxJS objects (documented below). For information on the CanJS side of the interface, please refer to can.eventstream's documentation.

Check out dist/sandbox.html and dist/sandbox.js for some rough usage examples, including a fairly short drag-and-drop demo using can.Component, and super-simple, single-line two-way binding between pairs of computes and pairs of can.Maps.

can.rx is hosted at Github. can.rx is a public domain work, dedicated using CC0 1.0. Feel free to do whatever you want with it.

Quickstart

Install

$ npm install can.rx or $ bower install can.rx

Prebuilt releases are included in dist.

Example

var compute = can.compute(),
    observable = compute.bind();

observable.subscribe(function(x) { console.log("Value changed: ", x); });

compute(1);

observable.toCompute().bind("change", function() {
  console.log("compute updated from property change.");
});

compute(2);

Documentation

For the most part, can.rx is a straightforward implementation of the can.eventstream interface.

can.rx also extends Rx.Observable.prototype with a few utility methods that directly wrap can.eventstream functions, documented below.

Rx.Observable#toCompute([compute=can.compute()])

Wraps can.bindComputeFromStream.

stream.toCompute(compute) is the same as can.bindComputeFromStream(stream, compute);

Rx.Observable#toMap([map=new can.Map()])

Wraps can.bindMapFromStream.

stream.toMap(compute) is the same as can.bindMapFromStream(stream, compute);

Rx.Observable#toList([list=new can.List()])

Wraps can.bindListFromStream.

stream.toList(compute) is the same as can.bindListFromStream(stream, compute);