Patchable
Functional state made easy.
What?
Patchable provides a simple JS API to handle immutable values.
It is a simple wrapper on top of the amazing library Immer
(If you need it's full power, please use it directly!)
In addition to Immer wrappers, Patchable also provides a super simple reference cell with getter, setter and mutator functions.
API
immutable
Creates an immutable value.
const val = ; val1 = 6; // fails (silently)val1; // ==> 7
patched
Takes a value and a function that patches the value, and generates a patched value.
const val = ; const val2 = ; val1; // ==> 6
patching
Curried version of patched
.
const val = ; const valPatcher = ; const val2 = v1 = 6); val1; // ==> 6
patcher
Takes a patch function and returns a function which you can call with a value to be updated.
const incrementorOfFirstValue = ; const val = ; const val2 = ; val1; // ==> 8
patchRef
Creates a "reference cell" and returns 3 functions to read, write and update the cell value.
const initialValue = name: "John" age: 21 balance: 250 ;const getter setter mutator = ; ; // ==> { name: "John", age: 21, balance: 250 }; "balance"; // ==> 250 ; ; // ==> { name: "Jane", age: 25 } ; ; // ==> { name: "Jane", age: 26 }