Coder Social home page Coder Social logo

observ's Introduction

observ

build status NPM version Davis Dependency status

browser support

NPM

A observable value representation

Example

var Observable = require("observ")

var v = Observable("initial value")
v(function onchange(newValue) {
  assert.equal(newValue, "new value")
})
v.set("new value")

var curr = v()
assert.equal(curr, "new value")

What about dominictarr/observable ?

Both observ & observable have the same interface of

  • thing() gets the value
  • thing.set(...) sets the value
  • thing(function (value) { ... }) listens to the value.

The way observ and observable differ is in listening.

  • observ will ONLY call the listener if .set() is invoked.
  • observable calls the listener IMMEDIATELY and calls it whenever .set() is invoked

observ can be used in a similar fashion to observable by using var watch = require("observ/watch"). You can then just watch(thing, function (value) { ... }) and it will call the listener immediately

Both observ & observable have a computed method with the same interface.

  • require("observable").compute
  • require("observ/computed")

Example computed

var Observable = require("observ")
var computed = require("observ/computed")

var one = Observable(1)
var two = Observable(2)

var together = computed([one, two], function (a, b) {
  return a + b
})

assert.equal(together(), 3)
two.set(5)
assert.equal(together(), 7)

Docs

type Observable<A> :
  (() => A) & 
  ((Function<A>) => void) & {
    set: (A) => void
  }
  

observ : (A) => Observable<A>

observ/computed : (
  sources: Array<Observ<T>>,
  lambda: (...args: T) => S
) => Observ<S>

Installation

npm install observ

Contributors

  • Raynos

MIT Licenced

observ's People

Contributors

colingourlay avatar kristianmandrup avatar neonstalwart avatar raynos avatar

Watchers

 avatar  avatar  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.