Gathering detailed insights and metrics for proxy-state-tree
Gathering detailed insights and metrics for proxy-state-tree
npm install proxy-state-tree
Typescript
Module System
Node Version
NPM Version
91.9
Supply Chain
100
Quality
90
Maintenance
100
Vulnerability
100
License
JavaScript (100%)
Verify real, reachable, and deliverable emails with instant MX records, SMTP checks, and disposable email detection.
Total Downloads
2,662,493
Last Day
1,848
Last Week
10,527
Last Month
46,973
Last Year
380,180
MIT License
68 Stars
37 Commits
3 Watchers
1 Branches
3 Contributors
Updated on Jan 24, 2025
Minified
Minified + Gzipped
Latest Version
6.3.0
Package Id
proxy-state-tree@6.3.0
Unpacked Size
180.95 kB
Size
35.01 kB
File Count
34
NPM Version
6.3.0
Node Version
10.24.1
Cumulative downloads
Total Downloads
Last Day
-8.1%
1,848
Compared to previous day
Last Week
-7.6%
10,527
Compared to previous week
Last Month
13.5%
46,973
Compared to previous month
Last Year
6.4%
380,180
Compared to previous year
3
An implementation of the Mobx/Vue state tracking approach, for library authors
Has moved to repo: https://github.com/cerebral/overmind
npm install proxy-state-tree@beta
The proxy-state-tree project is created to stimulate innovation in state management. The introduction of Flux was followed by a big wave of libraries trying to improve on the idea. All these iterations helped moving the community forward and Redux was born a year later. It was frustrating to have all these variations of the same idea, but at the same time it made the core idea better. One factor I believe made this possible is that Flux state management is based on immutability. It is a difficult concept to understand, but when you understand it, it is easy to implement the concept of change. You literally just check if a value you depend on has changed. That said, immutability tends to put a lof effort on the hands of the consumer. You have to think really hard about how you structure state and expose state to components to avoid performance issues and prevent boilerplate.
vuejs and mobx has a different approach to change. They use getter/setter interception to track access to state and changes to state. This concept completely removes the consumers burden of how the state is structured and how it is exposed to the different parts of the app. You just expose state in any form and the usage is automatically tracked and optimized. The problem with this approach though is that it is difficult to implement as a library author. I want to change that!
proxy-state-tree is a low level implementation of the getter/setter interception with a single state tree to help library authors innovate. I hope to see innovations that removes the burden that immutability currently causes, but keeps the guarantees that was introduced in Flux. I invite you to make a mobx and redux baby! ;-)
Vue example with a simple implementation that allows you to define a state tree and expose a store to the components which can be mutated in the methods
Preact example with a simple implementation of a external state and actions passed on a Provider. Also includes a simple, but inspiring debugger
1import ProxyStateTree from 'proxy-state-tree' 2 3const tree = new ProxyStateTree({}) 4 5console.log(tree.get()) // {}
As a library author you would typically expose a mechanism to define the initial state of the application, which you would pass to the ProxyStateTree. You would also expose a way to access the state, hiding the tree.get()
from the consumer of your library.
You can track access to the state by using the startPathsTracking and clearPathsTracking methods.
1import ProxyStateTree from 'proxy-state-tree' 2 3const tree = new ProxyStateTree({ 4 foo: 'bar', 5 bar: 'baz' 6}) 7const state = tree.get() 8 9const trackId = tree.startPathsTracking() 10const foo = state.foo 11const bar = state.bar 12const paths = tree.clearPathsTracking(trackId) 13 14console.log(paths) // Set { 'foo', 'bar' }
You would typically use this mechanism to track usage of state. For example rendering a component, calculating a a computed value etc. The returned paths array is stored for later usage. The paths structure is used internally by proxy-state-tree, but you can also consume it as a library author to for example showing components and what paths they depend on in a devtool. Nested paths uses dot notation, for example ['foo.bar']
. Path tracking can be nested, but they can not run at the same time. Meaning the nested tracking must finish before the outer tracker.
1import ProxyStateTree from 'proxy-state-tree' 2 3const tree = new ProxyStateTree({ 4 foo: 'bar', 5 bar: [] 6}) 7const state = tree.get() 8 9tree.startMutationTracking() 10state.foo = 'bar2' 11state.bar.push('baz') 12const mutations = tree.clearMutationTracking() 13 14console.log(mutations) 15/* 16 [{ 17 method: 'set', 18 path: ['foo'], 19 args: ['bar2'] 20 }, { 21 method: 'push', 22 path: ['bar'], 23 args: ['baz'] 24 }] 25*/
You would use startMutationTracking and clearMutationTracking around logic that is allowed to do mutations, for example actions or similar. Trying to mutate without this tracking active results in an error. The returned array can be used in combination with a devtool.
1import ProxyStateTree from 'proxy-state-tree' 2 3const tree = new ProxyStateTree({ 4 foo: 'bar', 5 bar: 'baz' 6}) 7const state = tree.get() 8 9function render () { 10 const trackId = tree.startPathsTracking() 11 const foo = state.foo 12 const bar = state.bar 13 14 return tree.clearPathsTracking(trackId) 15} 16 17const listener = tree.addMutationListener(render(), () => { 18 // Runs when mutations matches paths passed in 19 20 // Whenever mutations affecting these paths occurs 21 // we typically create the paths again due to possible 22 // conditional logic, in "render" in this example 23 listener.update(render()) 24}) 25 26tree.startMutationTracking() 27state.foo = 'bar2' 28state.bar.push('baz') 29tree.clearMutationTracking() 30 31// This command flushes out the current mutations and 32// notifies any listeners 33tree.flush() 34 35// Remove listener 36listener.dispose()
Here we combine the tracked paths with the mutations performed to see if this components, computed or whatever indeed needs to run again, doing a new startPathsTracking and clearPathsTracking.
If you insert a function into the state tree it will be called when accessed. The function is passed the proxy-state-tree instance and the path of where the function lives in the tree.
1import ProxyStateTree from 'proxy-state-tree' 2 3const tree = new ProxyStateTree({ 4 foo: (proxyStateTree, path) => {} 5})
The allows you to easily extend functionality with for example a computed concept that lives in the tree, as you can see in this codesandbox.
No vulnerabilities found.
Reason
no binaries found in the repo
Reason
license file detected
Details
Reason
Found 4/20 approved changesets -- score normalized to 2
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
security policy file not detected
Details
Reason
project is not fuzzed
Details
Reason
branch protection not enabled on development/release branches
Details
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
Reason
65 existing vulnerabilities detected
Details
Score
Last Scanned on 2025-03-10
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More