post-js (Proxied Observable State Tree)
WIP This aims to be a minimalist re-implementation of mobx-state-tree.
PENDING:
- refactor Store.{regsiter,unregister}, replace with Store.{addEventListener,removeEventListener} and create events for action/patch/restore...
- get test coverage back to 100/100
This package utilizes Proxy, to create a "transparent" pojo-ish observable state tree.
The main thing this package does not plan to have support for that is in mobx-state-tree would be the runtime type system.
Install
$ npm install --save post-js
; const store = ; // transparently adds and removes values to the proxied observable store...storetest = "123"; // default creates an observable valuestoretest2 = ; // escape hatch for unobserved valuesstoreupdateTest2 = ;store { // you can do whatever async code you like in a normal function // when you are ready to update your store's data simply call a sync action ;}; // equivalent to mobx autorun...const fullNameDisposer = ; const fullCountDisposer = ; // you can register to receive json patchesconst fn = console;store;storetest = "test123"; // will console.log() -> [{ op: "add", path: "/test", value: "test123" }]// you can also unregister from the patch stream...store; // actions are "atomic" in in that the changes are batched like actions in mobx...// so autorun is de-glitched and guaranteed to not be stale...store; // you can retrieve the current snapshot of a store// the snapshot will include all observables/unobserveds for store and all of nested stores// non-serializable portions of the store such as functions and computed values// are not included in the snapshot...console; // will log all keys excluding actions and functions...for let v in storesnapshot console; ; // autoruns can be disposed to remove observable references and prevent further execution;store; // disposes of observables and delete's all keys for this store and all nested stores... // you can also use the observable primitives directly without the pojo proxy wrapperconst first = ;const last = ;const counter = ;const fullName = ;const fullCount = ; const plainFullNameDisposer = ;const plainFullCountDisposer = ; // unbatched updates// will trigger autoruns for each statement below...;;; // batched updates via actions// first param in action needs to be provided as it will be replaced// with the undefined context and shouldn't be used...const updateFull = ; // will trigger one run of each of the above active autoruns; // you can manually dispose of autoruns and computed values;;fullName;fullCount;
License
post-js is MIT licensed. See LICENSE.