Skip to content

Instantly share code, notes, and snippets.

View actions.js
import { Store } from 'laco'
const CounterStore = new Store({ count: 0 }, "CounterStore")
// Implementing some actions to update the store
const increment = () => CounterStore.set(state => ({ count: state.count + 1 }), "Increment");
const decrement = () => CounterStore.set(state => ({ count: state.count - 1 }), "Decrement");
View counterStore.js
import { Store } from 'laco'
const CounterStore = new Store({ count: 0 }, "CounterStore")
View globalstate.js
import { Store, getGlobalState } from 'laco'
const CounterStore = new Store({ count: 0 })
const ToggleStore= new Store({ toggle: false })
getGlobalState()
// Outputs an object:
// {
// "0": { count: 0 },
// "1": { toggle: false },
View Counter.jsx
import { render } from 'react-dom'
import { Store } from 'laco'
import { Subscribe } from 'laco-react'
// Creating a new store with an initial state { count: 0 }
const CounterStore = new Store({ count: 0 })
// Implementing some actions to update the store
const increment = () => CounterStore.set(state => ({ count: state.count + 1 }))
const decrement = () => CounterStore.set(state => ({ count: state.count - 1 }))
View gist:bc59305eeeba0810083575fe9b734543
### Keybase proof
I hereby claim:
* I am deamme on github.
* I am deam (https://keybase.io/deam) on keybase.
* I have a public key ASDru6OJKPBP2_Oio9EIWvW3BZsECn8QDMpkBLGjs3M9_Qo
To claim this, I am signing this object: