- reactive, for map, set, weakmap, weakset
- effect(fn)
- trigger fn when state used in fn
- track / trigger for set, add, delete type
- track 紀錄使用, trigger 基於使用觸法
- structure test: nested / array
- ref: for primitive
- computed(fn).value: cache fn result, only update when state update
- schedule: like debounce
- cleanup: cleanup dep everytime before rerun, and update dep after
npm install --save @plotdb/react
then include the main script ( index.min.js ) or import it based on your environment.
use reactive(youObject) to initialize reactive:
react(myObj = { .... })
To automatically trigger your function when the reactive object is updated:
react.by -> myObj.value = Math.random!
@plotdb/react tracks update by storing information inside a react.host instance which will be constructed automatically, but you can still build one manaully and use it along with react:
host = react.host!
react(myObj = {...}, host)
react(obj): initialize react withobj.react.by(cb): callcbwhen any fields underobjused bycbis updated.react.to(obj, cb): explicitly tell react to callcbwhenobjis updated.
link(parent, key, child): track parent and the field key where child is stored with WeakMap for path generation.path(object, key): get path toobject[key]from root object.ref(primitiveValue): return a trackable reference of the given primitive value.by(callback): register a callback which should be triggered by any update of fields it uses.track(target, key, callback): track changes fortarget[key]- optional
callbackwhich explicitly tell react to triggercallbackontarget[key]change.
- optional
trigger(target, key): trigger any callback that usestarget[key]root(obj): markobjas root for path resolutionraw(proxy, counterpart):- link a
proxyto itscounterpart. Returncounterpartifcounterpartis omitted.
- link a
isRoot(o): - return true if a given objectois root.