Observable Attributes
JavaScript
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
.gitignore
.npmignore
.travis.yml
README.md
index.js
package.json
test.js

README.md

attr Build Status

Define values that you can subscribe for changes. Based on pubsub

message = attr('Hello World')

message()
// => Hello World

message.subscribe(function (update, old) {
  console.log(update, old)
  // => 你好, Hello World
})

message('你好')
message()
// => 你好

Install

$ npm install attr

API

attr()

Creates and returns a new attr.

message = attr('Hello World')
message()
// => Hello World

To get the value of an attr, call it with no parameters:

message()
// => Hello World

To change the value of an attr, call the attr with new value:

message('Foo Bar')

message()
// => Foo Bar

#subscribe(function)

Subscribes the given function to changes.

message.subscribe(function () {

  message()
  // => Lorem Ipsum

})

message('Lorem Ipsum')

#subscribe.once(function)

#unsubscribe(function)

#unsubscribe.once(function)