Skip to content

azer/attr

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

22 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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)

About

Observable Attributes

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published