JavaScript/TypeScript library for state management.
npm i @lilbunnyrabbit/statefulia
const state = new State({
useChangeEvent: true,
useLogs: true,
});
// ...
const stateElement = state.init("clicks", {
defaultValue: 0,
config: {
useLocalStorage: true,
useEvents: true,
},
});
// Increment "clicks" element in State.
document.getElementById("clicks-button").addEventListener("click", () => {
stateElement.set(stateElement.get() + 1);
});
// ...
class App extends StateComponent {
constructor() {
super(state);
}
$onStateChange(key, value) {
switch (key) {
case "clicks":
document.getElementById("clicks-display").innerText = `${value} clicks.`;
break;
default:
break;
}
}
}
- TypeScript generics
- Documentation
MIT © Andraž Mesarič-Sirec