@legendapp/state 3.0.0-alpha.9 → 3.0.0-beta.0
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/.DS_Store +0 -0
- package/config/configureLegendState.d.mts +13 -0
- package/config/configureLegendState.d.ts +13 -0
- package/config/configureLegendState.js +45 -0
- package/config/configureLegendState.mjs +43 -0
- package/config/enable$GetSet.js +2 -1
- package/config/enable$GetSet.mjs +2 -1
- package/config/enableReactTracking.js +2 -1
- package/config/enableReactTracking.mjs +2 -1
- package/config/enableReactUse.js +2 -1
- package/config/enableReactUse.mjs +2 -1
- package/config/enable_PeekAssign.js +2 -1
- package/config/enable_PeekAssign.mjs +2 -1
- package/helpers/trackHistory.js +2 -2
- package/helpers/trackHistory.mjs +2 -2
- package/index.d.mts +103 -79
- package/index.d.ts +103 -79
- package/index.js +326 -316
- package/index.mjs +323 -314
- package/package.json +36 -1
- package/persist-plugins/async-storage.d.mts +6 -3
- package/persist-plugins/async-storage.d.ts +6 -3
- package/persist-plugins/async-storage.js +8 -4
- package/persist-plugins/async-storage.mjs +8 -5
- package/persist-plugins/indexeddb.d.mts +6 -4
- package/persist-plugins/indexeddb.d.ts +6 -4
- package/persist-plugins/indexeddb.js +35 -15
- package/persist-plugins/indexeddb.mjs +35 -16
- package/persist-plugins/mmkv.d.mts +5 -1
- package/persist-plugins/mmkv.d.ts +5 -1
- package/persist-plugins/mmkv.js +10 -5
- package/persist-plugins/mmkv.mjs +10 -6
- package/react-reactive/enableReactComponents.d.mts +9 -0
- package/react-reactive/enableReactComponents.d.ts +9 -0
- package/react-reactive/enableReactComponents.js +19 -0
- package/react-reactive/enableReactComponents.mjs +17 -0
- package/react-reactive/enableReactNativeComponents.d.mts +22 -0
- package/react-reactive/enableReactNativeComponents.d.ts +22 -0
- package/react-reactive/enableReactNativeComponents.js +53 -0
- package/react-reactive/enableReactNativeComponents.mjs +51 -0
- package/react-reactive/enableReactive.d.mts +5 -0
- package/react-reactive/enableReactive.d.ts +5 -0
- package/react-reactive/enableReactive.js +24 -0
- package/react-reactive/enableReactive.mjs +22 -0
- package/react-reactive/enableReactive.native.d.mts +5 -0
- package/react-reactive/enableReactive.native.d.ts +5 -0
- package/react-reactive/enableReactive.native.js +58 -0
- package/react-reactive/enableReactive.native.mjs +56 -0
- package/react-reactive/enableReactive.web.d.mts +5 -0
- package/react-reactive/enableReactive.web.d.ts +5 -0
- package/react-reactive/enableReactive.web.js +58 -0
- package/react-reactive/enableReactive.web.mjs +56 -0
- package/react.d.mts +39 -34
- package/react.d.ts +39 -34
- package/react.js +39 -17
- package/react.mjs +39 -17
- package/sync-plugins/crud.d.mts +21 -23
- package/sync-plugins/crud.d.ts +21 -23
- package/sync-plugins/crud.js +224 -112
- package/sync-plugins/crud.mjs +226 -114
- package/sync-plugins/fetch.js +12 -8
- package/sync-plugins/fetch.mjs +13 -9
- package/sync-plugins/firebase.d.mts +27 -0
- package/sync-plugins/firebase.d.ts +27 -0
- package/sync-plugins/firebase.js +373 -0
- package/sync-plugins/firebase.mjs +368 -0
- package/sync-plugins/keel.d.mts +43 -26
- package/sync-plugins/keel.d.ts +43 -26
- package/sync-plugins/keel.js +145 -99
- package/sync-plugins/keel.mjs +147 -99
- package/sync-plugins/supabase.d.mts +19 -9
- package/sync-plugins/supabase.d.ts +19 -9
- package/sync-plugins/supabase.js +52 -21
- package/sync-plugins/supabase.mjs +53 -22
- package/sync-plugins/tanstack-query.d.mts +2 -2
- package/sync-plugins/tanstack-query.d.ts +2 -2
- package/sync-plugins/tanstack-query.js +22 -5
- package/sync-plugins/tanstack-query.mjs +22 -5
- package/sync-plugins/tanstack-react-query.d.mts +1 -1
- package/sync-plugins/tanstack-react-query.d.ts +1 -1
- package/sync-plugins/tanstack-react-query.js +8 -1
- package/sync-plugins/tanstack-react-query.mjs +8 -1
- package/sync.d.mts +74 -200
- package/sync.d.ts +74 -200
- package/sync.js +495 -281
- package/sync.mjs +500 -286
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@legendapp/state",
|
|
3
|
-
"version": "3.0.0-
|
|
3
|
+
"version": "3.0.0-beta.0",
|
|
4
4
|
"description": "legend-state",
|
|
5
5
|
"sideEffects": false,
|
|
6
6
|
"private": false,
|
|
@@ -68,6 +68,31 @@
|
|
|
68
68
|
"require": "./trace.js",
|
|
69
69
|
"types": "./trace.d.ts"
|
|
70
70
|
},
|
|
71
|
+
"./react-reactive/enableReactive": {
|
|
72
|
+
"import": "./react-reactive/enableReactive.mjs",
|
|
73
|
+
"require": "./react-reactive/enableReactive.js",
|
|
74
|
+
"types": "./react-reactive/enableReactive.d.ts"
|
|
75
|
+
},
|
|
76
|
+
"./react-reactive/enableReactComponents": {
|
|
77
|
+
"import": "./react-reactive/enableReactComponents.mjs",
|
|
78
|
+
"require": "./react-reactive/enableReactComponents.js",
|
|
79
|
+
"types": "./react-reactive/enableReactComponents.d.ts"
|
|
80
|
+
},
|
|
81
|
+
"./react-reactive/enableReactNativeComponents": {
|
|
82
|
+
"import": "./react-reactive/enableReactNativeComponents.mjs",
|
|
83
|
+
"require": "./react-reactive/enableReactNativeComponents.js",
|
|
84
|
+
"types": "./react-reactive/enableReactNativeComponents.d.ts"
|
|
85
|
+
},
|
|
86
|
+
"./react-reactive/enableReactive.native": {
|
|
87
|
+
"import": "./react-reactive/enableReactive.native.mjs",
|
|
88
|
+
"require": "./react-reactive/enableReactive.native.js",
|
|
89
|
+
"types": "./react-reactive/enableReactive.native.d.ts"
|
|
90
|
+
},
|
|
91
|
+
"./react-reactive/enableReactive.web": {
|
|
92
|
+
"import": "./react-reactive/enableReactive.web.mjs",
|
|
93
|
+
"require": "./react-reactive/enableReactive.web.js",
|
|
94
|
+
"types": "./react-reactive/enableReactive.web.d.ts"
|
|
95
|
+
},
|
|
71
96
|
"./as/stringAsSet": {
|
|
72
97
|
"import": "./as/stringAsSet.mjs",
|
|
73
98
|
"require": "./as/stringAsSet.js",
|
|
@@ -153,6 +178,11 @@
|
|
|
153
178
|
"require": "./config/enableReactTracking.js",
|
|
154
179
|
"types": "./config/enableReactTracking.d.ts"
|
|
155
180
|
},
|
|
181
|
+
"./config/configureLegendState": {
|
|
182
|
+
"import": "./config/configureLegendState.mjs",
|
|
183
|
+
"require": "./config/configureLegendState.js",
|
|
184
|
+
"types": "./config/configureLegendState.d.ts"
|
|
185
|
+
},
|
|
156
186
|
"./config/enable$GetSet": {
|
|
157
187
|
"import": "./config/enable$GetSet.mjs",
|
|
158
188
|
"require": "./config/enable$GetSet.js",
|
|
@@ -208,6 +238,11 @@
|
|
|
208
238
|
"require": "./sync-plugins/crud.js",
|
|
209
239
|
"types": "./sync-plugins/crud.d.ts"
|
|
210
240
|
},
|
|
241
|
+
"./sync-plugins/firebase": {
|
|
242
|
+
"import": "./sync-plugins/firebase.mjs",
|
|
243
|
+
"require": "./sync-plugins/firebase.js",
|
|
244
|
+
"types": "./sync-plugins/firebase.d.ts"
|
|
245
|
+
},
|
|
211
246
|
"./sync-plugins/tanstack-react-query": {
|
|
212
247
|
"import": "./sync-plugins/tanstack-react-query.mjs",
|
|
213
248
|
"require": "./sync-plugins/tanstack-react-query.js",
|
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
import { Change } from '@legendapp/state';
|
|
2
|
-
import { ObservablePersistPlugin,
|
|
2
|
+
import { ObservablePersistPlugin, ObservablePersistAsyncStoragePluginOptions, ObservablePersistPluginOptions, PersistMetadata } from '@legendapp/state/sync';
|
|
3
3
|
|
|
4
4
|
declare class ObservablePersistAsyncStorage implements ObservablePersistPlugin {
|
|
5
5
|
private data;
|
|
6
|
-
|
|
6
|
+
private configuration;
|
|
7
|
+
constructor(configuration: ObservablePersistAsyncStoragePluginOptions);
|
|
8
|
+
initialize(configOptions: ObservablePersistPluginOptions): Promise<void>;
|
|
7
9
|
loadTable(table: string): void | Promise<void>;
|
|
8
10
|
getTable(table: string, init: object): any;
|
|
9
11
|
getMetadata(table: string): PersistMetadata;
|
|
@@ -14,5 +16,6 @@ declare class ObservablePersistAsyncStorage implements ObservablePersistPlugin {
|
|
|
14
16
|
private setValue;
|
|
15
17
|
private save;
|
|
16
18
|
}
|
|
19
|
+
declare function observablePersistAsyncStorage(configuration: ObservablePersistAsyncStoragePluginOptions): ObservablePersistAsyncStorage;
|
|
17
20
|
|
|
18
|
-
export { ObservablePersistAsyncStorage };
|
|
21
|
+
export { ObservablePersistAsyncStorage, observablePersistAsyncStorage };
|
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
import { Change } from '@legendapp/state';
|
|
2
|
-
import { ObservablePersistPlugin,
|
|
2
|
+
import { ObservablePersistPlugin, ObservablePersistAsyncStoragePluginOptions, ObservablePersistPluginOptions, PersistMetadata } from '@legendapp/state/sync';
|
|
3
3
|
|
|
4
4
|
declare class ObservablePersistAsyncStorage implements ObservablePersistPlugin {
|
|
5
5
|
private data;
|
|
6
|
-
|
|
6
|
+
private configuration;
|
|
7
|
+
constructor(configuration: ObservablePersistAsyncStoragePluginOptions);
|
|
8
|
+
initialize(configOptions: ObservablePersistPluginOptions): Promise<void>;
|
|
7
9
|
loadTable(table: string): void | Promise<void>;
|
|
8
10
|
getTable(table: string, init: object): any;
|
|
9
11
|
getMetadata(table: string): PersistMetadata;
|
|
@@ -14,5 +16,6 @@ declare class ObservablePersistAsyncStorage implements ObservablePersistPlugin {
|
|
|
14
16
|
private setValue;
|
|
15
17
|
private save;
|
|
16
18
|
}
|
|
19
|
+
declare function observablePersistAsyncStorage(configuration: ObservablePersistAsyncStoragePluginOptions): ObservablePersistAsyncStorage;
|
|
17
20
|
|
|
18
|
-
export { ObservablePersistAsyncStorage };
|
|
21
|
+
export { ObservablePersistAsyncStorage, observablePersistAsyncStorage };
|
|
@@ -7,13 +7,13 @@ var MetadataSuffix = "__m";
|
|
|
7
7
|
var AsyncStorage;
|
|
8
8
|
var { safeParse, safeStringify } = state.internal;
|
|
9
9
|
var ObservablePersistAsyncStorage = class {
|
|
10
|
-
constructor() {
|
|
10
|
+
constructor(configuration) {
|
|
11
11
|
this.data = {};
|
|
12
|
+
this.configuration = configuration;
|
|
12
13
|
}
|
|
13
|
-
|
|
14
|
-
|
|
14
|
+
async initialize(configOptions) {
|
|
15
|
+
const storageConfig = this.configuration || configOptions.asyncStorage;
|
|
15
16
|
let tables = [];
|
|
16
|
-
const storageConfig = config.asyncStorage;
|
|
17
17
|
if (storageConfig) {
|
|
18
18
|
AsyncStorage = storageConfig.AsyncStorage;
|
|
19
19
|
const { preload } = storageConfig;
|
|
@@ -87,5 +87,9 @@ var ObservablePersistAsyncStorage = class {
|
|
|
87
87
|
}
|
|
88
88
|
}
|
|
89
89
|
};
|
|
90
|
+
function observablePersistAsyncStorage(configuration) {
|
|
91
|
+
return new ObservablePersistAsyncStorage(configuration);
|
|
92
|
+
}
|
|
90
93
|
|
|
91
94
|
exports.ObservablePersistAsyncStorage = ObservablePersistAsyncStorage;
|
|
95
|
+
exports.observablePersistAsyncStorage = observablePersistAsyncStorage;
|
|
@@ -5,13 +5,13 @@ var MetadataSuffix = "__m";
|
|
|
5
5
|
var AsyncStorage;
|
|
6
6
|
var { safeParse, safeStringify } = internal;
|
|
7
7
|
var ObservablePersistAsyncStorage = class {
|
|
8
|
-
constructor() {
|
|
8
|
+
constructor(configuration) {
|
|
9
9
|
this.data = {};
|
|
10
|
+
this.configuration = configuration;
|
|
10
11
|
}
|
|
11
|
-
|
|
12
|
-
|
|
12
|
+
async initialize(configOptions) {
|
|
13
|
+
const storageConfig = this.configuration || configOptions.asyncStorage;
|
|
13
14
|
let tables = [];
|
|
14
|
-
const storageConfig = config.asyncStorage;
|
|
15
15
|
if (storageConfig) {
|
|
16
16
|
AsyncStorage = storageConfig.AsyncStorage;
|
|
17
17
|
const { preload } = storageConfig;
|
|
@@ -85,5 +85,8 @@ var ObservablePersistAsyncStorage = class {
|
|
|
85
85
|
}
|
|
86
86
|
}
|
|
87
87
|
};
|
|
88
|
+
function observablePersistAsyncStorage(configuration) {
|
|
89
|
+
return new ObservablePersistAsyncStorage(configuration);
|
|
90
|
+
}
|
|
88
91
|
|
|
89
|
-
export { ObservablePersistAsyncStorage };
|
|
92
|
+
export { ObservablePersistAsyncStorage, observablePersistAsyncStorage };
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Change } from '@legendapp/state';
|
|
2
|
-
import { ObservablePersistPlugin, ObservablePersistPluginOptions, PersistOptions, PersistMetadata } from '@legendapp/state/sync';
|
|
2
|
+
import { ObservablePersistPlugin, ObservablePersistIndexedDBPluginOptions, ObservablePersistPluginOptions, PersistOptions, PersistMetadata } from '@legendapp/state/sync';
|
|
3
3
|
|
|
4
4
|
declare class ObservablePersistIndexedDB implements ObservablePersistPlugin {
|
|
5
5
|
private tableData;
|
|
@@ -9,8 +9,9 @@ declare class ObservablePersistIndexedDB implements ObservablePersistPlugin {
|
|
|
9
9
|
private isSaveTaskQueued;
|
|
10
10
|
private pendingSaves;
|
|
11
11
|
private promisesQueued;
|
|
12
|
-
|
|
13
|
-
|
|
12
|
+
private configuration;
|
|
13
|
+
constructor(configuration: ObservablePersistIndexedDBPluginOptions);
|
|
14
|
+
initialize(configOptions: ObservablePersistPluginOptions): Promise<void>;
|
|
14
15
|
loadTable(table: string, config: PersistOptions): void | Promise<void>;
|
|
15
16
|
getTable(table: string, init: object, config: PersistOptions): any;
|
|
16
17
|
getMetadata(table: string, config: PersistOptions): any;
|
|
@@ -25,5 +26,6 @@ declare class ObservablePersistIndexedDB implements ObservablePersistPlugin {
|
|
|
25
26
|
private _setItem;
|
|
26
27
|
private _setTable;
|
|
27
28
|
}
|
|
29
|
+
declare function observablePersistIndexedDB(configuration: ObservablePersistIndexedDBPluginOptions): ObservablePersistIndexedDB;
|
|
28
30
|
|
|
29
|
-
export { ObservablePersistIndexedDB };
|
|
31
|
+
export { ObservablePersistIndexedDB, observablePersistIndexedDB };
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Change } from '@legendapp/state';
|
|
2
|
-
import { ObservablePersistPlugin, ObservablePersistPluginOptions, PersistOptions, PersistMetadata } from '@legendapp/state/sync';
|
|
2
|
+
import { ObservablePersistPlugin, ObservablePersistIndexedDBPluginOptions, ObservablePersistPluginOptions, PersistOptions, PersistMetadata } from '@legendapp/state/sync';
|
|
3
3
|
|
|
4
4
|
declare class ObservablePersistIndexedDB implements ObservablePersistPlugin {
|
|
5
5
|
private tableData;
|
|
@@ -9,8 +9,9 @@ declare class ObservablePersistIndexedDB implements ObservablePersistPlugin {
|
|
|
9
9
|
private isSaveTaskQueued;
|
|
10
10
|
private pendingSaves;
|
|
11
11
|
private promisesQueued;
|
|
12
|
-
|
|
13
|
-
|
|
12
|
+
private configuration;
|
|
13
|
+
constructor(configuration: ObservablePersistIndexedDBPluginOptions);
|
|
14
|
+
initialize(configOptions: ObservablePersistPluginOptions): Promise<void>;
|
|
14
15
|
loadTable(table: string, config: PersistOptions): void | Promise<void>;
|
|
15
16
|
getTable(table: string, init: object, config: PersistOptions): any;
|
|
16
17
|
getMetadata(table: string, config: PersistOptions): any;
|
|
@@ -25,5 +26,6 @@ declare class ObservablePersistIndexedDB implements ObservablePersistPlugin {
|
|
|
25
26
|
private _setItem;
|
|
26
27
|
private _setTable;
|
|
27
28
|
}
|
|
29
|
+
declare function observablePersistIndexedDB(configuration: ObservablePersistIndexedDBPluginOptions): ObservablePersistIndexedDB;
|
|
28
30
|
|
|
29
|
-
export { ObservablePersistIndexedDB };
|
|
31
|
+
export { ObservablePersistIndexedDB, observablePersistIndexedDB };
|
|
@@ -9,36 +9,47 @@ function requestToPromise(request) {
|
|
|
9
9
|
return new Promise((resolve) => request.onsuccess = () => resolve());
|
|
10
10
|
}
|
|
11
11
|
var ObservablePersistIndexedDB = class {
|
|
12
|
-
constructor() {
|
|
12
|
+
constructor(configuration) {
|
|
13
13
|
this.tableData = {};
|
|
14
14
|
this.tableMetadata = {};
|
|
15
15
|
this.tablesAdjusted = /* @__PURE__ */ new Map();
|
|
16
16
|
this.isSaveTaskQueued = false;
|
|
17
17
|
this.pendingSaves = /* @__PURE__ */ new Map();
|
|
18
18
|
this.promisesQueued = [];
|
|
19
|
+
this.configuration = configuration;
|
|
19
20
|
this.doSave = this.doSave.bind(this);
|
|
20
21
|
}
|
|
21
|
-
async initialize(
|
|
22
|
+
async initialize(configOptions) {
|
|
23
|
+
const config = this.configuration || configOptions.indexedDB;
|
|
22
24
|
if (typeof indexedDB === "undefined")
|
|
23
25
|
return;
|
|
24
|
-
if (process.env.NODE_ENV === "development" && !
|
|
26
|
+
if (process.env.NODE_ENV === "development" && !config) {
|
|
25
27
|
console.error("[legend-state] Must configure ObservablePersistIndexedDB");
|
|
26
28
|
}
|
|
27
|
-
const { databaseName, version, tableNames } = config
|
|
29
|
+
const { databaseName, version, tableNames } = config;
|
|
28
30
|
const openRequest = indexedDB.open(databaseName, version);
|
|
29
31
|
openRequest.onerror = () => {
|
|
30
|
-
console.error("
|
|
32
|
+
console.error("[legend-state] ObservablePersistIndexedDB load error", openRequest.error);
|
|
31
33
|
};
|
|
32
|
-
openRequest.onupgradeneeded = () => {
|
|
34
|
+
openRequest.onupgradeneeded = (event) => {
|
|
33
35
|
const db = openRequest.result;
|
|
34
|
-
const { tableNames: tableNames2 } = config
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
36
|
+
const { tableNames: tableNames2, deleteTableNames, onUpgradeNeeded } = config;
|
|
37
|
+
if (onUpgradeNeeded) {
|
|
38
|
+
onUpgradeNeeded(event);
|
|
39
|
+
} else {
|
|
40
|
+
deleteTableNames == null ? void 0 : deleteTableNames.forEach((table) => {
|
|
41
|
+
if (db.objectStoreNames.contains(table)) {
|
|
42
|
+
db.deleteObjectStore(table);
|
|
43
|
+
}
|
|
44
|
+
});
|
|
45
|
+
tableNames2.forEach((table) => {
|
|
46
|
+
if (!db.objectStoreNames.contains(table)) {
|
|
47
|
+
db.createObjectStore(table, {
|
|
48
|
+
keyPath: "id"
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
});
|
|
52
|
+
}
|
|
42
53
|
};
|
|
43
54
|
return new Promise((resolve) => {
|
|
44
55
|
openRequest.onsuccess = async () => {
|
|
@@ -57,6 +68,11 @@ var ObservablePersistIndexedDB = class {
|
|
|
57
68
|
}
|
|
58
69
|
loadTable(table, config) {
|
|
59
70
|
var _a;
|
|
71
|
+
if (!this.db) {
|
|
72
|
+
throw new Error(
|
|
73
|
+
"[legend-state] ObservablePersistIndexedDB loading without being initialized. This may happen when running outside of a browser."
|
|
74
|
+
);
|
|
75
|
+
}
|
|
60
76
|
if (!this.tableData[table]) {
|
|
61
77
|
const transaction = this.db.transaction(table, "readonly");
|
|
62
78
|
return this.initTable(table, transaction).then(() => this.loadTable(table, config));
|
|
@@ -163,7 +179,7 @@ var ObservablePersistIndexedDB = class {
|
|
|
163
179
|
pendingTable.items.add(key);
|
|
164
180
|
} else {
|
|
165
181
|
this.tableData[table] = valueAtPath;
|
|
166
|
-
pendingTable.tablePrev = prev;
|
|
182
|
+
pendingTable.tablePrev = prev || {};
|
|
167
183
|
break;
|
|
168
184
|
}
|
|
169
185
|
}
|
|
@@ -363,5 +379,9 @@ var ObservablePersistIndexedDB = class {
|
|
|
363
379
|
return lastSet;
|
|
364
380
|
}
|
|
365
381
|
};
|
|
382
|
+
function observablePersistIndexedDB(configuration) {
|
|
383
|
+
return new ObservablePersistIndexedDB(configuration);
|
|
384
|
+
}
|
|
366
385
|
|
|
367
386
|
exports.ObservablePersistIndexedDB = ObservablePersistIndexedDB;
|
|
387
|
+
exports.observablePersistIndexedDB = observablePersistIndexedDB;
|
|
@@ -7,36 +7,47 @@ function requestToPromise(request) {
|
|
|
7
7
|
return new Promise((resolve) => request.onsuccess = () => resolve());
|
|
8
8
|
}
|
|
9
9
|
var ObservablePersistIndexedDB = class {
|
|
10
|
-
constructor() {
|
|
10
|
+
constructor(configuration) {
|
|
11
11
|
this.tableData = {};
|
|
12
12
|
this.tableMetadata = {};
|
|
13
13
|
this.tablesAdjusted = /* @__PURE__ */ new Map();
|
|
14
14
|
this.isSaveTaskQueued = false;
|
|
15
15
|
this.pendingSaves = /* @__PURE__ */ new Map();
|
|
16
16
|
this.promisesQueued = [];
|
|
17
|
+
this.configuration = configuration;
|
|
17
18
|
this.doSave = this.doSave.bind(this);
|
|
18
19
|
}
|
|
19
|
-
async initialize(
|
|
20
|
+
async initialize(configOptions) {
|
|
21
|
+
const config = this.configuration || configOptions.indexedDB;
|
|
20
22
|
if (typeof indexedDB === "undefined")
|
|
21
23
|
return;
|
|
22
|
-
if (process.env.NODE_ENV === "development" && !
|
|
24
|
+
if (process.env.NODE_ENV === "development" && !config) {
|
|
23
25
|
console.error("[legend-state] Must configure ObservablePersistIndexedDB");
|
|
24
26
|
}
|
|
25
|
-
const { databaseName, version, tableNames } = config
|
|
27
|
+
const { databaseName, version, tableNames } = config;
|
|
26
28
|
const openRequest = indexedDB.open(databaseName, version);
|
|
27
29
|
openRequest.onerror = () => {
|
|
28
|
-
console.error("
|
|
30
|
+
console.error("[legend-state] ObservablePersistIndexedDB load error", openRequest.error);
|
|
29
31
|
};
|
|
30
|
-
openRequest.onupgradeneeded = () => {
|
|
32
|
+
openRequest.onupgradeneeded = (event) => {
|
|
31
33
|
const db = openRequest.result;
|
|
32
|
-
const { tableNames: tableNames2 } = config
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
34
|
+
const { tableNames: tableNames2, deleteTableNames, onUpgradeNeeded } = config;
|
|
35
|
+
if (onUpgradeNeeded) {
|
|
36
|
+
onUpgradeNeeded(event);
|
|
37
|
+
} else {
|
|
38
|
+
deleteTableNames == null ? void 0 : deleteTableNames.forEach((table) => {
|
|
39
|
+
if (db.objectStoreNames.contains(table)) {
|
|
40
|
+
db.deleteObjectStore(table);
|
|
41
|
+
}
|
|
42
|
+
});
|
|
43
|
+
tableNames2.forEach((table) => {
|
|
44
|
+
if (!db.objectStoreNames.contains(table)) {
|
|
45
|
+
db.createObjectStore(table, {
|
|
46
|
+
keyPath: "id"
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
});
|
|
50
|
+
}
|
|
40
51
|
};
|
|
41
52
|
return new Promise((resolve) => {
|
|
42
53
|
openRequest.onsuccess = async () => {
|
|
@@ -55,6 +66,11 @@ var ObservablePersistIndexedDB = class {
|
|
|
55
66
|
}
|
|
56
67
|
loadTable(table, config) {
|
|
57
68
|
var _a;
|
|
69
|
+
if (!this.db) {
|
|
70
|
+
throw new Error(
|
|
71
|
+
"[legend-state] ObservablePersistIndexedDB loading without being initialized. This may happen when running outside of a browser."
|
|
72
|
+
);
|
|
73
|
+
}
|
|
58
74
|
if (!this.tableData[table]) {
|
|
59
75
|
const transaction = this.db.transaction(table, "readonly");
|
|
60
76
|
return this.initTable(table, transaction).then(() => this.loadTable(table, config));
|
|
@@ -161,7 +177,7 @@ var ObservablePersistIndexedDB = class {
|
|
|
161
177
|
pendingTable.items.add(key);
|
|
162
178
|
} else {
|
|
163
179
|
this.tableData[table] = valueAtPath;
|
|
164
|
-
pendingTable.tablePrev = prev;
|
|
180
|
+
pendingTable.tablePrev = prev || {};
|
|
165
181
|
break;
|
|
166
182
|
}
|
|
167
183
|
}
|
|
@@ -361,5 +377,8 @@ var ObservablePersistIndexedDB = class {
|
|
|
361
377
|
return lastSet;
|
|
362
378
|
}
|
|
363
379
|
};
|
|
380
|
+
function observablePersistIndexedDB(configuration) {
|
|
381
|
+
return new ObservablePersistIndexedDB(configuration);
|
|
382
|
+
}
|
|
364
383
|
|
|
365
|
-
export { ObservablePersistIndexedDB };
|
|
384
|
+
export { ObservablePersistIndexedDB, observablePersistIndexedDB };
|
|
@@ -1,9 +1,12 @@
|
|
|
1
1
|
import { Change } from '@legendapp/state';
|
|
2
2
|
import { ObservablePersistPlugin, PersistOptions, PersistMetadata } from '@legendapp/state/sync';
|
|
3
|
+
import { MMKVConfiguration } from 'react-native-mmkv';
|
|
3
4
|
|
|
4
5
|
declare class ObservablePersistMMKV implements ObservablePersistPlugin {
|
|
5
6
|
private data;
|
|
6
7
|
private storages;
|
|
8
|
+
private configuration;
|
|
9
|
+
constructor(configuration: MMKVConfiguration);
|
|
7
10
|
getTable<T = any>(table: string, init: object, config: PersistOptions): T;
|
|
8
11
|
getMetadata(table: string, config: PersistOptions): PersistMetadata;
|
|
9
12
|
set(table: string, changes: Change[], config: PersistOptions): void;
|
|
@@ -14,5 +17,6 @@ declare class ObservablePersistMMKV implements ObservablePersistPlugin {
|
|
|
14
17
|
private setValue;
|
|
15
18
|
private save;
|
|
16
19
|
}
|
|
20
|
+
declare function observablePersistMMKV(configuration: MMKVConfiguration): ObservablePersistMMKV;
|
|
17
21
|
|
|
18
|
-
export { ObservablePersistMMKV };
|
|
22
|
+
export { ObservablePersistMMKV, observablePersistMMKV };
|
|
@@ -1,9 +1,12 @@
|
|
|
1
1
|
import { Change } from '@legendapp/state';
|
|
2
2
|
import { ObservablePersistPlugin, PersistOptions, PersistMetadata } from '@legendapp/state/sync';
|
|
3
|
+
import { MMKVConfiguration } from 'react-native-mmkv';
|
|
3
4
|
|
|
4
5
|
declare class ObservablePersistMMKV implements ObservablePersistPlugin {
|
|
5
6
|
private data;
|
|
6
7
|
private storages;
|
|
8
|
+
private configuration;
|
|
9
|
+
constructor(configuration: MMKVConfiguration);
|
|
7
10
|
getTable<T = any>(table: string, init: object, config: PersistOptions): T;
|
|
8
11
|
getMetadata(table: string, config: PersistOptions): PersistMetadata;
|
|
9
12
|
set(table: string, changes: Change[], config: PersistOptions): void;
|
|
@@ -14,5 +17,6 @@ declare class ObservablePersistMMKV implements ObservablePersistPlugin {
|
|
|
14
17
|
private setValue;
|
|
15
18
|
private save;
|
|
16
19
|
}
|
|
20
|
+
declare function observablePersistMMKV(configuration: MMKVConfiguration): ObservablePersistMMKV;
|
|
17
21
|
|
|
18
|
-
export { ObservablePersistMMKV };
|
|
22
|
+
export { ObservablePersistMMKV, observablePersistMMKV };
|
package/persist-plugins/mmkv.js
CHANGED
|
@@ -8,7 +8,7 @@ var symbolDefault = Symbol();
|
|
|
8
8
|
var MetadataSuffix = "__m";
|
|
9
9
|
var { safeParse, safeStringify } = state.internal;
|
|
10
10
|
var ObservablePersistMMKV = class {
|
|
11
|
-
constructor() {
|
|
11
|
+
constructor(configuration) {
|
|
12
12
|
this.data = {};
|
|
13
13
|
this.storages = /* @__PURE__ */ new Map([
|
|
14
14
|
[
|
|
@@ -18,6 +18,7 @@ var ObservablePersistMMKV = class {
|
|
|
18
18
|
})
|
|
19
19
|
]
|
|
20
20
|
]);
|
|
21
|
+
this.configuration = configuration;
|
|
21
22
|
}
|
|
22
23
|
// Gets
|
|
23
24
|
getTable(table, init, config) {
|
|
@@ -59,12 +60,12 @@ var ObservablePersistMMKV = class {
|
|
|
59
60
|
}
|
|
60
61
|
// Private
|
|
61
62
|
getStorage(config) {
|
|
62
|
-
const
|
|
63
|
-
if (
|
|
64
|
-
const key = JSON.stringify(
|
|
63
|
+
const configuration = config.mmkv || this.configuration;
|
|
64
|
+
if (configuration) {
|
|
65
|
+
const key = JSON.stringify(configuration);
|
|
65
66
|
let storage = this.storages.get(key);
|
|
66
67
|
if (!storage) {
|
|
67
|
-
storage = new reactNativeMmkv.MMKV(
|
|
68
|
+
storage = new reactNativeMmkv.MMKV(configuration);
|
|
68
69
|
this.storages.set(key, storage);
|
|
69
70
|
}
|
|
70
71
|
return storage;
|
|
@@ -90,5 +91,9 @@ var ObservablePersistMMKV = class {
|
|
|
90
91
|
}
|
|
91
92
|
}
|
|
92
93
|
};
|
|
94
|
+
function observablePersistMMKV(configuration) {
|
|
95
|
+
return new ObservablePersistMMKV(configuration);
|
|
96
|
+
}
|
|
93
97
|
|
|
94
98
|
exports.ObservablePersistMMKV = ObservablePersistMMKV;
|
|
99
|
+
exports.observablePersistMMKV = observablePersistMMKV;
|
package/persist-plugins/mmkv.mjs
CHANGED
|
@@ -6,7 +6,7 @@ var symbolDefault = Symbol();
|
|
|
6
6
|
var MetadataSuffix = "__m";
|
|
7
7
|
var { safeParse, safeStringify } = internal;
|
|
8
8
|
var ObservablePersistMMKV = class {
|
|
9
|
-
constructor() {
|
|
9
|
+
constructor(configuration) {
|
|
10
10
|
this.data = {};
|
|
11
11
|
this.storages = /* @__PURE__ */ new Map([
|
|
12
12
|
[
|
|
@@ -16,6 +16,7 @@ var ObservablePersistMMKV = class {
|
|
|
16
16
|
})
|
|
17
17
|
]
|
|
18
18
|
]);
|
|
19
|
+
this.configuration = configuration;
|
|
19
20
|
}
|
|
20
21
|
// Gets
|
|
21
22
|
getTable(table, init, config) {
|
|
@@ -57,12 +58,12 @@ var ObservablePersistMMKV = class {
|
|
|
57
58
|
}
|
|
58
59
|
// Private
|
|
59
60
|
getStorage(config) {
|
|
60
|
-
const
|
|
61
|
-
if (
|
|
62
|
-
const key = JSON.stringify(
|
|
61
|
+
const configuration = config.mmkv || this.configuration;
|
|
62
|
+
if (configuration) {
|
|
63
|
+
const key = JSON.stringify(configuration);
|
|
63
64
|
let storage = this.storages.get(key);
|
|
64
65
|
if (!storage) {
|
|
65
|
-
storage = new MMKV(
|
|
66
|
+
storage = new MMKV(configuration);
|
|
66
67
|
this.storages.set(key, storage);
|
|
67
68
|
}
|
|
68
69
|
return storage;
|
|
@@ -88,5 +89,8 @@ var ObservablePersistMMKV = class {
|
|
|
88
89
|
}
|
|
89
90
|
}
|
|
90
91
|
};
|
|
92
|
+
function observablePersistMMKV(configuration) {
|
|
93
|
+
return new ObservablePersistMMKV(configuration);
|
|
94
|
+
}
|
|
91
95
|
|
|
92
|
-
export { ObservablePersistMMKV };
|
|
96
|
+
export { ObservablePersistMMKV, observablePersistMMKV };
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { FCReactiveObject, configureReactive } from '@legendapp/state/react';
|
|
2
|
+
|
|
3
|
+
declare function enableReactComponents(config: typeof configureReactive): void;
|
|
4
|
+
declare module '@legendapp/state/react' {
|
|
5
|
+
interface IReactive extends FCReactiveObject<JSX.IntrinsicElements> {
|
|
6
|
+
}
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export { enableReactComponents };
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { FCReactiveObject, configureReactive } from '@legendapp/state/react';
|
|
2
|
+
|
|
3
|
+
declare function enableReactComponents(config: typeof configureReactive): void;
|
|
4
|
+
declare module '@legendapp/state/react' {
|
|
5
|
+
interface IReactive extends FCReactiveObject<JSX.IntrinsicElements> {
|
|
6
|
+
}
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export { enableReactComponents };
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
// src/react-reactive/enableReactComponents.ts
|
|
4
|
+
function enableReactComponents(config) {
|
|
5
|
+
const bindInfo = { value: { handler: "onChange", getValue: (e) => e.target.value, defaultValue: "" } };
|
|
6
|
+
const bindInfoInput = Object.assign(
|
|
7
|
+
{ checked: { handler: "onChange", getValue: (e) => e.target.checked } },
|
|
8
|
+
bindInfo
|
|
9
|
+
);
|
|
10
|
+
config({
|
|
11
|
+
binders: {
|
|
12
|
+
input: bindInfoInput,
|
|
13
|
+
textarea: bindInfo,
|
|
14
|
+
select: bindInfo
|
|
15
|
+
}
|
|
16
|
+
});
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
exports.enableReactComponents = enableReactComponents;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
// src/react-reactive/enableReactComponents.ts
|
|
2
|
+
function enableReactComponents(config) {
|
|
3
|
+
const bindInfo = { value: { handler: "onChange", getValue: (e) => e.target.value, defaultValue: "" } };
|
|
4
|
+
const bindInfoInput = Object.assign(
|
|
5
|
+
{ checked: { handler: "onChange", getValue: (e) => e.target.checked } },
|
|
6
|
+
bindInfo
|
|
7
|
+
);
|
|
8
|
+
config({
|
|
9
|
+
binders: {
|
|
10
|
+
input: bindInfoInput,
|
|
11
|
+
textarea: bindInfo,
|
|
12
|
+
select: bindInfo
|
|
13
|
+
}
|
|
14
|
+
});
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export { enableReactComponents };
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { FCReactiveObject, FCReactive, configureReactive } from '@legendapp/state/react';
|
|
2
|
+
import { ActivityIndicator, ActivityIndicatorProps, Button, ButtonProps, FlatList, FlatListProps, Image, ImageProps, Pressable, PressableProps, ScrollView, ScrollViewProps, SectionList, SectionListProps, Switch, SwitchProps, Text, TextProps, TextInput, TextInputProps, TouchableWithoutFeedback, TouchableWithoutFeedbackProps, View, ViewProps } from 'react-native';
|
|
3
|
+
|
|
4
|
+
declare function enableReactNativeComponents(configure: typeof configureReactive): void;
|
|
5
|
+
declare module '@legendapp/state/react' {
|
|
6
|
+
interface IReactive extends FCReactiveObject<JSX.IntrinsicElements> {
|
|
7
|
+
ActivityIndicator: FCReactive<ActivityIndicator, ActivityIndicatorProps>;
|
|
8
|
+
Button: FCReactive<Button, ButtonProps>;
|
|
9
|
+
FlatList: FCReactive<FlatList, FlatListProps<any>>;
|
|
10
|
+
Image: FCReactive<Image, ImageProps>;
|
|
11
|
+
Pressable: FCReactive<typeof Pressable, PressableProps>;
|
|
12
|
+
ScrollView: FCReactive<ScrollView, ScrollViewProps>;
|
|
13
|
+
SectionList: FCReactive<SectionList, SectionListProps<any>>;
|
|
14
|
+
Switch: FCReactive<Switch, SwitchProps>;
|
|
15
|
+
Text: FCReactive<Text, TextProps>;
|
|
16
|
+
TextInput: FCReactive<TextInput, TextInputProps>;
|
|
17
|
+
TouchableWithoutFeedback: FCReactive<TouchableWithoutFeedback, TouchableWithoutFeedbackProps>;
|
|
18
|
+
View: FCReactive<View, ViewProps>;
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export { enableReactNativeComponents };
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { FCReactiveObject, FCReactive, configureReactive } from '@legendapp/state/react';
|
|
2
|
+
import { ActivityIndicator, ActivityIndicatorProps, Button, ButtonProps, FlatList, FlatListProps, Image, ImageProps, Pressable, PressableProps, ScrollView, ScrollViewProps, SectionList, SectionListProps, Switch, SwitchProps, Text, TextProps, TextInput, TextInputProps, TouchableWithoutFeedback, TouchableWithoutFeedbackProps, View, ViewProps } from 'react-native';
|
|
3
|
+
|
|
4
|
+
declare function enableReactNativeComponents(configure: typeof configureReactive): void;
|
|
5
|
+
declare module '@legendapp/state/react' {
|
|
6
|
+
interface IReactive extends FCReactiveObject<JSX.IntrinsicElements> {
|
|
7
|
+
ActivityIndicator: FCReactive<ActivityIndicator, ActivityIndicatorProps>;
|
|
8
|
+
Button: FCReactive<Button, ButtonProps>;
|
|
9
|
+
FlatList: FCReactive<FlatList, FlatListProps<any>>;
|
|
10
|
+
Image: FCReactive<Image, ImageProps>;
|
|
11
|
+
Pressable: FCReactive<typeof Pressable, PressableProps>;
|
|
12
|
+
ScrollView: FCReactive<ScrollView, ScrollViewProps>;
|
|
13
|
+
SectionList: FCReactive<SectionList, SectionListProps<any>>;
|
|
14
|
+
Switch: FCReactive<Switch, SwitchProps>;
|
|
15
|
+
Text: FCReactive<Text, TextProps>;
|
|
16
|
+
TextInput: FCReactive<TextInput, TextInputProps>;
|
|
17
|
+
TouchableWithoutFeedback: FCReactive<TouchableWithoutFeedback, TouchableWithoutFeedbackProps>;
|
|
18
|
+
View: FCReactive<View, ViewProps>;
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export { enableReactNativeComponents };
|