@legendapp/state 3.0.0-alpha.3 → 3.0.0-alpha.31
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/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/config.d.mts +13 -0
- package/config.d.ts +13 -0
- package/config.js +2066 -0
- package/config.mjs +2064 -0
- package/helpers/trackHistory.js +2 -2
- package/helpers/trackHistory.mjs +2 -2
- package/index.d.mts +25 -302
- package/index.d.ts +25 -302
- package/index.js +293 -322
- package/index.mjs +294 -321
- package/observableInterfaces-CZR3_8mM.d.mts +283 -0
- package/observableInterfaces-CZR3_8mM.d.ts +283 -0
- package/package.json +11 -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 +12 -4
- package/persist-plugins/async-storage.mjs +12 -5
- package/persist-plugins/indexeddb.d.mts +6 -4
- package/persist-plugins/indexeddb.d.ts +6 -4
- package/persist-plugins/indexeddb.js +16 -6
- package/persist-plugins/indexeddb.mjs +16 -7
- package/persist-plugins/mmkv.d.mts +5 -1
- package/persist-plugins/mmkv.d.ts +5 -1
- package/persist-plugins/mmkv.js +14 -5
- package/persist-plugins/mmkv.mjs +14 -6
- package/react.d.mts +18 -14
- package/react.d.ts +18 -14
- package/react.js +57 -32
- package/react.mjs +58 -33
- package/sync-plugins/crud.d.mts +21 -24
- package/sync-plugins/crud.d.ts +21 -24
- package/sync-plugins/crud.js +240 -139
- package/sync-plugins/crud.mjs +242 -141
- 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 +27 -10
- package/sync-plugins/keel.d.ts +27 -10
- package/sync-plugins/keel.js +51 -32
- package/sync-plugins/keel.mjs +52 -33
- package/sync-plugins/supabase.d.mts +12 -7
- package/sync-plugins/supabase.d.ts +12 -7
- package/sync-plugins/supabase.js +24 -13
- package/sync-plugins/supabase.mjs +25 -14
- 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 +71 -197
- package/sync.d.ts +71 -197
- package/sync.js +465 -284
- package/sync.mjs +471 -290
- 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
|
@@ -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,13 @@ var ObservablePersistAsyncStorage = class {
|
|
|
87
87
|
}
|
|
88
88
|
}
|
|
89
89
|
};
|
|
90
|
+
function configureObservablePersistAsyncStorage(configuration) {
|
|
91
|
+
return class ObservablePersistAsyncStorageConfigured extends ObservablePersistAsyncStorage {
|
|
92
|
+
constructor() {
|
|
93
|
+
super(configuration);
|
|
94
|
+
}
|
|
95
|
+
};
|
|
96
|
+
}
|
|
90
97
|
|
|
91
98
|
exports.ObservablePersistAsyncStorage = ObservablePersistAsyncStorage;
|
|
99
|
+
exports.configureObservablePersistAsyncStorage = configureObservablePersistAsyncStorage;
|
|
@@ -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,12 @@ var ObservablePersistAsyncStorage = class {
|
|
|
85
85
|
}
|
|
86
86
|
}
|
|
87
87
|
};
|
|
88
|
+
function configureObservablePersistAsyncStorage(configuration) {
|
|
89
|
+
return class ObservablePersistAsyncStorageConfigured extends ObservablePersistAsyncStorage {
|
|
90
|
+
constructor() {
|
|
91
|
+
super(configuration);
|
|
92
|
+
}
|
|
93
|
+
};
|
|
94
|
+
}
|
|
88
95
|
|
|
89
|
-
export { ObservablePersistAsyncStorage };
|
|
96
|
+
export { ObservablePersistAsyncStorage, configureObservablePersistAsyncStorage };
|
|
@@ -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 configureObservablePersistIndexedDB(configuration: ObservablePersistIndexedDBPluginOptions): typeof ObservablePersistIndexedDB;
|
|
28
30
|
|
|
29
|
-
export { ObservablePersistIndexedDB };
|
|
31
|
+
export { ObservablePersistIndexedDB, configureObservablePersistIndexedDB };
|
|
@@ -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 configureObservablePersistIndexedDB(configuration: ObservablePersistIndexedDBPluginOptions): typeof ObservablePersistIndexedDB;
|
|
28
30
|
|
|
29
|
-
export { ObservablePersistIndexedDB };
|
|
31
|
+
export { ObservablePersistIndexedDB, configureObservablePersistIndexedDB };
|
|
@@ -9,29 +9,31 @@ 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
32
|
console.error("Error", openRequest.error);
|
|
31
33
|
};
|
|
32
34
|
openRequest.onupgradeneeded = () => {
|
|
33
35
|
const db = openRequest.result;
|
|
34
|
-
const { tableNames: tableNames2 } = config
|
|
36
|
+
const { tableNames: tableNames2 } = config;
|
|
35
37
|
tableNames2.forEach((table) => {
|
|
36
38
|
if (!db.objectStoreNames.contains(table)) {
|
|
37
39
|
db.createObjectStore(table, {
|
|
@@ -163,7 +165,7 @@ var ObservablePersistIndexedDB = class {
|
|
|
163
165
|
pendingTable.items.add(key);
|
|
164
166
|
} else {
|
|
165
167
|
this.tableData[table] = valueAtPath;
|
|
166
|
-
pendingTable.tablePrev = prev;
|
|
168
|
+
pendingTable.tablePrev = prev || {};
|
|
167
169
|
break;
|
|
168
170
|
}
|
|
169
171
|
}
|
|
@@ -363,5 +365,13 @@ var ObservablePersistIndexedDB = class {
|
|
|
363
365
|
return lastSet;
|
|
364
366
|
}
|
|
365
367
|
};
|
|
368
|
+
function configureObservablePersistIndexedDB(configuration) {
|
|
369
|
+
return class ObservablePersistIndexedDBConfigured extends ObservablePersistIndexedDB {
|
|
370
|
+
constructor() {
|
|
371
|
+
super(configuration);
|
|
372
|
+
}
|
|
373
|
+
};
|
|
374
|
+
}
|
|
366
375
|
|
|
367
376
|
exports.ObservablePersistIndexedDB = ObservablePersistIndexedDB;
|
|
377
|
+
exports.configureObservablePersistIndexedDB = configureObservablePersistIndexedDB;
|
|
@@ -7,29 +7,31 @@ 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
30
|
console.error("Error", openRequest.error);
|
|
29
31
|
};
|
|
30
32
|
openRequest.onupgradeneeded = () => {
|
|
31
33
|
const db = openRequest.result;
|
|
32
|
-
const { tableNames: tableNames2 } = config
|
|
34
|
+
const { tableNames: tableNames2 } = config;
|
|
33
35
|
tableNames2.forEach((table) => {
|
|
34
36
|
if (!db.objectStoreNames.contains(table)) {
|
|
35
37
|
db.createObjectStore(table, {
|
|
@@ -161,7 +163,7 @@ var ObservablePersistIndexedDB = class {
|
|
|
161
163
|
pendingTable.items.add(key);
|
|
162
164
|
} else {
|
|
163
165
|
this.tableData[table] = valueAtPath;
|
|
164
|
-
pendingTable.tablePrev = prev;
|
|
166
|
+
pendingTable.tablePrev = prev || {};
|
|
165
167
|
break;
|
|
166
168
|
}
|
|
167
169
|
}
|
|
@@ -361,5 +363,12 @@ var ObservablePersistIndexedDB = class {
|
|
|
361
363
|
return lastSet;
|
|
362
364
|
}
|
|
363
365
|
};
|
|
366
|
+
function configureObservablePersistIndexedDB(configuration) {
|
|
367
|
+
return class ObservablePersistIndexedDBConfigured extends ObservablePersistIndexedDB {
|
|
368
|
+
constructor() {
|
|
369
|
+
super(configuration);
|
|
370
|
+
}
|
|
371
|
+
};
|
|
372
|
+
}
|
|
364
373
|
|
|
365
|
-
export { ObservablePersistIndexedDB };
|
|
374
|
+
export { ObservablePersistIndexedDB, configureObservablePersistIndexedDB };
|
|
@@ -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 configureObservablePersistMMKV(configuration: MMKVConfiguration): typeof ObservablePersistMMKV;
|
|
17
21
|
|
|
18
|
-
export { ObservablePersistMMKV };
|
|
22
|
+
export { ObservablePersistMMKV, configureObservablePersistMMKV };
|
|
@@ -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 configureObservablePersistMMKV(configuration: MMKVConfiguration): typeof ObservablePersistMMKV;
|
|
17
21
|
|
|
18
|
-
export { ObservablePersistMMKV };
|
|
22
|
+
export { ObservablePersistMMKV, configureObservablePersistMMKV };
|
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,13 @@ var ObservablePersistMMKV = class {
|
|
|
90
91
|
}
|
|
91
92
|
}
|
|
92
93
|
};
|
|
94
|
+
function configureObservablePersistMMKV(configuration) {
|
|
95
|
+
return class ObservablePersistMMKVConfigured extends ObservablePersistMMKV {
|
|
96
|
+
constructor() {
|
|
97
|
+
super(configuration);
|
|
98
|
+
}
|
|
99
|
+
};
|
|
100
|
+
}
|
|
93
101
|
|
|
94
102
|
exports.ObservablePersistMMKV = ObservablePersistMMKV;
|
|
103
|
+
exports.configureObservablePersistMMKV = configureObservablePersistMMKV;
|
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,12 @@ var ObservablePersistMMKV = class {
|
|
|
88
89
|
}
|
|
89
90
|
}
|
|
90
91
|
};
|
|
92
|
+
function configureObservablePersistMMKV(configuration) {
|
|
93
|
+
return class ObservablePersistMMKVConfigured extends ObservablePersistMMKV {
|
|
94
|
+
constructor() {
|
|
95
|
+
super(configuration);
|
|
96
|
+
}
|
|
97
|
+
};
|
|
98
|
+
}
|
|
91
99
|
|
|
92
|
-
export { ObservablePersistMMKV };
|
|
100
|
+
export { ObservablePersistMMKV, configureObservablePersistMMKV };
|
package/react.d.mts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import * as react from 'react';
|
|
2
|
-
import { ReactNode, ReactElement, FC, LegacyRef, ComponentClass, ReducerWithoutAction, ReducerStateWithoutAction, DispatchWithoutAction, Reducer, ReducerState, Dispatch, ReducerAction } from 'react';
|
|
3
|
-
import { ObservableParam, Observable, ObservableBoolean, Selector, RecursiveValueOrFunction,
|
|
2
|
+
import { ReactNode, ReactElement, FC, LegacyRef, ComponentClass, DependencyList, ReducerWithoutAction, ReducerStateWithoutAction, DispatchWithoutAction, Reducer, ReducerState, Dispatch, ReducerAction } from 'react';
|
|
3
|
+
import { ObservableParam, Observable, ObservableBoolean, Selector, RecursiveValueOrFunction, ObserveOptions, ObserveEvent, ObserveEventCallback } from '@legendapp/state';
|
|
4
4
|
|
|
5
5
|
declare function Computed({ children }: {
|
|
6
6
|
children: ObservableParam | (() => ReactNode);
|
|
@@ -69,6 +69,7 @@ interface PropsIfReady<T> {
|
|
|
69
69
|
}
|
|
70
70
|
interface PropsBase<T> {
|
|
71
71
|
else?: ReactNode | (() => ReactNode);
|
|
72
|
+
$value?: Observable<T>;
|
|
72
73
|
wrap?: FC;
|
|
73
74
|
children: ReactNode | ((value?: T) => ReactNode);
|
|
74
75
|
}
|
|
@@ -110,10 +111,10 @@ declare function reactiveObserver<T extends FC<any>>(component: T, bindKeys?: Bi
|
|
|
110
111
|
declare function reactiveObserver<T extends FC<any>, T2 extends keyof ExtractFCPropsType<T>>(component: T, bindKeys?: BindKeys<ExtractFCPropsType<T>>): T | FC<ShapeWithPick$<ExtractFCPropsType<T>, T2>>;
|
|
111
112
|
declare function reactiveComponents<P extends Record<string, FC>>(components: P): ObjectShapeWith$<P>;
|
|
112
113
|
|
|
113
|
-
declare function useComputed<T>(
|
|
114
|
-
declare function useComputed<T>(
|
|
115
|
-
declare function useComputed<T, T2 = T>(
|
|
116
|
-
declare function useComputed<T, T2 = T>(
|
|
114
|
+
declare function useComputed<T>(get: () => T | Promise<T>): Observable<T>;
|
|
115
|
+
declare function useComputed<T>(get: () => T | Promise<T>, deps: any[]): Observable<T>;
|
|
116
|
+
declare function useComputed<T, T2 = T>(get: (() => T | Promise<T>) | ObservableParam<T>, set: (value: T2) => void): Observable<T>;
|
|
117
|
+
declare function useComputed<T, T2 = T>(get: (() => T | Promise<T>) | ObservableParam<T>, set: (value: T2) => void, deps: any[]): Observable<T>;
|
|
117
118
|
|
|
118
119
|
declare const useEffectOnce: (effect: () => void | (() => void), deps: any[]) => void;
|
|
119
120
|
|
|
@@ -130,9 +131,9 @@ declare const useMountOnce: typeof useMount;
|
|
|
130
131
|
* @see https://www.legendapp.com/dev/state/react/#useObservable
|
|
131
132
|
*/
|
|
132
133
|
declare function useObservable<T>(): Observable<T | undefined>;
|
|
133
|
-
declare function useObservable<T>(value: Promise<RecursiveValueOrFunction<T>> | (() => RecursiveValueOrFunction<T>) | RecursiveValueOrFunction<T
|
|
134
|
-
declare function useObservable<T>(value: T): Observable<T>;
|
|
135
|
-
declare function useObservable<T>(value?: T): Observable<any>;
|
|
134
|
+
declare function useObservable<T>(value: Promise<RecursiveValueOrFunction<T>> | (() => RecursiveValueOrFunction<T>) | RecursiveValueOrFunction<T>, deps?: DependencyList): Observable<T>;
|
|
135
|
+
declare function useObservable<T>(value: T, deps?: DependencyList): Observable<T>;
|
|
136
|
+
declare function useObservable<T>(value?: T, deps?: DependencyList): Observable<any>;
|
|
136
137
|
|
|
137
138
|
declare function useObservableReducer<R extends ReducerWithoutAction<any>, I>(reducer: R, initializerArg: I, initializer: (arg: I) => ReducerStateWithoutAction<R>): [Observable<ReducerStateWithoutAction<R>>, DispatchWithoutAction];
|
|
138
139
|
declare function useObservableReducer<R extends ReducerWithoutAction<any>>(reducer: R, initializerArg: ReducerStateWithoutAction<R>, initializer?: undefined): [Observable<ReducerStateWithoutAction<R>>, DispatchWithoutAction];
|
|
@@ -140,11 +141,14 @@ declare function useObservableReducer<R extends Reducer<any, any>, I>(reducer: R
|
|
|
140
141
|
declare function useObservableReducer<R extends Reducer<any, any>, I>(reducer: R, initializerArg: I, initializer: (arg: I) => ReducerState<R>): [Observable<ReducerState<R>>, Dispatch<ReducerAction<R>>];
|
|
141
142
|
declare function useObservableReducer<R extends Reducer<any, any>>(reducer: R, initialState: ReducerState<R>, initializer?: undefined): [Observable<ReducerState<R>>, Dispatch<ReducerAction<R>>];
|
|
142
143
|
|
|
143
|
-
|
|
144
|
-
|
|
144
|
+
interface UseObserveOptions extends ObserveOptions {
|
|
145
|
+
deps?: any[];
|
|
146
|
+
}
|
|
147
|
+
declare function useObserve<T>(run: (e: ObserveEvent<T>) => T | void, options?: UseObserveOptions): () => void;
|
|
148
|
+
declare function useObserve<T>(selector: Selector<T>, reaction?: (e: ObserveEventCallback<T>) => any, options?: UseObserveOptions): () => void;
|
|
145
149
|
|
|
146
|
-
declare function useObserveEffect<T>(run: (e: ObserveEvent<T>) => T | void, options?:
|
|
147
|
-
declare function useObserveEffect<T>(selector: Selector<T>, reaction?: (e: ObserveEventCallback<T>) => any, options?:
|
|
150
|
+
declare function useObserveEffect<T>(run: (e: ObserveEvent<T>) => T | void, options?: UseObserveOptions): void;
|
|
151
|
+
declare function useObserveEffect<T>(selector: Selector<T>, reaction?: (e: ObserveEventCallback<T>) => any, options?: UseObserveOptions): void;
|
|
148
152
|
|
|
149
153
|
declare function useSelector<T>(selector: Selector<T>, options?: UseSelectorOptions): T;
|
|
150
154
|
|
|
@@ -154,4 +158,4 @@ declare const useUnmountOnce: typeof useUnmount;
|
|
|
154
158
|
declare function useWhen<T>(predicate: Selector<T>, effect: (value: T) => any | (() => any)): Promise<any>;
|
|
155
159
|
declare function useWhenReady<T>(predicate: Selector<T>, effect: (value: T) => any | (() => any)): Promise<any>;
|
|
156
160
|
|
|
157
|
-
export { type BindKey, type BindKeys, Computed, type ExtractFCPropsType, type FCReactive, type FCReactiveObject, For, type IReactive, Memo, type ObjectShapeWith$, Reactive, type ShapeWith$, type ShapeWithNew$, type ShapeWithPick$, Show, Switch, type UseSelectorOptions, configureReactive, hasSymbol, observer, reactive, reactiveComponents, reactiveObserver, useComputed, useEffectOnce, useIsMounted, useMount, useMountOnce, useObservable, useObservableReducer, useObserve, useObserveEffect, usePauseProvider, useSelector, useUnmount, useUnmountOnce, useWhen, useWhenReady };
|
|
161
|
+
export { type BindKey, type BindKeys, Computed, type ExtractFCPropsType, type FCReactive, type FCReactiveObject, For, type IReactive, Memo, type ObjectShapeWith$, Reactive, type ShapeWith$, type ShapeWithNew$, type ShapeWithPick$, Show, Switch, type UseObserveOptions, type UseSelectorOptions, configureReactive, hasSymbol, observer, reactive, reactiveComponents, reactiveObserver, useComputed, useEffectOnce, useIsMounted, useMount, useMountOnce, useObservable, useObservableReducer, useObserve, useObserveEffect, usePauseProvider, useSelector, useUnmount, useUnmountOnce, useWhen, useWhenReady };
|
package/react.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import * as react from 'react';
|
|
2
|
-
import { ReactNode, ReactElement, FC, LegacyRef, ComponentClass, ReducerWithoutAction, ReducerStateWithoutAction, DispatchWithoutAction, Reducer, ReducerState, Dispatch, ReducerAction } from 'react';
|
|
3
|
-
import { ObservableParam, Observable, ObservableBoolean, Selector, RecursiveValueOrFunction,
|
|
2
|
+
import { ReactNode, ReactElement, FC, LegacyRef, ComponentClass, DependencyList, ReducerWithoutAction, ReducerStateWithoutAction, DispatchWithoutAction, Reducer, ReducerState, Dispatch, ReducerAction } from 'react';
|
|
3
|
+
import { ObservableParam, Observable, ObservableBoolean, Selector, RecursiveValueOrFunction, ObserveOptions, ObserveEvent, ObserveEventCallback } from '@legendapp/state';
|
|
4
4
|
|
|
5
5
|
declare function Computed({ children }: {
|
|
6
6
|
children: ObservableParam | (() => ReactNode);
|
|
@@ -69,6 +69,7 @@ interface PropsIfReady<T> {
|
|
|
69
69
|
}
|
|
70
70
|
interface PropsBase<T> {
|
|
71
71
|
else?: ReactNode | (() => ReactNode);
|
|
72
|
+
$value?: Observable<T>;
|
|
72
73
|
wrap?: FC;
|
|
73
74
|
children: ReactNode | ((value?: T) => ReactNode);
|
|
74
75
|
}
|
|
@@ -110,10 +111,10 @@ declare function reactiveObserver<T extends FC<any>>(component: T, bindKeys?: Bi
|
|
|
110
111
|
declare function reactiveObserver<T extends FC<any>, T2 extends keyof ExtractFCPropsType<T>>(component: T, bindKeys?: BindKeys<ExtractFCPropsType<T>>): T | FC<ShapeWithPick$<ExtractFCPropsType<T>, T2>>;
|
|
111
112
|
declare function reactiveComponents<P extends Record<string, FC>>(components: P): ObjectShapeWith$<P>;
|
|
112
113
|
|
|
113
|
-
declare function useComputed<T>(
|
|
114
|
-
declare function useComputed<T>(
|
|
115
|
-
declare function useComputed<T, T2 = T>(
|
|
116
|
-
declare function useComputed<T, T2 = T>(
|
|
114
|
+
declare function useComputed<T>(get: () => T | Promise<T>): Observable<T>;
|
|
115
|
+
declare function useComputed<T>(get: () => T | Promise<T>, deps: any[]): Observable<T>;
|
|
116
|
+
declare function useComputed<T, T2 = T>(get: (() => T | Promise<T>) | ObservableParam<T>, set: (value: T2) => void): Observable<T>;
|
|
117
|
+
declare function useComputed<T, T2 = T>(get: (() => T | Promise<T>) | ObservableParam<T>, set: (value: T2) => void, deps: any[]): Observable<T>;
|
|
117
118
|
|
|
118
119
|
declare const useEffectOnce: (effect: () => void | (() => void), deps: any[]) => void;
|
|
119
120
|
|
|
@@ -130,9 +131,9 @@ declare const useMountOnce: typeof useMount;
|
|
|
130
131
|
* @see https://www.legendapp.com/dev/state/react/#useObservable
|
|
131
132
|
*/
|
|
132
133
|
declare function useObservable<T>(): Observable<T | undefined>;
|
|
133
|
-
declare function useObservable<T>(value: Promise<RecursiveValueOrFunction<T>> | (() => RecursiveValueOrFunction<T>) | RecursiveValueOrFunction<T
|
|
134
|
-
declare function useObservable<T>(value: T): Observable<T>;
|
|
135
|
-
declare function useObservable<T>(value?: T): Observable<any>;
|
|
134
|
+
declare function useObservable<T>(value: Promise<RecursiveValueOrFunction<T>> | (() => RecursiveValueOrFunction<T>) | RecursiveValueOrFunction<T>, deps?: DependencyList): Observable<T>;
|
|
135
|
+
declare function useObservable<T>(value: T, deps?: DependencyList): Observable<T>;
|
|
136
|
+
declare function useObservable<T>(value?: T, deps?: DependencyList): Observable<any>;
|
|
136
137
|
|
|
137
138
|
declare function useObservableReducer<R extends ReducerWithoutAction<any>, I>(reducer: R, initializerArg: I, initializer: (arg: I) => ReducerStateWithoutAction<R>): [Observable<ReducerStateWithoutAction<R>>, DispatchWithoutAction];
|
|
138
139
|
declare function useObservableReducer<R extends ReducerWithoutAction<any>>(reducer: R, initializerArg: ReducerStateWithoutAction<R>, initializer?: undefined): [Observable<ReducerStateWithoutAction<R>>, DispatchWithoutAction];
|
|
@@ -140,11 +141,14 @@ declare function useObservableReducer<R extends Reducer<any, any>, I>(reducer: R
|
|
|
140
141
|
declare function useObservableReducer<R extends Reducer<any, any>, I>(reducer: R, initializerArg: I, initializer: (arg: I) => ReducerState<R>): [Observable<ReducerState<R>>, Dispatch<ReducerAction<R>>];
|
|
141
142
|
declare function useObservableReducer<R extends Reducer<any, any>>(reducer: R, initialState: ReducerState<R>, initializer?: undefined): [Observable<ReducerState<R>>, Dispatch<ReducerAction<R>>];
|
|
142
143
|
|
|
143
|
-
|
|
144
|
-
|
|
144
|
+
interface UseObserveOptions extends ObserveOptions {
|
|
145
|
+
deps?: any[];
|
|
146
|
+
}
|
|
147
|
+
declare function useObserve<T>(run: (e: ObserveEvent<T>) => T | void, options?: UseObserveOptions): () => void;
|
|
148
|
+
declare function useObserve<T>(selector: Selector<T>, reaction?: (e: ObserveEventCallback<T>) => any, options?: UseObserveOptions): () => void;
|
|
145
149
|
|
|
146
|
-
declare function useObserveEffect<T>(run: (e: ObserveEvent<T>) => T | void, options?:
|
|
147
|
-
declare function useObserveEffect<T>(selector: Selector<T>, reaction?: (e: ObserveEventCallback<T>) => any, options?:
|
|
150
|
+
declare function useObserveEffect<T>(run: (e: ObserveEvent<T>) => T | void, options?: UseObserveOptions): void;
|
|
151
|
+
declare function useObserveEffect<T>(selector: Selector<T>, reaction?: (e: ObserveEventCallback<T>) => any, options?: UseObserveOptions): void;
|
|
148
152
|
|
|
149
153
|
declare function useSelector<T>(selector: Selector<T>, options?: UseSelectorOptions): T;
|
|
150
154
|
|
|
@@ -154,4 +158,4 @@ declare const useUnmountOnce: typeof useUnmount;
|
|
|
154
158
|
declare function useWhen<T>(predicate: Selector<T>, effect: (value: T) => any | (() => any)): Promise<any>;
|
|
155
159
|
declare function useWhenReady<T>(predicate: Selector<T>, effect: (value: T) => any | (() => any)): Promise<any>;
|
|
156
160
|
|
|
157
|
-
export { type BindKey, type BindKeys, Computed, type ExtractFCPropsType, type FCReactive, type FCReactiveObject, For, type IReactive, Memo, type ObjectShapeWith$, Reactive, type ShapeWith$, type ShapeWithNew$, type ShapeWithPick$, Show, Switch, type UseSelectorOptions, configureReactive, hasSymbol, observer, reactive, reactiveComponents, reactiveObserver, useComputed, useEffectOnce, useIsMounted, useMount, useMountOnce, useObservable, useObservableReducer, useObserve, useObserveEffect, usePauseProvider, useSelector, useUnmount, useUnmountOnce, useWhen, useWhenReady };
|
|
161
|
+
export { type BindKey, type BindKeys, Computed, type ExtractFCPropsType, type FCReactive, type FCReactiveObject, For, type IReactive, Memo, type ObjectShapeWith$, Reactive, type ShapeWith$, type ShapeWithNew$, type ShapeWithPick$, Show, Switch, type UseObserveOptions, type UseSelectorOptions, configureReactive, hasSymbol, observer, reactive, reactiveComponents, reactiveObserver, useComputed, useEffectOnce, useIsMounted, useMount, useMountOnce, useObservable, useObservableReducer, useObserve, useObserveEffect, usePauseProvider, useSelector, useUnmount, useUnmountOnce, useWhen, useWhenReady };
|