diff --git a/bower.json b/bower.json index 2e39c8e22..d8b12aa6a 100644 --- a/bower.json +++ b/bower.json @@ -1,6 +1,6 @@ { "name": "rxjs", - "version": "2.2.27", + "version": "2.2.28", "main": [ "dist/rx.all.js", "dist/rx.all.min.js", diff --git a/doc/api/helpers/readme.md b/doc/api/helpers/readme.md index ef7cd12a6..6ca01fa65 100644 --- a/doc/api/helpers/readme.md +++ b/doc/api/helpers/readme.md @@ -4,14 +4,80 @@ Helper functions for the Reactive Extensions for JavaScript ## Documentation ## +- [`Rx.helpers.defaultComparer`](#rxhelpersdefaultcomparerx-y) +- [`Rx.helpers.defaultSubComparer`](#rxhelpersdefaultsubscomparerx-y) - ['Rx.helpers.defaultError'](#rxhelpersdefaulterror) - [`Rx.helpers.identity`](#rxhelpersidentityx) - [`Rx.helpers.isPromise`](#rxhelpersispromisep) - [`Rx.helpers.just`](#rxhelpersjustvalue) - [`Rx.helpers.noop`](#rxhelpersnoop) +- [`Rx.helpers.pluck`](#rxhelperspluckproperty) * * * +### `Rx.helpers.defaultComparer(x, y)` +#[Ⓢ](https://github.com/Reactive-Extensions/RxJS/blob/master/src/core/basicheader.js "View in source") [Ⓣ][1] + +The default equality comparer, used when a comparer is not supplied to a function. Uses an internal deep equality check. + +#### Arguments +1. `x` *(Any)*: The first value to compare +2. `y` *(Any)*: The second value to compare + +#### Returns +*(Boolean)*: `true` if equal; else `false`. + +#### Example + +```js +var comparer = Rx.helpers.defaultComparer; + +// Should return true +var x = 42, y = 42 +console.log(comparer(x, y)); +// => true + +// Should return false +var x = new Date(0), y = new Date(); +console.log(comparer(x, y)); +// => false +``` +* * * + +### `Rx.helpers.defaultSubcomparer(x, y)` +#[Ⓢ](https://github.com/Reactive-Extensions/RxJS/blob/master/src/core/basicheader.js "View in source") [Ⓣ][1] + +The default comparer to determine whether one object is greater, less than or equal to another. + +#### Arguments +1. `x` *(Any)*: The first value to compare +2. `y` *(Any)*: The second value to compare + +#### Returns +*(Number)*: Returns `1` if `x` is greater than `y`, `-1` if `y` is greater than `x`, and `0` if the objects are equal. + +#### Example + +```js +var comparer = Rx.helpers.defaultSubcomparer; + +// Should return 0 +var x = 42, y = 42 +console.log(comparer(x, y)); +// => 0 + +// Should return -1 +var x = new Date(0), y = new Date(); +console.log(comparer(x, y)); +// => -1 + +// Should return 1 +var x = 43, y = 42; +console.log(comparer(x, y)); +// => 1 +``` +* * * + ### `Rx.helpers.defaultError(err)` #[Ⓢ](https://github.com/Reactive-Extensions/RxJS/blob/master/src/core/basicheader.js "View in source") [Ⓣ][1] @@ -77,6 +143,29 @@ Rx.Observable.timer(100) ``` * * * +### `Rx.helpers.isPromise(p)` +#[Ⓢ](https://github.com/Reactive-Extensions/RxJS/blob/master/src/core/basicheader.js "View in source") [Ⓣ][1] + +A function which determines whether the object is a `Promise`. + +#### Arguments +1. `p` *(Any)*: The object to determine whether it is a promise. + +#### Returns +*(Boolean)*: `true` if the object is a `Promise` else `false` + +#### Example + +```js +var isPromise = Rx.helpers.isPromise; + +var p = RSVP.Promise(function (res) { res(42); }); + +console.log(isPromise(p)); +// => true +``` +* * * + ### `Rx.helpers.noop()` #[Ⓢ](https://github.com/Reactive-Extensions/RxJS/blob/master/src/core/basicheader.js "View in source") [Ⓣ][1] @@ -92,28 +181,30 @@ noop(); ``` * * * -### `Rx.helpers.isPromise(p)` -#[Ⓢ](https://github.com/Reactive-Extensions/RxJS/blob/master/src/core/basicheader.js "View in source") [Ⓣ][1] +### `Rx.helpers.pluck(property)` +#[Ⓢ](https://github.com/Reactive-Extensions/RxJS/blob/master/src/core/basicheader.js "View in source") [Ⓣ][1] -A function which determines whether the object is a `Promise`. +Plucks a property from the object. #### Arguments -1. `p` *(Any)*: The object to determine whether it is a promise. +1. `property` *(String)*: The property name to pluck from the object. #### Returns -*(Boolean)*: `true` if the object is a `Promise` else `false` +*(Boolean)*: `true` if equal; else `false`. #### Example ```js -var isPromise = Rx.helpers.isPromise; +var pluck = Rx.helpers.pluck; -var p = RSVP.Promise(function (res) { res(42); }); +var source = Rx.Observable.interval(1000) + .timeInterval() + .map(pluck('value')) + .take(3); -var isPromise(p); -console.log(p); -// => true +source.subscribe(console.log.bind(console)); +// => 0 +// => 1 +// => 2 ``` * * * - - diff --git a/package.json b/package.json index d175baecb..9debdc62a 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,7 @@ "name": "rx", "title": "Reactive Extensions for JavaScript (RxJS)", "description": "Library for composing asynchronous and event-based operations in JavaScript", - "version": "2.2.27", + "version": "2.2.28", "homepage": "https://github.com/Reactive-Extensions/RxJS", "author": { "name": "Cloud Programmability Team", @@ -20,7 +20,7 @@ ], "bugs": "https://github.com/Reactive-Extensions/RxJS/issues", "jam": { - "main": "rx.js" + "main": "dist/rx.all.js" }, "dependencies": {}, "devDependencies": { diff --git a/readme.md b/readme.md index 372b623d9..7be13c2cf 100644 --- a/readme.md +++ b/readme.md @@ -45,15 +45,15 @@ But the best news of all is that you already know how to program like this. Tak var source = getStockData(); source - .filter(function (quote) { - return quote.price > 30; - }) - .map(function (quote) { - return quote.price; - }) - .forEach(function (price) { - console.log('Prices higher than $30: $' + price); - }); + .filter(function (quote) { + return quote.price > 30; + }) + .map(function (quote) { + return quote.price; + }) + .forEach(function (price) { + console.log('Prices higher than $30: $' + price); + }); ``` Now what if this data were to come as some sort of event, for example a stream, such as as a WebSocket, then we could pretty much write the same query to iterate our data, with very little change. @@ -63,19 +63,19 @@ Now what if this data were to come as some sort of event, for example a stream, var source = getAsyncStockData(); var subscription = source - .filter(function (quote) { - return quote.price > 30; - }) - .map(function (quote) { - return quote.price; - }) - .subscribe( - function (price) { - console.log('Prices higher than $30: $' + price); - }, - function (err) { - console.log('Something went wrong: ' + err.message); - }); + .filter(function (quote) { + return quote.price > 30; + }) + .map(function (quote) { + return quote.price; + }) + .subscribe( + function (price) { + console.log('Prices higher than $30: $' + price); + }, + function (err) { + console.log('Something went wrong: ' + err.message); + }); /* When we're done */ subscription.dispose(); @@ -111,10 +111,10 @@ One question you may ask yourself, is why RxJS? What about Promises? Promises To give you an idea about rich composition, we can create an autocompletion service which takes the user input from a text input and then query a service, making sure not to flood the service with calls for every key stroke, but instead allow to go at a more natural pace. First, we'll reference the JavaScript files, including jQuery, although RxJS has no dependencies on jQuery... - - - - +```html + + +``` Next, we'll get the user input from an input, listening to the keyup event by using the `Rx.Observable.fromEvent` method. This will either use the event binding from [jQuery](http://jquery.com), [Zepto](http://zeptojs.com/), [AngularJS](https://angularjs.org/) and [Ember.js](http://emberjs.com/) if available, and if not, falls back to the native event binding. This gives you consistent ways of thinking of events depending on your framework, so there are no surprises. ```js @@ -214,6 +214,13 @@ You can find the documentation [here](https://github.com/Reactive-Extensions/RxJ - [RxJS Koans](https://github.com/mattpodwysocki/RxJSKoans) - [Rx Workshop](http://rxworkshop.codeplex.com/) - [The introduction to Reactive Programming you've been missing](https://gist.github.com/staltz/868e7e9bc2a7b8c1f754) + - [Reactive Programming and MVC](http://aaronstacy.com/writings/reactive-programming-and-mvc/) + +- Examples + - [React RxJS Autocomplete](https://github.com/eliseumds/react-autocomplete) + - [React RxJS TODO MVC](https://github.com/fdecampredon/react-rxjs-todomvc) + - [Ninya.io - Angular + RxJS + rx.angular.js](https://github.com/ninya-io/ninya.io) - [Site](http://stackwho.herokuapp.com/) + - [Reactive Trader](https://github.com/AdaptiveConsulting/ReactiveTrader) - [Site](https://reactivetrader.azurewebsites.net/) - Presentations - Don't Cross the Streams - Cascadia.js 2012 [slides/demos](http://www.slideshare.net/mattpodwysocki/cascadiajs-dont-cross-the-streams) | [video](http://www.youtube.com/watch?v=FqBq4uoiG0M) @@ -230,11 +237,13 @@ You can find the documentation [here](https://github.com/Reactive-Extensions/RxJ - [Adding Even More Fun to Functional Programming With RXJS - Ryan Anklam](https://www.youtube.com/watch?v=8EExNfm0gt4) - Reference Material + - [RxJS GitBook](http://xgrommx.github.io/rx-book/) - [Intro to Rx](http://introtorx.com/) - [101 Rx Samples Wiki](http://rxwiki.wikidot.com/101samples) - [Rx Design Guidelines](http://go.microsoft.com/fwlink/?LinkID=205219) - [Beginners Guide to Rx](http://msdn.microsoft.com/en-us/data/gg577611) + - Books - [Intro to Rx](http://www.amazon.com/Introduction-to-Rx-ebook/dp/B008GM3YPM/) - [Programming Reactive Extensions and LINQ](http://www.amazon.com/Programming-Reactive-Extensions-Jesse-Liberty/dp/1430237473/) @@ -245,22 +254,29 @@ There are a number of ways to get started with RxJS. The files are available on ### Download the Source - git clone https://github.com/Reactive-Extensions/rxjs.git - cd ./rxjs +```bash +git clone https://github.com/Reactive-Extensions/rxjs.git +cd ./rxjs +``` ### Installing with [NPM](https://npmjs.org/) - npm install rx - npm install -g rx - WARNING: 'npm install rxjs' will install an old, out of date, 3rd party version of Rx. +```bash` +npm install rx +npm install -g rx +``` ### Using with Node.js and Ringo.js - var Rx = require('rx'); +```js +var Rx = require('rx'); +``` ### Installing with [Bower](http://bower.io/) - bower install rxjs +```bash +bower install rxjs +``` ### Installing with [Jam](http://jamjs.org/) @@ -287,27 +303,31 @@ There are a number of ways to get started with RxJS. The files are available on ### In a Browser: - - +```html + + - - + + - - + + +``` ### Along with a number of our extras for RxJS: - - - - - - - - - - +```html + + + + + + + + + + +``` ### Using RxJS with an AMD loader such as Require.js @@ -350,7 +370,7 @@ You can contribute by reviewing and sending feedback on code checkins, suggestin Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. Microsoft Open Technologies would like to thank its contributors, a list -of whom are at http://rx.codeplex.com/wikipage?title=Contributors. +of whom are at https://github.com/Reactive-Extensions/RxJS/wiki/Contributors. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may