vanilla-cafe
v0.1.5
Published
Global State Manager for Vanilla JS
Downloads
16
Maintainers
Readme
npm i vanilla-cafe
Create a store
import { createStore } from "vanilla-cafe";
export const { set, sub, get } = createStore({
count: 0
})
Update states
import { set, sub, get } from '../store';
function increment(){
set.count(p => p + 1)
}
Subscribe to changes
let count = 0;
function handleCountChange(newValue){
count = newValue
}
const unsubscribe = sub.count(handleCountChange)
Get the current state's value
const count = get.count()