Skip to content

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.

  1. Create your state 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
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:

  1. Create your state instance.
  2. Create a watcher for your event (you can call it whatever you want)
  3. Trigger the event
const myState = new puffin.state({})

myState.on('sayHello',() => {
  console.log('hello!')
})

myState.emit('sayHello')

Documentation

Tutorials

Contributing

About

Clone this wiki locally