@legendapp/state 3.0.0-alpha.2 → 3.0.0-alpha.21
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/CHANGELOG.md +831 -1
- package/LICENSE +21 -1
- package/README.md +141 -1
- package/babel.js +0 -2
- package/babel.mjs +0 -2
- package/helpers/trackHistory.js +2 -2
- package/helpers/trackHistory.mjs +2 -2
- package/index.d.mts +45 -32
- package/index.d.ts +45 -32
- package/index.js +234 -156
- package/index.mjs +234 -156
- package/package.json +6 -1
- package/persist-plugins/async-storage.d.mts +2 -2
- package/persist-plugins/async-storage.d.ts +2 -2
- package/persist-plugins/indexeddb.js +1 -1
- package/persist-plugins/indexeddb.mjs +1 -1
- package/react.d.mts +17 -14
- package/react.d.ts +17 -14
- package/react.js +55 -30
- package/react.mjs +56 -31
- package/sync-plugins/_transformObjectFields.d.mts +31 -0
- package/sync-plugins/_transformObjectFields.d.ts +31 -0
- package/sync-plugins/_transformObjectFields.js +114 -0
- package/sync-plugins/_transformObjectFields.mjs +110 -0
- package/sync-plugins/crud.d.mts +14 -23
- package/sync-plugins/crud.d.ts +14 -23
- package/sync-plugins/crud.js +205 -134
- package/sync-plugins/crud.mjs +206 -135
- package/sync-plugins/firebase.d.mts +26 -0
- package/sync-plugins/firebase.d.ts +26 -0
- package/sync-plugins/firebase.js +365 -0
- package/sync-plugins/firebase.mjs +360 -0
- package/sync-plugins/keel.d.mts +24 -8
- package/sync-plugins/keel.d.ts +24 -8
- package/sync-plugins/keel.js +32 -16
- package/sync-plugins/keel.mjs +32 -16
- package/sync-plugins/supabase.d.mts +1 -1
- package/sync-plugins/supabase.d.ts +1 -1
- package/sync-plugins/supabase.js +5 -4
- package/sync-plugins/supabase.mjs +6 -5
- package/sync-plugins/tanstack-query.d.mts +2 -2
- package/sync-plugins/tanstack-query.d.ts +2 -2
- package/sync-plugins/tanstack-query.js +3 -2
- package/sync-plugins/tanstack-query.mjs +3 -2
- package/sync-plugins/tanstack-react-query.d.mts +1 -1
- package/sync-plugins/tanstack-react-query.d.ts +1 -1
- package/sync.d.mts +38 -185
- package/sync.d.ts +38 -185
- package/sync.js +354 -296
- package/sync.mjs +356 -297
- package/types/babel.d.ts +12 -1
- package/.DS_Store +0 -0
- /package/config/{enable_GetSet.d.mts → enable$GetSet.d.mts} +0 -0
- /package/config/{enable_GetSet.d.ts → enable$GetSet.d.ts} +0 -0
package/LICENSE
CHANGED
|
@@ -1 +1,21 @@
|
|
|
1
|
-
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2022 Moo.do LLC
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1 +1,141 @@
|
|
|
1
|
-
|
|
1
|
+
# Legend-State
|
|
2
|
+
|
|
3
|
+
Legend-State is a super fast all-in-one state and sync library that lets you write less code to make faster apps. Legend-State has four primary goals:
|
|
4
|
+
|
|
5
|
+
### 1. 🦄 As easy as possible to use
|
|
6
|
+
|
|
7
|
+
There is no boilerplate and there are no contexts, actions, reducers, dispatchers, sagas, thunks, or epics. It doesn't modify your data at all, and you can just call `get()` to get the raw data and `set()` to change it.
|
|
8
|
+
|
|
9
|
+
In React components you can call `use()` on any observable to get the raw data and automatically re-render whenever it changes.
|
|
10
|
+
|
|
11
|
+
```jsx
|
|
12
|
+
import { observable, observe } from "@legendapp/state"
|
|
13
|
+
import { observer } from "@legendapp/state/react"
|
|
14
|
+
|
|
15
|
+
const settings$ = observable({ theme: 'dark' })
|
|
16
|
+
|
|
17
|
+
// get returns the raw data
|
|
18
|
+
settings$.theme.get() // 'dark'
|
|
19
|
+
// set sets
|
|
20
|
+
settings$.theme.set('light')
|
|
21
|
+
|
|
22
|
+
// Computed observables with just a function
|
|
23
|
+
const isDark$ = observable(() => settings$.theme.get() === 'dark')
|
|
24
|
+
|
|
25
|
+
// observing contexts re-run when tracked observables change
|
|
26
|
+
observe(() => {
|
|
27
|
+
console.log(settings$.theme.get())
|
|
28
|
+
})
|
|
29
|
+
|
|
30
|
+
const Component = observer(function Component() {
|
|
31
|
+
const theme = state$.settings.theme.get()
|
|
32
|
+
|
|
33
|
+
return <div>Theme: {theme}</div>
|
|
34
|
+
})
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
### 2. ⚡️ The fastest React state library
|
|
38
|
+
|
|
39
|
+
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" and "replace all rows" benchmarks. At only `4kb` and with the massive reduction in boilerplate code, you'll have big savings in file size too.
|
|
40
|
+
|
|
41
|
+
<p>
|
|
42
|
+
<img src="https://www.legendapp.com/img/dev/state/times.png" />
|
|
43
|
+
</p>
|
|
44
|
+
|
|
45
|
+
See [Fast 🔥](https://www.legendapp.com/open-source/state/v3/intro/fast/) for more details of why Legend-State is so fast.
|
|
46
|
+
|
|
47
|
+
### 3. 🔥 Fine-grained reactivity for minimal renders
|
|
48
|
+
|
|
49
|
+
Legend-State lets you make your renders super fine-grained, so your apps will be much faster because React has to do less work. The best way to be fast is to render less, less often.
|
|
50
|
+
|
|
51
|
+
```jsx
|
|
52
|
+
function FineGrained() {
|
|
53
|
+
const count$ = useObservable(0)
|
|
54
|
+
|
|
55
|
+
useInterval(() => {
|
|
56
|
+
count$.set(v => v + 1)
|
|
57
|
+
}, 600)
|
|
58
|
+
|
|
59
|
+
// The text updates itself so the component doesn't re-render
|
|
60
|
+
return (
|
|
61
|
+
<div>
|
|
62
|
+
Count: <Memo>{count$}</Memo>
|
|
63
|
+
</div>
|
|
64
|
+
)
|
|
65
|
+
}
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
### 4. 💾 Powerful sync and persistence
|
|
69
|
+
|
|
70
|
+
Legend-State includes a powerful [sync and persistence system](../../usage/persist-sync). It easily enables local-first apps by optimistically applying all changes locally first, retrying changes even after restart until they eventually sync, and syncing minimal diffs. We use Legend-State as the sync systems in [Legend](https://legendapp.com) and [Bravely](https://bravely.io), so it is by necessity very full featured while being simple to set up.
|
|
71
|
+
|
|
72
|
+
Local persistence plugins for the browser and React Native are included, with sync plugins for [Keel](https://www.keel.so), [Supabase](https://www.supabase.com), [TanStack Query](https://tanstack.com/query), and `fetch`.
|
|
73
|
+
|
|
74
|
+
```js
|
|
75
|
+
const state$ = observable(
|
|
76
|
+
users: syncedKeel({
|
|
77
|
+
list: queries.getUsers,
|
|
78
|
+
create: mutations.createUsers,
|
|
79
|
+
update: mutations.updateUsers,
|
|
80
|
+
delete: mutations.deleteUsers,
|
|
81
|
+
persist: { name: 'users', retrySync: true },
|
|
82
|
+
debounceSet: 500,
|
|
83
|
+
retry: {
|
|
84
|
+
infinite: true,
|
|
85
|
+
},
|
|
86
|
+
changesSince: 'last-sync',
|
|
87
|
+
}),
|
|
88
|
+
// direct link to my user within the users observable
|
|
89
|
+
me: () => state$.users['myuid']
|
|
90
|
+
)
|
|
91
|
+
|
|
92
|
+
observe(() => {
|
|
93
|
+
// get() activates through to state$.users and starts syncing.
|
|
94
|
+
// it updates itself and re-runs observers when name changes
|
|
95
|
+
const name = me$.name.get()
|
|
96
|
+
})
|
|
97
|
+
|
|
98
|
+
// Setting a value goes through to state$.users and saves update to server
|
|
99
|
+
me$.name.set('Annyong')
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
## Install
|
|
103
|
+
|
|
104
|
+
`bun add @legendapp/state` or `npm install @legendapp/state` or `yarn add @legendapp/state`
|
|
105
|
+
|
|
106
|
+
## Highlights
|
|
107
|
+
|
|
108
|
+
- ✨ Super easy to use 😌
|
|
109
|
+
- ✨ Super fast ⚡️
|
|
110
|
+
- ✨ Super small at 4kb 🐥
|
|
111
|
+
- ✨ Fine-grained reactivity 🔥
|
|
112
|
+
- ✨ No boilerplate
|
|
113
|
+
- ✨ Designed for maximum performance and scalability
|
|
114
|
+
- ✨ React components re-render only on changes
|
|
115
|
+
- ✨ Very strongly typed with TypeScript
|
|
116
|
+
- ✨ Persistence plugins for automatically saving/loading from storage
|
|
117
|
+
- ✨ State can be global or within components
|
|
118
|
+
|
|
119
|
+
[Read more](https://www.legendapp.com/open-source/state/v3/intro/why/) about why Legend-State might be right for you.
|
|
120
|
+
|
|
121
|
+
## Documentation
|
|
122
|
+
|
|
123
|
+
See [the documentation site](https://www.legendapp.com/open-source/state/).
|
|
124
|
+
|
|
125
|
+
## Community
|
|
126
|
+
|
|
127
|
+
Join us on [Discord](https://discord.gg/5CBaNtADNX) to get involved with the Legend community.
|
|
128
|
+
|
|
129
|
+
## 👩⚖️ License
|
|
130
|
+
|
|
131
|
+
[MIT](LICENSE)
|
|
132
|
+
|
|
133
|
+
---
|
|
134
|
+
|
|
135
|
+
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).
|
|
136
|
+
|
|
137
|
+
<p>
|
|
138
|
+
<a href="https://www.legendapp.com"><img src="https://www.legendapp.com/img/LogoTextOnWhite.png" height="56" alt="Legend" /></a>
|
|
139
|
+
<span> </span>
|
|
140
|
+
<a href="https://www.bravely.io"><img src="https://www.legendapp.com/img/bravely-logo.png" height="56" alt="Bravely" /></a>
|
|
141
|
+
</p>
|
package/babel.js
CHANGED
|
@@ -15,7 +15,6 @@ function babel_default() {
|
|
|
15
15
|
const s = specifiers[i].imported.name;
|
|
16
16
|
if (!hasLegendImport && (s === "Computed" || s === "Memo" || s === "Show")) {
|
|
17
17
|
hasLegendImport = true;
|
|
18
|
-
path.skip();
|
|
19
18
|
break;
|
|
20
19
|
}
|
|
21
20
|
}
|
|
@@ -25,7 +24,6 @@ function babel_default() {
|
|
|
25
24
|
JSXElement: {
|
|
26
25
|
enter(path) {
|
|
27
26
|
if (!hasLegendImport) {
|
|
28
|
-
path.skip();
|
|
29
27
|
return;
|
|
30
28
|
}
|
|
31
29
|
const openingElement = path.node.openingElement;
|
package/babel.mjs
CHANGED
|
@@ -13,7 +13,6 @@ function babel_default() {
|
|
|
13
13
|
const s = specifiers[i].imported.name;
|
|
14
14
|
if (!hasLegendImport && (s === "Computed" || s === "Memo" || s === "Show")) {
|
|
15
15
|
hasLegendImport = true;
|
|
16
|
-
path.skip();
|
|
17
16
|
break;
|
|
18
17
|
}
|
|
19
18
|
}
|
|
@@ -23,7 +22,6 @@ function babel_default() {
|
|
|
23
22
|
JSXElement: {
|
|
24
23
|
enter(path) {
|
|
25
24
|
if (!hasLegendImport) {
|
|
26
|
-
path.skip();
|
|
27
25
|
return;
|
|
28
26
|
}
|
|
29
27
|
const openingElement = path.node.openingElement;
|
package/helpers/trackHistory.js
CHANGED
|
@@ -5,8 +5,8 @@ var state = require('@legendapp/state');
|
|
|
5
5
|
// src/helpers/trackHistory.ts
|
|
6
6
|
function trackHistory(value$, targetObservable) {
|
|
7
7
|
const history = targetObservable != null ? targetObservable : state.observable();
|
|
8
|
-
value$.onChange(({
|
|
9
|
-
if (!
|
|
8
|
+
value$.onChange(({ isFromPersist, isFromSync, changes }) => {
|
|
9
|
+
if (!isFromPersist && !isFromSync) {
|
|
10
10
|
const time = Date.now().toString();
|
|
11
11
|
for (let i = 0; i < changes.length; i++) {
|
|
12
12
|
const { path, prevAtPath, pathTypes } = changes[i];
|
package/helpers/trackHistory.mjs
CHANGED
|
@@ -3,8 +3,8 @@ import { observable, constructObjectWithPath, mergeIntoObservable } from '@legen
|
|
|
3
3
|
// src/helpers/trackHistory.ts
|
|
4
4
|
function trackHistory(value$, targetObservable) {
|
|
5
5
|
const history = targetObservable != null ? targetObservable : observable();
|
|
6
|
-
value$.onChange(({
|
|
7
|
-
if (!
|
|
6
|
+
value$.onChange(({ isFromPersist, isFromSync, changes }) => {
|
|
7
|
+
if (!isFromPersist && !isFromSync) {
|
|
8
8
|
const time = Date.now().toString();
|
|
9
9
|
for (let i = 0; i < changes.length; i++) {
|
|
10
10
|
const { path, prevAtPath, pathTypes } = changes[i];
|
package/index.d.mts
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
type Primitive$1 = string | number | boolean | symbol | bigint | undefined | null | Date;
|
|
2
|
-
type ArrayOverrideFnNames = 'find' | 'every' | 'some' | 'filter' | 'reduce' | 'reduceRight' | 'forEach' | 'map' | 'sort';
|
|
2
|
+
type ArrayOverrideFnNames = 'find' | 'findIndex' | 'every' | 'some' | 'filter' | 'reduce' | 'reduceRight' | 'forEach' | 'map' | 'sort';
|
|
3
3
|
type RemoveIndex<T> = {
|
|
4
4
|
[K in keyof T as string extends K ? never : number extends K ? never : K]: T[K];
|
|
5
5
|
};
|
|
6
6
|
type BuiltIns = String | Boolean | Number | Date | Error | RegExp | Array<any> | Function | Promise<any>;
|
|
7
7
|
type IsUserDefinedObject<T> = T extends Function | BuiltIns | any[] ? false : T extends object ? true : false;
|
|
8
|
-
type RemoveObservables<T> = T extends ImmutableObservableBase<infer t> ? t : IsUserDefinedObject<T> extends true ? {
|
|
8
|
+
type RemoveObservables<T> = T extends ImmutableObservableBase<infer t> ? t : T extends ImmutableObservableBase<infer t>[] ? t[] : IsUserDefinedObject<T> extends true ? {
|
|
9
9
|
[K in keyof T]: RemoveObservables<T[K]>;
|
|
10
|
-
} : T extends ImmutableObservableBase<infer TObs> ? TObs : T extends () => infer TRet ? RemoveObservables<TRet> & T : T extends (key: string) => infer TRet ? Record<
|
|
10
|
+
} : T extends ImmutableObservableBase<infer TObs> ? TObs : T extends () => infer TRet ? RemoveObservables<TRet> & T : T extends (key: infer TKey extends string | number) => infer TRet ? Record<TKey, RemoveObservables<TRet>> & T : T;
|
|
11
11
|
interface ObservableArray<T, U> extends ObservablePrimitive<T>, Pick<Array<Observable<U>>, ArrayOverrideFnNames>, Omit<RemoveIndex<Array<U>>, ArrayOverrideFnNames> {
|
|
12
12
|
}
|
|
13
13
|
interface ObservableObjectFns<T> {
|
|
@@ -76,18 +76,19 @@ type ObservableChildren<T, Nullable = IsNullable<T>> = {
|
|
|
76
76
|
[K in keyof T]-?: Observable<UndefinedIf<T[K], Nullable>>;
|
|
77
77
|
};
|
|
78
78
|
type ObservableFunctionChildren<T> = {
|
|
79
|
-
[K in keyof T]-?: T[K] extends Observable ? T[K] : T[K] extends (key: infer Key extends string) => Promise<infer t> | infer t ?
|
|
79
|
+
[K in keyof T]-?: T[K] extends Observable ? T[K] : T[K] extends (key: infer Key extends string | number) => Promise<infer t> | infer t ? IsLookupFunction<T[K]> extends true ? Observable<Record<Key, t>> & T[K] : t extends void ? T[K] : t extends Observable ? t : Observable<t> & (() => t) : T[K] & Observable<T[K]>;
|
|
80
80
|
};
|
|
81
81
|
type IsStrictAny<T> = 0 extends 1 & T ? true : false;
|
|
82
82
|
type ObservableObject<T> = ObservableObjectFunctions<ObservableProps<T> & NonObservableProps<T>> & ObservableChildren<ObservableProps<T>> & ObservableFunctionChildren<NonObservableProps<T>>;
|
|
83
83
|
type ObservableFunction<T> = T extends () => infer t ? t | (() => t) : T;
|
|
84
|
-
type
|
|
84
|
+
type IsLookupFunction<T> = T extends (...args: infer P) => any ? P extends {
|
|
85
85
|
length: 1;
|
|
86
|
-
} ? P[0] extends string | ObservablePrimitive<string> ? true : false : false : false;
|
|
87
|
-
type ObservableNode<T, NT = NonNullable<T>> = [NT] extends [never] ? ObservablePrimitive<T> : IsStrictAny<T> extends true ? ObservableAny : [T] extends [Promise<infer t>] ? ObservableNode<t> : [T] extends [(key: infer K extends string) => infer t] ? [t] extends [ImmutableObservableBase<any>] ?
|
|
86
|
+
} ? P[0] extends string | ObservablePrimitive<string> | number | ObservablePrimitive<number> ? true : false : false : false;
|
|
87
|
+
type ObservableNode<T, NT = NonNullable<T>> = [NT] extends [never] ? ObservablePrimitive<T> : IsStrictAny<T> extends true ? ObservableAny : [T] extends [Promise<infer t>] ? ObservableNode<t> : [T] extends [(key: infer K extends string) => infer t] ? [t] extends [ImmutableObservableBase<any>] ? IsLookupFunction<T> extends true ? Observable<Record<K, t>> : t : IsLookupFunction<T> extends true ? Observable<Record<K, t>> & T : Observable<ObservableFunction<t>> : [NT] extends [ImmutableObservableBase<any>] ? NT : [NT] extends [Primitive$1] ? [NT] extends [boolean] ? ObservableBoolean : ObservablePrimitive<T> : NT extends Map<any, any> | WeakMap<any, any> ? ObservableMap<NT> : NT extends Set<infer U> ? ObservableSet<Set<UndefinedIf<U, IsNullable<T>>>> : NT extends WeakSet<any> ? ObservableSet<NT> : NT extends Array<infer U> ? ObservableArray<T, U> & ObservableChildren<T> : ObservableObject<T> & {};
|
|
88
88
|
type Observable<T = any> = ObservableNode<T> & {};
|
|
89
89
|
type ObservableParam<T = any> = ImmutableObservableSimple<T> & MutableObservableSimple;
|
|
90
|
-
type
|
|
90
|
+
type FixExpanded<T> = [T] extends [boolean] ? boolean : T;
|
|
91
|
+
type ValueOrFunction<T> = [T] extends [Function] ? T : T | ImmutableObservableBase<FixExpanded<T> | T> | Promise<FixExpanded<T> | T> | (() => FixExpanded<T> | T | Promise<FixExpanded<T> | T> | ImmutableObservableBase<FixExpanded<T> | T>);
|
|
91
92
|
type ValueOrFunctionKeys<T> = {
|
|
92
93
|
[K in keyof T]: RecursiveValueOrFunction<T[K]>;
|
|
93
94
|
};
|
|
@@ -95,7 +96,7 @@ type RecursiveValueOrFunction<T> = T extends Function ? T : T extends object ? (
|
|
|
95
96
|
|
|
96
97
|
declare const symbolOpaque: unique symbol;
|
|
97
98
|
declare function getPathType(value: any): TypeAtPath;
|
|
98
|
-
declare function safeStringify(value: any):
|
|
99
|
+
declare function safeStringify(value: any): any;
|
|
99
100
|
declare function safeParse(value: any): any;
|
|
100
101
|
declare function clone<T>(value: T): any;
|
|
101
102
|
declare function isObservable(value$: any): value$ is Observable;
|
|
@@ -119,7 +120,8 @@ interface ListenerParams<T = any> {
|
|
|
119
120
|
value: T;
|
|
120
121
|
getPrevious: () => T;
|
|
121
122
|
changes: Change[];
|
|
122
|
-
|
|
123
|
+
isFromSync: boolean;
|
|
124
|
+
isFromPersist: boolean;
|
|
123
125
|
}
|
|
124
126
|
type ListenerFn<T = any> = (params: ListenerParams<T>) => void;
|
|
125
127
|
interface ObservableEvent {
|
|
@@ -178,12 +180,15 @@ interface BaseNodeValue {
|
|
|
178
180
|
numListenersRecursive: number;
|
|
179
181
|
state?: Observable<ObservableSyncState>;
|
|
180
182
|
activated?: boolean;
|
|
183
|
+
recursivelyAutoActivated?: boolean;
|
|
181
184
|
activationState?: LinkedOptions & {
|
|
182
185
|
onError?: () => void;
|
|
183
|
-
|
|
186
|
+
onChange: (params: UpdateFnParams) => void | Promise<void>;
|
|
184
187
|
};
|
|
185
188
|
dirtyFn?: () => void;
|
|
186
189
|
dirtyChildren?: Set<NodeValue>;
|
|
190
|
+
numGets?: number;
|
|
191
|
+
getNumResolved?: number;
|
|
187
192
|
}
|
|
188
193
|
interface RootNodeValue extends BaseNodeValue {
|
|
189
194
|
parent?: undefined;
|
|
@@ -229,12 +234,12 @@ interface WaitForSetFnParams<T = any> {
|
|
|
229
234
|
changes: Change[];
|
|
230
235
|
}
|
|
231
236
|
type GetMode = 'set' | 'assign' | 'merge' | 'append' | 'prepend';
|
|
232
|
-
interface UpdateFnParams {
|
|
233
|
-
value:
|
|
237
|
+
interface UpdateFnParams<T = any> {
|
|
238
|
+
value: T;
|
|
234
239
|
mode?: GetMode;
|
|
235
240
|
lastSync?: number | undefined;
|
|
236
241
|
}
|
|
237
|
-
type UpdateFn = (params: UpdateFnParams) => void;
|
|
242
|
+
type UpdateFn<T = any> = (params: UpdateFnParams<T>) => void;
|
|
238
243
|
type Linked<T> = T;
|
|
239
244
|
interface ObserveOptions {
|
|
240
245
|
immediate?: boolean;
|
|
@@ -245,12 +250,17 @@ interface ObservableSyncStateBase {
|
|
|
245
250
|
isSyncEnabled: boolean;
|
|
246
251
|
lastSync?: number;
|
|
247
252
|
syncCount?: number;
|
|
253
|
+
isGetting?: boolean;
|
|
254
|
+
numPendingGets?: number;
|
|
255
|
+
numPendingSets?: number;
|
|
256
|
+
isSetting?: boolean;
|
|
248
257
|
clearPersist: () => Promise<void>;
|
|
249
258
|
sync: () => Promise<void>;
|
|
250
259
|
getPendingChanges: () => Record<string, {
|
|
251
260
|
p: any;
|
|
252
261
|
v?: any;
|
|
253
262
|
}> | undefined;
|
|
263
|
+
numPendingRemoteLoads?: number;
|
|
254
264
|
}
|
|
255
265
|
interface ObservableState {
|
|
256
266
|
isLoaded: boolean;
|
|
@@ -265,6 +275,13 @@ interface RetryOptions {
|
|
|
265
275
|
maxDelay?: number;
|
|
266
276
|
}
|
|
267
277
|
|
|
278
|
+
declare function getProxy(node: NodeValue, p?: string, asFunction?: Function): Observable;
|
|
279
|
+
declare function set(node: NodeValue, newValue?: any): void;
|
|
280
|
+
declare function get(node: NodeValue, options?: TrackingType | GetOptions): any;
|
|
281
|
+
declare function peek(node: NodeValue): any;
|
|
282
|
+
declare function isObserved(node: NodeValue): boolean;
|
|
283
|
+
declare function shouldIgnoreUnobserved(node: NodeValue, refreshFn: () => void): true | undefined;
|
|
284
|
+
|
|
268
285
|
declare function createPreviousHandler(value: any, changes: Change[]): () => any;
|
|
269
286
|
declare function batch(fn: () => void): void;
|
|
270
287
|
declare function beginBatch(): void;
|
|
@@ -273,8 +290,6 @@ declare function endBatch(force?: boolean): void;
|
|
|
273
290
|
declare function computed<T>(get: () => RecursiveValueOrFunction<T>): Observable<T>;
|
|
274
291
|
declare function computed<T, T2 = T>(get: (() => RecursiveValueOrFunction<T>) | RecursiveValueOrFunction<T>, set: (value: T2) => void): Observable<T>;
|
|
275
292
|
|
|
276
|
-
declare function linked<T>(params: LinkedOptions<T> | (() => T), options?: LinkedOptions<T>): Linked<T>;
|
|
277
|
-
|
|
278
293
|
declare function configureLegendState({ observableFunctions, observableProperties, jsonReplacer, jsonReviver, }: {
|
|
279
294
|
observableFunctions?: Record<string, (node: NodeValue, ...args: any[]) => any>;
|
|
280
295
|
observableProperties?: Record<string, {
|
|
@@ -293,7 +308,7 @@ declare function opaqueObject<T extends object>(value: T): OpaqueObject<T>;
|
|
|
293
308
|
declare function getValueAtPath(obj: Record<string, any>, path: string[]): any;
|
|
294
309
|
declare function setAtPath<T extends object>(obj: T, path: string[], pathTypes: TypeAtPath[], value: any, mode?: 'set' | 'merge', fullObj?: T, restore?: (path: string[], value: any) => void): T;
|
|
295
310
|
declare function setInObservableAtPath(value$: ObservableParam, path: string[], pathTypes: TypeAtPath[], value: any, mode: 'assign' | 'set' | 'merge'): void;
|
|
296
|
-
declare function mergeIntoObservable<T extends ObservableParam<
|
|
311
|
+
declare function mergeIntoObservable<T extends ObservableParam<any>>(target: T, ...sources: any[]): T;
|
|
297
312
|
declare function constructObjectWithPath(path: string[], pathTypes: TypeAtPath[], value: any): object;
|
|
298
313
|
declare function deconstructObjectWithPath(path: string[], pathTypes: TypeAtPath[], value: any): object;
|
|
299
314
|
declare function isObservableValueReady(value: any): boolean;
|
|
@@ -301,6 +316,7 @@ declare function setSilently(value$: ObservableParam, newValue: any): any;
|
|
|
301
316
|
declare function initializePathType(pathType: TypeAtPath): any;
|
|
302
317
|
declare function applyChange<T extends object>(value: T, change: Change, applyPrevious?: boolean): T;
|
|
303
318
|
declare function applyChanges<T extends object>(value: T, changes: Change[], applyPrevious?: boolean): T;
|
|
319
|
+
declare function deepMerge<T extends object>(target: T, ...sources: any[]): T;
|
|
304
320
|
|
|
305
321
|
declare const hasOwnProperty: (v: PropertyKey) => boolean;
|
|
306
322
|
declare function isArray(obj: unknown): obj is Array<any>;
|
|
@@ -317,12 +333,13 @@ declare function isNumber(obj: unknown): obj is number;
|
|
|
317
333
|
declare function isEmpty(obj: object): boolean;
|
|
318
334
|
declare function isNullOrUndefined(value: any): value is undefined | null;
|
|
319
335
|
|
|
336
|
+
declare function linked<T>(params: LinkedOptions<T> | (() => T), options?: LinkedOptions<T>): Linked<T>;
|
|
337
|
+
|
|
320
338
|
declare function observable<T>(): Observable<T | undefined>;
|
|
321
339
|
declare function observable<T>(value: Promise<RecursiveValueOrFunction<T>> | (() => RecursiveValueOrFunction<T>) | RecursiveValueOrFunction<T>): Observable<T>;
|
|
322
340
|
declare function observable<T>(value: T): Observable<T>;
|
|
323
341
|
declare function observablePrimitive<T>(value: Promise<T>): ObservablePrimitive<T>;
|
|
324
342
|
declare function observablePrimitive<T>(value?: T): ObservablePrimitive<T>;
|
|
325
|
-
declare function syncState(obs: ObservableParam): Observable<ObservableSyncState>;
|
|
326
343
|
|
|
327
344
|
declare function observe<T>(run: (e: ObserveEvent<T>) => T | void, options?: ObserveOptions): () => void;
|
|
328
345
|
declare function observe<T>(selector: Selector<T> | ((e: ObserveEvent<T>) => any), reaction?: (e: ObserveEventCallback<T>) => any, options?: ObserveOptions): () => void;
|
|
@@ -332,6 +349,8 @@ declare function proxy<T extends Record<string, any>>(get: <K extends keyof T>(k
|
|
|
332
349
|
declare function proxy<T>(get: (key: string) => ObservableParam<T>): Observable<Record<string, T>>;
|
|
333
350
|
declare function proxy<T>(get: (key: string) => T): Observable<Record<string, T>>;
|
|
334
351
|
|
|
352
|
+
declare function syncState(obs: ObservableParam): Observable<ObservableSyncState>;
|
|
353
|
+
|
|
335
354
|
declare function trackSelector<T>(selector: Selector<T>, update: (params: ListenerParams) => void, observeEvent?: ObserveEvent<T>, observeOptions?: ObserveOptions, createResubscribe?: boolean): {
|
|
336
355
|
nodes: Map<NodeValue, TrackingNode> | undefined;
|
|
337
356
|
value: T;
|
|
@@ -346,23 +365,18 @@ declare function whenReady<T, T2>(predicate: Promise<T>, effect: (value: T) => T
|
|
|
346
365
|
declare function whenReady<T, T2>(predicate: Selector<T>, effect: (value: T) => T2): Promise<T2>;
|
|
347
366
|
declare function whenReady<T>(predicate: Selector<T>): Promise<T>;
|
|
348
367
|
|
|
349
|
-
declare function
|
|
350
|
-
|
|
351
|
-
declare function get(node: NodeValue, options?: TrackingType | GetOptions): any;
|
|
352
|
-
declare function peek(node: NodeValue): any;
|
|
353
|
-
declare function isObserved(node: NodeValue): boolean;
|
|
354
|
-
declare function shouldIgnoreUnobserved(node: NodeValue, refreshFn: () => void): true | undefined;
|
|
355
|
-
|
|
356
|
-
declare function runWithRetry<T>(node: NodeValue, state: {
|
|
357
|
-
attemptNum: number;
|
|
368
|
+
declare function runWithRetry<T>(state: {
|
|
369
|
+
retryNum: number;
|
|
358
370
|
retry: RetryOptions | undefined;
|
|
359
371
|
}, fn: (e: {
|
|
360
|
-
|
|
372
|
+
retryNum: number;
|
|
373
|
+
cancelRetry: () => void;
|
|
361
374
|
}) => T | Promise<T>): T | Promise<T>;
|
|
362
375
|
|
|
363
376
|
declare const internal: {
|
|
364
377
|
createPreviousHandler: typeof createPreviousHandler;
|
|
365
378
|
clone: typeof clone;
|
|
379
|
+
deepMerge: typeof deepMerge;
|
|
366
380
|
ensureNodeValue: typeof ensureNodeValue;
|
|
367
381
|
findIDKey: typeof findIDKey;
|
|
368
382
|
get: typeof get;
|
|
@@ -373,7 +387,6 @@ declare const internal: {
|
|
|
373
387
|
getValueAtPath: typeof getValueAtPath;
|
|
374
388
|
globalState: {
|
|
375
389
|
isLoadingLocal: boolean;
|
|
376
|
-
isMerging: boolean;
|
|
377
390
|
isLoadingRemote: boolean;
|
|
378
391
|
activateSyncedNode: (node: NodeValue, newValue: any) => {
|
|
379
392
|
update: UpdateFn;
|
|
@@ -381,8 +394,8 @@ declare const internal: {
|
|
|
381
394
|
};
|
|
382
395
|
pendingNodes: Map<NodeValue, () => void>;
|
|
383
396
|
dirtyNodes: Set<NodeValue>;
|
|
384
|
-
replacer: ((this: any, key: string, value: any) => any)
|
|
385
|
-
reviver: ((this: any, key: string, value: any) => any)
|
|
397
|
+
replacer: undefined | ((this: any, key: string, value: any) => any);
|
|
398
|
+
reviver: undefined | ((this: any, key: string, value: any) => any);
|
|
386
399
|
};
|
|
387
400
|
initializePathType: typeof initializePathType;
|
|
388
401
|
observableFns: Map<string, (node: NodeValue, ...args: any[]) => any>;
|
|
@@ -401,4 +414,4 @@ declare const internal: {
|
|
|
401
414
|
};
|
|
402
415
|
};
|
|
403
416
|
|
|
404
|
-
export { type ArrayValue, type Change, type ChildNodeValue, type ClassConstructor, type GetMode, type GetOptions, type ImmutableObservableBase, type Linked, type LinkedOptions, type ListenerFn, type ListenerParams, type NodeValue, type NodeValueListener, type NotPrimitive, type Observable, type ObservableBoolean, type ObservableEvent, type ObservableListenerDispose, type ObservableObject, type ObservableParam, type ObservablePrimitive, type ObservableRoot, type ObservableState, type ObservableSyncState, type ObservableSyncStateBase, type ObservableValue, type ObserveEvent, type ObserveEventCallback, type ObserveOptions, type OpaqueObject, type Primitive, type RecordValue, type RecursiveValueOrFunction, type RemoveObservables, type RetryOptions, type RootNodeValue, type Selector, type SetParams, type TrackingNode, type TrackingState, type TrackingType, type TypeAtPath, type UpdateFn, type UpdateFnParams, type WaitForSetFnParams, applyChange, applyChanges, batch, beginBatch, computeSelector, computed, configureLegendState, constructObjectWithPath, deconstructObjectWithPath, endBatch, event, getObservableIndex, hasOwnProperty, internal, isArray, isBoolean, isDate, isEmpty, isFunction, isMap, isNullOrUndefined, isNumber, isObject, isObservable, isObservableValueReady, isObserved, isPrimitive, isPromise, isString, isSymbol, linked, mergeIntoObservable, observable, observablePrimitive, observe, opaqueObject, proxy, setAtPath, setInObservableAtPath, setSilently, shouldIgnoreUnobserved, syncState, trackSelector, when, whenReady };
|
|
417
|
+
export { type ArrayValue, type Change, type ChildNodeValue, type ClassConstructor, type GetMode, type GetOptions, type ImmutableObservableBase, type Linked, type LinkedOptions, type ListenerFn, type ListenerParams, type NodeValue, type NodeValueListener, type NotPrimitive, type Observable, type ObservableBoolean, type ObservableEvent, type ObservableListenerDispose, type ObservableObject, type ObservableObjectFns, type ObservableParam, type ObservablePrimitive, type ObservableRoot, type ObservableState, type ObservableSyncState, type ObservableSyncStateBase, type ObservableValue, type ObserveEvent, type ObserveEventCallback, type ObserveOptions, type OpaqueObject, type Primitive, type RecordValue, type RecursiveValueOrFunction, type RemoveObservables, type RetryOptions, type RootNodeValue, type Selector, type SetParams, type TrackingNode, type TrackingState, type TrackingType, type TypeAtPath, type UpdateFn, type UpdateFnParams, type WaitForSetFnParams, applyChange, applyChanges, batch, beginBatch, computeSelector, computed, configureLegendState, constructObjectWithPath, deconstructObjectWithPath, endBatch, event, getObservableIndex, hasOwnProperty, internal, isArray, isBoolean, isDate, isEmpty, isFunction, isMap, isNullOrUndefined, isNumber, isObject, isObservable, isObservableValueReady, isObserved, isPrimitive, isPromise, isString, isSymbol, linked, mergeIntoObservable, observable, observablePrimitive, observe, opaqueObject, proxy, setAtPath, setInObservableAtPath, setSilently, shouldIgnoreUnobserved, syncState, trackSelector, when, whenReady };
|