@legendapp/state 0.14.1 → 0.14.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md ADDED
@@ -0,0 +1,107 @@
1
+ # Legend-State
2
+
3
+ Legend-State is a super fast and powerful state manager for JavaScript apps with two primary goals:
4
+
5
+ ### 1. <span className="text-xl">🦄</span> As easy as possible to use
6
+
7
+ There is no boilerplate and there are no actions, reducers, selectors, dispatchers, sagas, thunks, or epics. Observables are just normal objects that you can listen to for changes.
8
+
9
+ ```jsx
10
+ // Create an observable object
11
+ const state = observable({ settings: { theme: 'dark' } })
12
+
13
+ // Observables work like any other object
14
+ state.settings.theme === 'dark' // true
15
+
16
+ // Listen anywhere for changes
17
+ state.settings.theme.onChange((theme) => { ... })
18
+
19
+ // observer HOC automatically re-renders when state changes
20
+ const Component = observer(() => {
21
+ return <div>Theme: {state.settings.theme}</div>
22
+ })
23
+ ```
24
+
25
+ ### 2. <span className="text-xl">⚡️</span> The fastest React state library
26
+
27
+ Legend-State beats every other state library on just about every metric and is so optimized for arrays that it even beats vanilla JS on the swap benchmark. At only `3kb` and with the massive reduction in boilerplate code, you'll have big savings in file size too.
28
+
29
+ <p>
30
+ <img src="https://www.legendapp.com/img/dev/state/times.png" />
31
+ </p>
32
+
33
+ See [the documentation](https://www.legendapp.com/dev/state) for more details.
34
+
35
+ ## Install
36
+
37
+ `npm install @legendapp/state` or `yarn add @legendapp/state`
38
+
39
+ ## Example
40
+
41
+ ```jsx
42
+ // Create an observable object
43
+ const state = observable({ settings: { theme: 'dark' } })
44
+
45
+ // Observables work like any other object
46
+ state.settings.theme === 'dark' // true
47
+
48
+ // Listen anywhere for changes
49
+ state.settings.theme.onChange((theme) => { ... })
50
+
51
+ // Modify with simple set functions
52
+ state.settings.theme.set('light')
53
+
54
+ // Automatically persist state
55
+ persistObservable(state, { local: 'exampleState' })
56
+
57
+ // Components re-render only when accessed observables change
58
+ const Component = observer(function Component() {
59
+ const toggle = () => {
60
+ state.settings.theme.set(theme => theme === 'dark' ? 'light' : 'dark')
61
+ }
62
+ return (
63
+ <div>
64
+ <div>Theme: {state.settings.theme}</div>
65
+ <Button onClick={toggle}>
66
+ Toggle theme
67
+ </Button>
68
+ </div>
69
+ )
70
+ })
71
+ ```
72
+
73
+ ## Highlights
74
+
75
+ - ✨ Super easy to use - observables are normal objects
76
+ - ✨ No boilerplate
77
+ - ✨ Safe from 🔫 footguns
78
+ - ✨ Designed for maximum performance and scalability
79
+ - ✨ React components re-render only on changes
80
+ - ✨ Very strongly typed with TypeScript
81
+ - ✨ Persistence plugins for automatically saving/loading from storage
82
+ - ✨ State can be global or within components
83
+
84
+ [Read more](https://www.legendapp.com/dev/state/why/) about why Legend-State might be right for you.
85
+
86
+ ## Documentation
87
+
88
+ See [the documentation site](https://www.legendapp.com/dev/state/).
89
+
90
+ ## Todo
91
+
92
+ - [ ] Remote persistence to Firebase
93
+ - [ ] Conflict resolution for remote persistence
94
+
95
+ ## 👩‍⚖️ License
96
+
97
+ [MIT](LICENSE)
98
+
99
+ ---
100
+
101
+ Legend-State is created and maintained by [Jay Meistrich](https://github.com/jmeistrich) with [Legend](https://www.legendapp.com) and [Bravely](https://www.bravely.io).
102
+
103
+ <p>
104
+ <a href="https://www.legendapp.com"><img src="https://www.legendapp.com/img/LogoTextOnWhite.png" height="56" alt="Legend" /></a>
105
+ <span>&nbsp;&nbsp;&nbsp;&nbsp;</span>
106
+ <a href="https://www.bravely.io"><img src="https://www.legendapp.com/img/bravely-logo.png" height="56" alt="Bravely" /></a>
107
+ </p>