Reactivity
Reactive Primitives are added out of necessity in a sensible and abstracted API. Currently it uses a customized port to Classes of the Solid Core Reactivity.
# Snippet
# Reactive Functions
name | arguments | returns | description |
---|---|---|---|
signal | (initialValue, {equals:false/(a,b)=>a===b}) | [read, write, update] | {read:()=>value, write:(newValue)=>boolean, update:(prev)=>nextValue} | tuple to read and write values from/to a signal. Useupdate for running a function that receives the previous value and return to set a new value. When using update the signal doesnt track. |
signalify | (object, [prop1, props2]?) | object | it replaces already exsisting object properties with setters/getters. It can be used in a class with getters/setters. Aditionally you may pass an array of prop names to choose what to signalify. NOTE: new properties wont be tracked/mutable. This is NOT recursive. |
mutable | object | object | it replaces all object properties with setters/getters. New properties are tracked/mutable. This is done recursively. |
merge | (target, source, keys?) | target | Merge `source` into `target` |
replace | (target, source, keys?) | target | Merge `source` into `target` and removes from `target` keys not present in `source` |
memo | fn | signal | read-only signal that will update when the return value of the function changes, memos are lazy |
writable | fn | signal | like a memo but the function wont run unless is used (lazy), and if you write to the return value it will get that as a value |
root | fn | dispose function | creates a new tracking scope |
effect | fn | void | function to re-run when dependencies change |
syncEffect | fn | void | function to re-run when dependencies change. the difference with an effect is that an effect may run at a later point in time while a syncEffect is garanteed to run right away after your call. |
asyncEffect | (currentRunningEffect: Promise<any>) => any | any | for when you need to run effects one after another you can await the previous running effect with the parameter that the callback receives. |
batch | fn | void | batches changes |
cleanup | fn | void | cleanup callback for when the reactive context is disposed |
owned | fn | owned function | returns a function that holds the owner on the scope. If you call it will run the function you passed initialy with that owner |
withValue | withValue(value, fn) => fn(value) | void | given a value and a function, if the value is a function then it will create an effect that unwraps the value and pass it to the function you defined |
map | map(Iterable, callback) | void | reactive version of array.map for iterables |