Simple state management (React optional)
https://githubbox.com/anduong96/Tiamut/tree/main/example
npm i --save tiamut
import { createStoreHook, createStore } from 'tiamut';
const store = createStoreHook(
createStore({
initialState: {
value: 1,
},
actions: {
addOne(state) {
return {
...state,
value: value + 1,
};
},
},
}),
);
const MyApp = () => {
const value = store.useSelect((state) => state.value);
function addOne() {
// Call this from anywhere
// Even outside of component
store.actions.addOne();
}
return (
<div>
<div>{value}</div>
<button onClick={addOne}>Add One</button>
</div>
);
};
import { createStore, createCombinedStoreHook } from "tiamut";
const foo = createStore({
initialState: {
value: 1,
},
});
const bar = createStore({
initialState: {
value: 2,
},
actions: {
addOne(state) {
return {
...state,
value: state.value + 1
}
}
}
});
const store = createCombinedStoresHook({
foo,
bar,
});
const MyApp = () => {
const value = store.useSelect((state) => state.foo.value);
function handleAction() {
store.actions.bar.addOne();
// or
// bar.actions.addOne();
}
return (
<div>
<div>{value}</div>
<button onClick={handleAction}>Add One</button>
</div>;
)
};