@lilbunnyrabbit/statefulia
v0.0.0-alpha
Published
JavaScript/TypeScript library for state management.
Downloads
1
Maintainers
Readme
Statefulia
JavaScript/TypeScript library for state management.
Installation
npm i @lilbunnyrabbit/statefulia
Example
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;
}
}
}
TODO
- [ ] TypeScript generics
- [ ] Documentation
License
MIT © Andraž Mesarič-Sirec