Skip to content

Latest commit

 

History

History
86 lines (67 loc) · 2.56 KB

README.md

File metadata and controls

86 lines (67 loc) · 2.56 KB

Functional Reactive Programming for JavaScript

Contributors, pull requests, and issues welcome!

Have a look at the annotated source code.

Check out the meager test suite.

What is FRP?

Inspiration

Why not Elm?

Elm is really cool, but it's Haskell that compiles to JavaScript. Transpiling gives me the willies. Until native debugging for the languages is available in most browsers, you'll still need to understand the JavaScript environemnt in order to find issues.

Why not Flapjax?

Flapjax is also cool, but it's self-contained and looks like it was written by Haskellers. I want a library that I can integrate with existing code in a JavaScript style.

My Goals

  • Provide a JavaScript library using familiar idioms constrained by the style of FRP.
  • Make use of underscore.js and jQuery to avoid reinventing useful functions.
  • Provide a fast, continuation-based iterator system with common patterns already implemented.
  • Provide useful tools for mapping along streams of $.Deferred objects.
  • Provide utilities for binding to Google Maps.

Dependencies

Examples

frp.Stream.$('body', 'click', 'button.twiddle').build(
    'map', [function(e) { return $(e.target).closest('button').hasClass('on'); }],
    'unique', []);

This streams boolean values reflecting the button state ('on'), but only when that value changes.

frp.Stream.$('canvas', 'mousemove').build(
    'map', [function(e) { return {'x': e.pageX, 'y': pageY}; }],
    'lastN', [2],
    'atLeastN', [2],
    'filter', [function(pos) { return slope(pos[1], pos[0]) > 2; }],
    'mapApply', [function(b, a) { return b; }]);

This streams the mouse position whenever the slope from the previously recorded position is greater than 2.