attr

Define values that you can subscribe for changes

npm install attr
2 downloads in the last day
27 downloads in the last week
165 downloads in the last month

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)

npm loves you