0.0.22 • Published 6 years ago
istate v0.0.22
istate
A state management that is inspired on recoil
Simple state
import istate from 'istate';
const Count = istate(0);
const Increase = () => {
const [count, setCount] = Count();
setCount(count + 1);
};
Increase();
console.log(Count.get()); // 1Modify state using reducer
const Increase = () => {
const [, setCount] = Count();
setCount((count) => count + 1);
};Handle state changing
Count.subscribe(() => console.log('count state changed'));State family
const Boxes = istate((id) => ({
id,
x: 0,
y: 0,
}));
const MoveBox = (id, offsetX, offsetY) => {
const [, setBox] = Boxes(id);
setBox((box) => ({
...box,
x: box.x + offsetX,
y: box.y + offsetY,
}));
};
const ResetBox = (id) => {
const [, boxApi] = Boxes(id);
boxApi.reset();
};State dependencies
const Counter = istate(0);
const DoubleCounter = istate(() => {
const [counter] = Counter();
return counter * 2;
});
const Increase = () => {
const [counter, setCounter] = Counter();
setCounter(counter + 1);
};
Increase(); // Counter = 1, DoubleCounter = 2
Increase(); // Counter = 2, DoubleCounter = 40.0.22
6 years ago
0.0.20
6 years ago
0.0.19
6 years ago
0.0.18
6 years ago
0.0.17
6 years ago
0.0.16
6 years ago
0.0.15
6 years ago
0.0.14
6 years ago
0.0.13
6 years ago
0.0.12
6 years ago
0.0.11
6 years ago
0.0.10
6 years ago
0.0.9
6 years ago
0.0.8
6 years ago
0.0.3
6 years ago
0.0.5
6 years ago
0.0.4
6 years ago
0.0.7
6 years ago
0.0.6
6 years ago
0.0.2
6 years ago
0.0.1
6 years ago