fairmont-reactive
Advanced tools
Comparing version 1.0.0-beta-25 to 1.0.0-beta-26
{ | ||
"name": "fairmont-reactive", | ||
"version": "1.0.0-beta-25", | ||
"version": "1.0.0-beta-26", | ||
"description": "Functional reactive programming in JavaScript and CoffeeScript.", | ||
@@ -5,0 +5,0 @@ "files": [ |
133
README.md
@@ -1,106 +0,77 @@ | ||
# Fairmont/Reactive | ||
# Fairmont-Reactive | ||
[Fairmont][0]/Reactive is a JavaScript library for functional reactive programming. | ||
Fairmont-Reactive is a JavaScript library for functional reactive programming. It's part of the [Fairmont][] library. | ||
[0]:https://github.com/pandastrike/fairmont | ||
## Installation | ||
Here's a simple 'hello, world' Web server written in a functional, reactive style using Fairmont. | ||
`npm install fairmont-reactive` | ||
### In JavaScript | ||
## Examples | ||
```javascript | ||
start(flow([ | ||
Here's a simple reactive Web app implementing a counter using Fairmont's Reactive programming functions. | ||
events("request", server), | ||
In JavaScript: | ||
select(spread(function(request) { | ||
return request.method === "GET"; | ||
})), | ||
```javascript | ||
var $ = require("jquery"), | ||
F = require("fairmont"); | ||
select(spread(function(request) { | ||
return request.url === "/"; | ||
})), | ||
$(function() { | ||
tee(spread(function(ignored, response) { | ||
response.statusCode = 200; | ||
response.write("hello, world"); | ||
response.end(); | ||
})), | ||
var data = { counter: 0 }; | ||
map(spread(logger)); | ||
F.start(F.flow([ | ||
F.events("click", $("a[href='#increment']")), | ||
F.map(function() { data.counter++; }) | ||
])); | ||
])); | ||
``` | ||
F.start(F.flow([ | ||
F.events("change", F.observe(data)), | ||
F.map(function() { | ||
$("p.counter") | ||
.html(data.counter); | ||
}) | ||
])); | ||
}); | ||
### In CoffeeScript | ||
```coffee | ||
start flow [ | ||
events "request", server | ||
select spread (request) -> request.method == "GET" | ||
select spread (request) -> request.url == "/" | ||
tee spread (ignored, response) -> | ||
response.statusCode = 200 | ||
response.write "hello, world" | ||
response.end() | ||
map spread logger | ||
] | ||
``` | ||
## Examples | ||
In CoffeeScript: | ||
You can get a feel for what [Fairmont][0] can do for you by [checking out the examples](./examples). | ||
```coffeescript | ||
{start, flow, events, map, observe} = require "fairmont-reactive" | ||
## Introduction | ||
$ = require "jquery" | ||
### Iterators | ||
$ -> | ||
An _iterator_ is an ES6 iterator, with a `next` function that produces a value wrapper. | ||
A _value wrapper_ is what iterators produce, with `done` and `value` properties. | ||
These are part of the ES6 standard. | ||
data = counter: 0 | ||
### Reactors | ||
start flow [ | ||
events "click", $("a[href='#increment']") | ||
map -> data.counter++ | ||
] | ||
An _asynchronous iterator_ is an iterator that produces promises that resolve to value wrappers. | ||
These are a proposed part of ES7. | ||
An _asynchronous iterator function_ is a function that returns promises that resolve to value wrappers. | ||
start flow [ | ||
events "change", observe data | ||
map -> | ||
$("p.counter") | ||
.html data.counter | ||
] | ||
``` | ||
A _reactor_ is [Fairmont][0] lingo for an asynchronous iterator. | ||
Check out our other reactive examples: | ||
When talking about values that could be iterators or reactors, we will sometimes say _producers_. | ||
- an [echo server][] | ||
- a [Web server][] | ||
- a [file watcher][] | ||
### Adapters, Filters, and Reducers | ||
[echo server]:https://github.com/pandastrike/fairmont-reactive/blob/master/examples/echo-server.litcoffee | ||
[Web server]:https://github.com/pandastrike/fairmont-reactive/blob/master/examples/web-server.litcoffee | ||
[file watcher]:https://github.com/pandastrike/fairmont-reactive/blob/master/examples/file-watcher.litcoffee | ||
An _adapter_ creates a producer (an iterator or reactor) from a non-producer. | ||
An _iterator filter_ is a function that takes an iterator and returns another iterator. | ||
Iterator filters are just called _filters_ for convenience whenever it isn't ambiguous. | ||
## Documentation | ||
An _iterator reducer_ is a function that takes an iterator and returns a value that isn't an iterator. | ||
Iterator reducers are just called _reducers_ for convenience whenever it isn't ambiguous. | ||
Check out the [wiki][] for an getting started guides, tutorials, and reference documentation. | ||
When talking about functions that could be adapters, filters, or reducers, we will sometimes say _transforms_. | ||
### Polymorphic Filters And Reducers | ||
Most transforms are implemented for both iterators and reactors. | ||
For example, if we pass an iterator to `map` we'll get back an iterator. Whereas if we pass it a reactor, we'll get back a reactor. | ||
Similarly, if we pass an iterator to `collect` we'll get back an array. | ||
If we pass it a reactor, we'll get back a promise that resolves to an array. | ||
Many values that aren't iterators or reactors will be coerced into one or the other when passed to a transform or reduction. | ||
For example, if you pass an array into `map`, the array will be coerced into an iterator. | ||
Similarly, if you pass a promise into `map`, the promise will be coerced into a reactor. | ||
## About Fairmont | ||
[Fairmont][0] takes full advantage of ES6+ features like iterators (including async iterators, called _reactors_), generators, and promises. Inspired by libraries like [Underscore](http://underscorejs.org/) and many others, [Fairmont][0] features include: | ||
* reactive programming support through async iterators | ||
* lazy evaluation on collection operations via iterators | ||
* core functional operations, like currying and composition | ||
* bridge functions for integrating with OOP-based libraries | ||
* common file and stream based operations | ||
* streams and event emitters modeled as reactors | ||
* seamless integration between synchronous and asynchronous operations | ||
* … and more! | ||
## Status | ||
@@ -114,2 +85,4 @@ | ||
[200]:https://github.com/pandastrike/fairmont/issues | ||
[tickets]:https://github.com/pandastrike/fairmont/issues | ||
[Fairmont]:https://github.com/pandastrike/fairmont | ||
[wiki]:https://github.com/pandastrike/fairmont/wiki |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
52223
88