-
-
Notifications
You must be signed in to change notification settings - Fork 125
PuffinState
Marc Espín Sanz edited this page Apr 24, 2020
·
3 revisions
Graviton uses a lot Puffin's state instances. It's an easy way to manage reactive objects and events.
- Create your object 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
// 1
const myObject = new puffin.state({
someData:true
})
// 2
myObject.keyChanged('someData',(newValue)=>{
console.log(`someData has a new value -> ${newValue}`)
})
// 3
myObject.data.someData = "Graviton"
You can also create your own events:
- Create your object instance.
- Create a watcher for your event (you can call it whatever you want)
- Trigger the event
// 1
const myObject = new puffin.state({
someData:true
})
// 2
myObject.on('sayHello',()=>{
console.log('hello!')
})
// 3
myObject.emit('sayHello')
Documentation
Tutorials
Contributing
About