https://github.com/azer/attr
Observable Attributes
https://github.com/azer/attr
Last synced: 12 months ago
JSON representation
Observable Attributes
- Host: GitHub
- URL: https://github.com/azer/attr
- Owner: azer
- Created: 2013-03-05T21:24:19.000Z (over 13 years ago)
- Default Branch: master
- Last Pushed: 2016-12-29T16:44:46.000Z (over 9 years ago)
- Last Synced: 2025-04-09T08:01:36.488Z (about 1 year ago)
- Language: JavaScript
- Homepage:
- Size: 9.77 KB
- Stars: 7
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
## attr [](https://travis-ci.org/azer/attr)
Define values that you can subscribe for changes. Based on [pubsub](http://github.com/azer/pubsub)
```js
message = attr('Hello World')
message()
// => Hello World
message.subscribe(function (update, old) {
console.log(update, old)
// => 你好, Hello World
})
message('你好')
message()
// => 你好
```
## Install
```bash
$ npm install attr
```
## API
### attr()
Creates and returns a new attr.
```js
message = attr('Hello World')
message()
// => Hello World
```
To get the value of an attr, call it with no parameters:
```js
message()
// => Hello World
```
To change the value of an attr, call the attr with new value:
```js
message('Foo Bar')
message()
// => Foo Bar
```
### #subscribe(`function`)
Subscribes the given function to changes.
```js
message.subscribe(function () {
message()
// => Lorem Ipsum
})
message('Lorem Ipsum')
```
### #subscribe.once(`function`)
### #unsubscribe(`function`)
### #unsubscribe.once(`function`)