-
-
Notifications
You must be signed in to change notification settings - Fork 126
PuffinState
Marc Espín Sanz edited this page Jun 23, 2020
·
3 revisions
Graviton uses a lot Puffin's state instances. It's an easy way to manage reactive objects and events.
- Create your state instance
- Create a watcher for the key "someData"; every time its value is changed it will execute your function
- Modify someData's value to trigger the function
const myState = new puffin.state({
someData: true
})
myState.keyChanged('someData', newValue => {
console.log(`someData has a new value -> ${newValue}`)
})
myState.data.someData = 'Graviton'
You can also create your own events:
- Create your state instance.
- Create a watcher for your event (you can call it whatever you want)
- Trigger the event
const myState = new puffin.state({})
myState.on('sayHello',() => {
console.log('hello!')
})
myState.emit('sayHello')
Documentation
Tutorials
Contributing
About