Add example to listener documentation
This commit is contained in:
parent
b28dd09709
commit
fbb9bea3c0
1 changed files with 23 additions and 0 deletions
23
listener.md
23
listener.md
|
@ -14,3 +14,26 @@ listener.listen([prop, ...], callback)
|
|||
listener.listen(prop)
|
||||
// Removes all callbacks from a given property
|
||||
```
|
||||
|
||||
## Example
|
||||
|
||||
```js
|
||||
import Listener from 'listener.js'
|
||||
const listener = Listener({})
|
||||
|
||||
// Listen for any changed property
|
||||
listener.listen("*", (value, prop) => console.log(`${prop} changed to ${value}`))
|
||||
|
||||
// Listen only for changes to the foo property
|
||||
listener.listen("foo", prop => console.log("it was foo, by the way"))
|
||||
|
||||
// Several listeners for one property are possible
|
||||
// They will be executed in order of definition
|
||||
listener.listen("foo", prop => do_something())
|
||||
|
||||
listener.foo = "New Value"
|
||||
// Triggers 3 handlers
|
||||
|
||||
listener.bar = "New Value"
|
||||
// Triggers only the * handler
|
||||
```
|
||||
|
|
Loading…
Reference in a new issue