GithubHelp home page GithubHelp logo

reagi's Introduction

Reagi

Build Status

Reagi is an FRP library for Clojure and ClojureScript, built on top of core.async.

Installation

Add the following dependency to your project.clj file:

[reagi "0.7.0"]

Overview

Reagi introduces two new reference types: behaviors and event streams.

user=> (require '[reagi.core :as r])
nil

A behavior models continuous change, and is evaluated each time you dereference it.

user=> (def t (r/behavior (System/currentTimeMillis)))
#'user/t
user=> @t
1380475144266
user=> @t
1380475175587

An event stream models a series of discrete changes. Events must be expicitly pushed onto the stream. Dereferencing the event stream returns the last value pushed onto the stream.

user=> (def e (r/events))
#'user/e
user=> (r/push! e 1)
#<Events@66d278af: 1>
user=> @e
1

If the event stream is empty, dereferencing it will block the running thread, much like a promise.

Reagi provides a number of functions for transforming event streams, which mimic many of the standard Clojure functions for dealing with seqs:

user=> (def incremented (r/map inc e))
#'user/m
user=> (r/push! e 2)
#<Events@66d278af: 2>
user=> @incremented
3

Finally, behaviors can be converted to event streams by sampling them at a specified interval:

user=> (def et (r/sample 1000 t))
#'user/et
user=> @et
1380475969885

Documentation

Differences in ClojureScript version

The ClojureScript version of Reagi has two main differences from the Clojure version:

  1. Trying to deref an unrealized stream blocks the current thread in Clojure, but raises an error in ClojureScript.

  2. Event streams that fall out of scope in Clojure are automatically cleaned up. In ClojureScript, the reagi.core/dispose function must be manually called on streams before they fall out of scope.

License

Copyright © 2013 James Reeves

Distributed under the Eclipse Public License, the same as Clojure.

reagi's People

Contributors

mopemope avatar weavejester avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.