Skip to content

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.

  1. Create your object instance
  2. Create a watcher for the key "someData"; every time its value is changed it will execute your function
  3. 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:

  1. Create your object instance.
  2. Create a watcher for your event (you can call it whatever you want)
  3. 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

Clone this wiki locally