@legendapp/state 3.0.0-beta.3 → 3.0.0-beta.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/.DS_Store +0 -0
- package/config/enableReactComponents.js +3 -1
- package/config/enableReactComponents.mjs +3 -1
- package/config/enableReactTracking.d.mts +2 -1
- package/config/enableReactTracking.d.ts +2 -1
- package/config/enableReactTracking.js +32 -13
- package/config/enableReactTracking.mjs +32 -13
- package/index.d.mts +38 -5
- package/index.d.ts +38 -5
- package/index.js +202 -31
- package/index.mjs +202 -31
- package/package.json +35 -1
- package/persist-plugins/async-storage.js +17 -9
- package/persist-plugins/async-storage.mjs +17 -9
- package/persist-plugins/expo-sqlite.d.mts +19 -0
- package/persist-plugins/expo-sqlite.d.ts +19 -0
- package/persist-plugins/expo-sqlite.js +72 -0
- package/persist-plugins/expo-sqlite.mjs +69 -0
- package/react-native.d.mts +4 -0
- package/react-native.d.ts +4 -0
- package/react-native.js +53 -0
- package/react-native.mjs +40 -0
- package/react-reactive/Components.d.mts +19 -0
- package/react-reactive/Components.d.ts +19 -0
- package/react-reactive/Components.js +53 -0
- package/react-reactive/Components.mjs +40 -0
- package/react-reactive/enableReactComponents.d.mts +3 -2
- package/react-reactive/enableReactComponents.d.ts +3 -2
- package/react-reactive/enableReactComponents.js +10 -3
- package/react-reactive/enableReactComponents.mjs +10 -3
- package/react-reactive/enableReactNativeComponents.d.mts +3 -20
- package/react-reactive/enableReactNativeComponents.d.ts +3 -20
- package/react-reactive/enableReactNativeComponents.js +8 -3
- package/react-reactive/enableReactNativeComponents.mjs +8 -3
- package/react-reactive/enableReactive.js +10 -3
- package/react-reactive/enableReactive.mjs +10 -3
- package/react-reactive/enableReactive.native.js +8 -3
- package/react-reactive/enableReactive.native.mjs +8 -3
- package/react-reactive/enableReactive.web.js +8 -3
- package/react-reactive/enableReactive.web.mjs +8 -3
- package/react-web.d.mts +6 -0
- package/react-web.d.ts +6 -0
- package/react-web.js +39 -0
- package/react-web.mjs +37 -0
- package/react.d.mts +41 -21
- package/react.d.ts +41 -21
- package/react.js +86 -63
- package/react.mjs +87 -65
- package/sync-plugins/crud.d.mts +24 -9
- package/sync-plugins/crud.d.ts +24 -9
- package/sync-plugins/crud.js +250 -116
- package/sync-plugins/crud.mjs +251 -117
- package/sync-plugins/firebase.d.mts +7 -3
- package/sync-plugins/firebase.d.ts +7 -3
- package/sync-plugins/firebase.js +4 -2
- package/sync-plugins/firebase.mjs +4 -2
- package/sync-plugins/keel.d.mts +12 -13
- package/sync-plugins/keel.d.ts +12 -13
- package/sync-plugins/keel.js +60 -52
- package/sync-plugins/keel.mjs +61 -48
- package/sync-plugins/supabase.d.mts +7 -3
- package/sync-plugins/supabase.d.ts +7 -3
- package/sync-plugins/supabase.js +90 -33
- package/sync-plugins/supabase.mjs +91 -34
- package/sync-plugins/tanstack-query.d.mts +3 -3
- package/sync-plugins/tanstack-query.d.ts +3 -3
- package/sync.d.mts +16 -8
- package/sync.d.ts +16 -8
- package/sync.js +324 -215
- package/sync.mjs +323 -215
- package/trace.js +5 -6
- package/trace.mjs +5 -6
- package/types/reactive-native.d.ts +19 -0
- package/types/reactive-web.d.ts +7 -0
package/react.js
CHANGED
|
@@ -45,6 +45,7 @@ function createSelectorFunctions(options, isPaused$) {
|
|
|
45
45
|
} = state.trackSelector(
|
|
46
46
|
_selector,
|
|
47
47
|
_update,
|
|
48
|
+
options,
|
|
48
49
|
void 0,
|
|
49
50
|
void 0,
|
|
50
51
|
/*createResubscribe*/
|
|
@@ -100,12 +101,24 @@ function createSelectorFunctions(options, isPaused$) {
|
|
|
100
101
|
}
|
|
101
102
|
};
|
|
102
103
|
}
|
|
104
|
+
function doSuspense(selector) {
|
|
105
|
+
const vProm = state.when(selector);
|
|
106
|
+
if (React__default.default.use) {
|
|
107
|
+
React__default.default.use(vProm);
|
|
108
|
+
} else {
|
|
109
|
+
throw vProm;
|
|
110
|
+
}
|
|
111
|
+
}
|
|
103
112
|
function useSelector(selector, options) {
|
|
104
113
|
var _a;
|
|
114
|
+
let value;
|
|
105
115
|
if (reactGlobals.inObserver && state.isObservable(selector) && !(options == null ? void 0 : options.suspense)) {
|
|
106
|
-
|
|
116
|
+
value = state.computeSelector(selector, options);
|
|
117
|
+
if ((options == null ? void 0 : options.suspense) && value === void 0) {
|
|
118
|
+
doSuspense(selector);
|
|
119
|
+
}
|
|
120
|
+
return value;
|
|
107
121
|
}
|
|
108
|
-
let value;
|
|
109
122
|
try {
|
|
110
123
|
const isPaused$ = React.useContext(getPauseContext());
|
|
111
124
|
const selectorFn = React.useMemo(() => createSelectorFunctions(options, isPaused$), []);
|
|
@@ -120,16 +133,8 @@ function useSelector(selector, options) {
|
|
|
120
133
|
}
|
|
121
134
|
throw err;
|
|
122
135
|
}
|
|
123
|
-
if (options == null ? void 0 : options.suspense) {
|
|
124
|
-
|
|
125
|
-
if (state.isPromise(value) || !value && state.isObservable(selector)) {
|
|
126
|
-
const vProm = isProm ? value : state.when(selector);
|
|
127
|
-
if (React__default.default.use) {
|
|
128
|
-
React__default.default.use(vProm);
|
|
129
|
-
} else {
|
|
130
|
-
throw vProm;
|
|
131
|
-
}
|
|
132
|
-
}
|
|
136
|
+
if ((options == null ? void 0 : options.suspense) && value === void 0) {
|
|
137
|
+
doSuspense(selector);
|
|
133
138
|
}
|
|
134
139
|
return value;
|
|
135
140
|
}
|
|
@@ -140,7 +145,7 @@ function Computed({ children }) {
|
|
|
140
145
|
}
|
|
141
146
|
var hasSymbol = typeof Symbol === "function" && Symbol.for;
|
|
142
147
|
var didWarnProps = false;
|
|
143
|
-
function createReactiveComponent(component, observe3, reactive2, bindKeys) {
|
|
148
|
+
function createReactiveComponent(component, observe3, reactive2, keysReactive, bindKeys) {
|
|
144
149
|
const ReactForwardRefSymbol = hasSymbol ? Symbol.for("react.forward_ref") : (
|
|
145
150
|
// eslint-disable-next-line react/display-name, @typescript-eslint/no-unused-vars
|
|
146
151
|
typeof React.forwardRef === "function" && React.forwardRef((props) => null)["$$typeof"]
|
|
@@ -165,6 +170,7 @@ function createReactiveComponent(component, observe3, reactive2, bindKeys) {
|
|
|
165
170
|
throw new Error(`[legend-state] \`render\` property of ForwardRef was not a function`);
|
|
166
171
|
}
|
|
167
172
|
}
|
|
173
|
+
const keysReactiveSet = keysReactive ? new Set(keysReactive) : void 0;
|
|
168
174
|
const proxyHandler = {
|
|
169
175
|
apply(target, thisArg, argArray) {
|
|
170
176
|
if (reactive2) {
|
|
@@ -174,9 +180,10 @@ function createReactiveComponent(component, observe3, reactive2, bindKeys) {
|
|
|
174
180
|
for (let i = 0; i < keys.length; i++) {
|
|
175
181
|
const key = keys[i];
|
|
176
182
|
const p = props[key];
|
|
183
|
+
const isReactiveKey = keysReactiveSet && keysReactiveSet.has(key);
|
|
177
184
|
if (key === "children" && (state.isFunction(p) || state.isObservable(p))) {
|
|
178
185
|
props[key] = useSelector(p, { skipCheck: true });
|
|
179
|
-
} else if (key.startsWith("$") || key.endsWith("$")) {
|
|
186
|
+
} else if (isReactiveKey || key.startsWith("$") || key.endsWith("$")) {
|
|
180
187
|
if (process.env.NODE_ENV === "development" && !didWarnProps && key.endsWith("$")) {
|
|
181
188
|
didWarnProps = true;
|
|
182
189
|
console.warn(
|
|
@@ -186,7 +193,7 @@ function createReactiveComponent(component, observe3, reactive2, bindKeys) {
|
|
|
186
193
|
)}. See https://legendapp.com/open-source/state/migrating for more details.`
|
|
187
194
|
);
|
|
188
195
|
}
|
|
189
|
-
const k = key.endsWith("$") ? key.slice(0, -1) : key.slice(1);
|
|
196
|
+
const k = isReactiveKey ? key : key.endsWith("$") ? key.slice(0, -1) : key.slice(1);
|
|
190
197
|
const bind = bindKeys == null ? void 0 : bindKeys[k];
|
|
191
198
|
const shouldBind = bind && state.isObservable(p);
|
|
192
199
|
propsOut[k] = shouldBind && (bind == null ? void 0 : bind.selector) ? bind.selector(propsOut, p) : useSelector(p);
|
|
@@ -204,7 +211,9 @@ function createReactiveComponent(component, observe3, reactive2, bindKeys) {
|
|
|
204
211
|
process.env.NODE_ENV === "development" ? handlerFn : React.useCallback(handlerFn, [props[bind.handler], bindKeys]);
|
|
205
212
|
}
|
|
206
213
|
}
|
|
207
|
-
|
|
214
|
+
if (!isReactiveKey) {
|
|
215
|
+
delete propsOut[key];
|
|
216
|
+
}
|
|
208
217
|
} else if (propsOut[key] === void 0) {
|
|
209
218
|
propsOut[key] = p;
|
|
210
219
|
}
|
|
@@ -241,11 +250,11 @@ function createReactiveComponent(component, observe3, reactive2, bindKeys) {
|
|
|
241
250
|
function observer(component) {
|
|
242
251
|
return createReactiveComponent(component, true);
|
|
243
252
|
}
|
|
244
|
-
function reactive(component, bindKeys) {
|
|
245
|
-
return createReactiveComponent(component, false, true, bindKeys);
|
|
253
|
+
function reactive(component, keys, bindKeys) {
|
|
254
|
+
return createReactiveComponent(component, false, true, keys, bindKeys);
|
|
246
255
|
}
|
|
247
|
-
function reactiveObserver(component, bindKeys) {
|
|
248
|
-
return createReactiveComponent(component, true, true, bindKeys);
|
|
256
|
+
function reactiveObserver(component, keys, bindKeys) {
|
|
257
|
+
return createReactiveComponent(component, true, true, keys, bindKeys);
|
|
249
258
|
}
|
|
250
259
|
function reactiveComponents(components) {
|
|
251
260
|
return new Proxy(
|
|
@@ -336,7 +345,10 @@ function For({
|
|
|
336
345
|
}
|
|
337
346
|
return out;
|
|
338
347
|
}
|
|
339
|
-
var Memo = React.memo(
|
|
348
|
+
var Memo = React.memo(
|
|
349
|
+
Computed,
|
|
350
|
+
(prev, next) => next.scoped ? prev.children === next.children : true
|
|
351
|
+
);
|
|
340
352
|
|
|
341
353
|
// src/react/configureReactive.ts
|
|
342
354
|
var ReactiveFns = /* @__PURE__ */ new Map();
|
|
@@ -371,7 +383,7 @@ var Reactive = new Proxy(
|
|
|
371
383
|
}
|
|
372
384
|
return React.createElement(Component, propsOut);
|
|
373
385
|
});
|
|
374
|
-
target[p] = reactive(render, ReactiveFnBinders.get(p));
|
|
386
|
+
target[p] = reactive(render, [], ReactiveFnBinders.get(p));
|
|
375
387
|
}
|
|
376
388
|
return target[p];
|
|
377
389
|
}
|
|
@@ -399,38 +411,6 @@ function Switch({
|
|
|
399
411
|
const child = children[useSelector(value)];
|
|
400
412
|
return (_b = child ? child() : (_a = children["default"]) == null ? void 0 : _a.call(children)) != null ? _b : null;
|
|
401
413
|
}
|
|
402
|
-
function useObservable(initialValue, deps) {
|
|
403
|
-
var _a;
|
|
404
|
-
const ref = React.useRef({});
|
|
405
|
-
ref.current.value = initialValue;
|
|
406
|
-
const depsObs$ = deps ? useObservable(deps) : void 0;
|
|
407
|
-
if (!((_a = ref.current) == null ? void 0 : _a.obs$)) {
|
|
408
|
-
const value = depsObs$ ? state.isFunction(initialValue) && initialValue.length === 1 ? (p) => {
|
|
409
|
-
depsObs$.get();
|
|
410
|
-
return ref.current.value(p);
|
|
411
|
-
} : () => {
|
|
412
|
-
depsObs$.get();
|
|
413
|
-
return state.computeSelector(ref.current.value);
|
|
414
|
-
} : initialValue;
|
|
415
|
-
ref.current.obs$ = state.observable(value);
|
|
416
|
-
}
|
|
417
|
-
if (depsObs$) {
|
|
418
|
-
depsObs$.set(deps);
|
|
419
|
-
}
|
|
420
|
-
return ref.current.obs$;
|
|
421
|
-
}
|
|
422
|
-
|
|
423
|
-
// src/react/useComputed.ts
|
|
424
|
-
function useComputed(get, set, deps) {
|
|
425
|
-
if (!deps && state.isArray(set)) {
|
|
426
|
-
deps = set;
|
|
427
|
-
set = void 0;
|
|
428
|
-
}
|
|
429
|
-
return useObservable(
|
|
430
|
-
set ? state.linked({ get, set: ({ value }) => set(value) }) : get,
|
|
431
|
-
deps
|
|
432
|
-
);
|
|
433
|
-
}
|
|
434
414
|
var useEffectOnce = (effect, deps) => {
|
|
435
415
|
if (process.env.NODE_ENV === "development" || process.env.NODE_ENV === "test") {
|
|
436
416
|
const refDispose = React.useRef({ num: 0 });
|
|
@@ -459,6 +439,8 @@ var useEffectOnce = (effect, deps) => {
|
|
|
459
439
|
React.useEffect(effect, deps);
|
|
460
440
|
}
|
|
461
441
|
};
|
|
442
|
+
|
|
443
|
+
// src/react/useMount.ts
|
|
462
444
|
function useMount(fn) {
|
|
463
445
|
return useEffectOnce(() => {
|
|
464
446
|
const ret = fn();
|
|
@@ -469,6 +451,54 @@ function useMount(fn) {
|
|
|
469
451
|
}
|
|
470
452
|
var useMountOnce = useMount;
|
|
471
453
|
|
|
454
|
+
// src/react/useUnmount.ts
|
|
455
|
+
function useUnmount(fn) {
|
|
456
|
+
return useMount(() => fn);
|
|
457
|
+
}
|
|
458
|
+
var useUnmountOnce = useUnmount;
|
|
459
|
+
|
|
460
|
+
// src/react/useObservable.ts
|
|
461
|
+
var { deactivateNode } = state.internal;
|
|
462
|
+
function useObservable(initialValue, deps) {
|
|
463
|
+
var _a;
|
|
464
|
+
const ref = React.useRef({});
|
|
465
|
+
ref.current.value = initialValue;
|
|
466
|
+
const depsObs$ = deps ? useObservable(deps) : void 0;
|
|
467
|
+
if (!((_a = ref.current) == null ? void 0 : _a.obs$)) {
|
|
468
|
+
const value = depsObs$ ? state.isFunction(initialValue) && initialValue.length === 1 ? (p) => {
|
|
469
|
+
depsObs$.get();
|
|
470
|
+
return ref.current.value(p);
|
|
471
|
+
} : () => {
|
|
472
|
+
depsObs$.get();
|
|
473
|
+
return state.computeSelector(ref.current.value);
|
|
474
|
+
} : initialValue;
|
|
475
|
+
ref.current.obs$ = state.observable(value);
|
|
476
|
+
}
|
|
477
|
+
if (depsObs$) {
|
|
478
|
+
depsObs$.set(deps);
|
|
479
|
+
}
|
|
480
|
+
useUnmount(() => {
|
|
481
|
+
const obs = ref.current.obs$;
|
|
482
|
+
if (obs) {
|
|
483
|
+
const node = state.getNode(obs);
|
|
484
|
+
deactivateNode(node);
|
|
485
|
+
}
|
|
486
|
+
});
|
|
487
|
+
return ref.current.obs$;
|
|
488
|
+
}
|
|
489
|
+
|
|
490
|
+
// src/react/useComputed.ts
|
|
491
|
+
function useComputed(get, set, deps) {
|
|
492
|
+
if (!deps && state.isArray(set)) {
|
|
493
|
+
deps = set;
|
|
494
|
+
set = void 0;
|
|
495
|
+
}
|
|
496
|
+
return useObservable(
|
|
497
|
+
set ? state.linked({ get, set: ({ value }) => set(value) }) : get,
|
|
498
|
+
deps
|
|
499
|
+
);
|
|
500
|
+
}
|
|
501
|
+
|
|
472
502
|
// src/react/useIsMounted.ts
|
|
473
503
|
function useIsMounted() {
|
|
474
504
|
const obs = useObservable(false);
|
|
@@ -488,14 +518,6 @@ function useObservableReducer(reducer, initializerArg, initializer) {
|
|
|
488
518
|
};
|
|
489
519
|
return [obs, dispatch];
|
|
490
520
|
}
|
|
491
|
-
|
|
492
|
-
// src/react/useUnmount.ts
|
|
493
|
-
function useUnmount(fn) {
|
|
494
|
-
return useMount(() => fn);
|
|
495
|
-
}
|
|
496
|
-
var useUnmountOnce = useUnmount;
|
|
497
|
-
|
|
498
|
-
// src/react/useObserve.ts
|
|
499
521
|
function useObserve(selector, reactionOrOptions, options) {
|
|
500
522
|
let reaction;
|
|
501
523
|
if (state.isFunction(reactionOrOptions)) {
|
|
@@ -516,7 +538,7 @@ function useObserve(selector, reactionOrOptions, options) {
|
|
|
516
538
|
ref.current.reaction = reaction;
|
|
517
539
|
if (!ref.current.dispose) {
|
|
518
540
|
ref.current.dispose = state.observe(
|
|
519
|
-
(e) => state.computeSelector(ref.current.selector, e),
|
|
541
|
+
(e) => state.computeSelector(ref.current.selector, void 0, e),
|
|
520
542
|
(e) => {
|
|
521
543
|
var _a, _b;
|
|
522
544
|
return (_b = (_a = ref.current).reaction) == null ? void 0 : _b.call(_a, e);
|
|
@@ -578,6 +600,7 @@ exports.observer = observer;
|
|
|
578
600
|
exports.reactive = reactive;
|
|
579
601
|
exports.reactiveComponents = reactiveComponents;
|
|
580
602
|
exports.reactiveObserver = reactiveObserver;
|
|
603
|
+
exports.use$ = useSelector;
|
|
581
604
|
exports.useComputed = useComputed;
|
|
582
605
|
exports.useEffectOnce = useEffectOnce;
|
|
583
606
|
exports.useIsMounted = useIsMounted;
|
package/react.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { isFunction, isEmpty, observable,
|
|
1
|
+
import { isFunction, isEmpty, observable, computeSelector, isArray, isMap, isObservableValueReady, isPromise, getNode as getNode$1, linked, observe, when, whenReady, internal, trackSelector, isPrimitive, isObservable } from '@legendapp/state';
|
|
2
2
|
import React, { memo, forwardRef, createElement, useState, useContext, useMemo, useRef, useEffect, createContext, useCallback } from 'react';
|
|
3
3
|
import { useSyncExternalStore } from 'use-sync-external-store/shim/index.js';
|
|
4
4
|
import { enableReactive } from '@legendapp/state/react-reactive/enableReactive';
|
|
@@ -39,6 +39,7 @@ function createSelectorFunctions(options, isPaused$) {
|
|
|
39
39
|
} = trackSelector(
|
|
40
40
|
_selector,
|
|
41
41
|
_update,
|
|
42
|
+
options,
|
|
42
43
|
void 0,
|
|
43
44
|
void 0,
|
|
44
45
|
/*createResubscribe*/
|
|
@@ -94,12 +95,24 @@ function createSelectorFunctions(options, isPaused$) {
|
|
|
94
95
|
}
|
|
95
96
|
};
|
|
96
97
|
}
|
|
98
|
+
function doSuspense(selector) {
|
|
99
|
+
const vProm = when(selector);
|
|
100
|
+
if (React.use) {
|
|
101
|
+
React.use(vProm);
|
|
102
|
+
} else {
|
|
103
|
+
throw vProm;
|
|
104
|
+
}
|
|
105
|
+
}
|
|
97
106
|
function useSelector(selector, options) {
|
|
98
107
|
var _a;
|
|
108
|
+
let value;
|
|
99
109
|
if (reactGlobals.inObserver && isObservable(selector) && !(options == null ? void 0 : options.suspense)) {
|
|
100
|
-
|
|
110
|
+
value = computeSelector(selector, options);
|
|
111
|
+
if ((options == null ? void 0 : options.suspense) && value === void 0) {
|
|
112
|
+
doSuspense(selector);
|
|
113
|
+
}
|
|
114
|
+
return value;
|
|
101
115
|
}
|
|
102
|
-
let value;
|
|
103
116
|
try {
|
|
104
117
|
const isPaused$ = useContext(getPauseContext());
|
|
105
118
|
const selectorFn = useMemo(() => createSelectorFunctions(options, isPaused$), []);
|
|
@@ -114,16 +127,8 @@ function useSelector(selector, options) {
|
|
|
114
127
|
}
|
|
115
128
|
throw err;
|
|
116
129
|
}
|
|
117
|
-
if (options == null ? void 0 : options.suspense) {
|
|
118
|
-
|
|
119
|
-
if (isPromise(value) || !value && isObservable(selector)) {
|
|
120
|
-
const vProm = isProm ? value : when(selector);
|
|
121
|
-
if (React.use) {
|
|
122
|
-
React.use(vProm);
|
|
123
|
-
} else {
|
|
124
|
-
throw vProm;
|
|
125
|
-
}
|
|
126
|
-
}
|
|
130
|
+
if ((options == null ? void 0 : options.suspense) && value === void 0) {
|
|
131
|
+
doSuspense(selector);
|
|
127
132
|
}
|
|
128
133
|
return value;
|
|
129
134
|
}
|
|
@@ -134,7 +139,7 @@ function Computed({ children }) {
|
|
|
134
139
|
}
|
|
135
140
|
var hasSymbol = typeof Symbol === "function" && Symbol.for;
|
|
136
141
|
var didWarnProps = false;
|
|
137
|
-
function createReactiveComponent(component, observe3, reactive2, bindKeys) {
|
|
142
|
+
function createReactiveComponent(component, observe3, reactive2, keysReactive, bindKeys) {
|
|
138
143
|
const ReactForwardRefSymbol = hasSymbol ? Symbol.for("react.forward_ref") : (
|
|
139
144
|
// eslint-disable-next-line react/display-name, @typescript-eslint/no-unused-vars
|
|
140
145
|
typeof forwardRef === "function" && forwardRef((props) => null)["$$typeof"]
|
|
@@ -159,6 +164,7 @@ function createReactiveComponent(component, observe3, reactive2, bindKeys) {
|
|
|
159
164
|
throw new Error(`[legend-state] \`render\` property of ForwardRef was not a function`);
|
|
160
165
|
}
|
|
161
166
|
}
|
|
167
|
+
const keysReactiveSet = keysReactive ? new Set(keysReactive) : void 0;
|
|
162
168
|
const proxyHandler = {
|
|
163
169
|
apply(target, thisArg, argArray) {
|
|
164
170
|
if (reactive2) {
|
|
@@ -168,9 +174,10 @@ function createReactiveComponent(component, observe3, reactive2, bindKeys) {
|
|
|
168
174
|
for (let i = 0; i < keys.length; i++) {
|
|
169
175
|
const key = keys[i];
|
|
170
176
|
const p = props[key];
|
|
177
|
+
const isReactiveKey = keysReactiveSet && keysReactiveSet.has(key);
|
|
171
178
|
if (key === "children" && (isFunction(p) || isObservable(p))) {
|
|
172
179
|
props[key] = useSelector(p, { skipCheck: true });
|
|
173
|
-
} else if (key.startsWith("$") || key.endsWith("$")) {
|
|
180
|
+
} else if (isReactiveKey || key.startsWith("$") || key.endsWith("$")) {
|
|
174
181
|
if (process.env.NODE_ENV === "development" && !didWarnProps && key.endsWith("$")) {
|
|
175
182
|
didWarnProps = true;
|
|
176
183
|
console.warn(
|
|
@@ -180,7 +187,7 @@ function createReactiveComponent(component, observe3, reactive2, bindKeys) {
|
|
|
180
187
|
)}. See https://legendapp.com/open-source/state/migrating for more details.`
|
|
181
188
|
);
|
|
182
189
|
}
|
|
183
|
-
const k = key.endsWith("$") ? key.slice(0, -1) : key.slice(1);
|
|
190
|
+
const k = isReactiveKey ? key : key.endsWith("$") ? key.slice(0, -1) : key.slice(1);
|
|
184
191
|
const bind = bindKeys == null ? void 0 : bindKeys[k];
|
|
185
192
|
const shouldBind = bind && isObservable(p);
|
|
186
193
|
propsOut[k] = shouldBind && (bind == null ? void 0 : bind.selector) ? bind.selector(propsOut, p) : useSelector(p);
|
|
@@ -198,7 +205,9 @@ function createReactiveComponent(component, observe3, reactive2, bindKeys) {
|
|
|
198
205
|
process.env.NODE_ENV === "development" ? handlerFn : useCallback(handlerFn, [props[bind.handler], bindKeys]);
|
|
199
206
|
}
|
|
200
207
|
}
|
|
201
|
-
|
|
208
|
+
if (!isReactiveKey) {
|
|
209
|
+
delete propsOut[key];
|
|
210
|
+
}
|
|
202
211
|
} else if (propsOut[key] === void 0) {
|
|
203
212
|
propsOut[key] = p;
|
|
204
213
|
}
|
|
@@ -235,11 +244,11 @@ function createReactiveComponent(component, observe3, reactive2, bindKeys) {
|
|
|
235
244
|
function observer(component) {
|
|
236
245
|
return createReactiveComponent(component, true);
|
|
237
246
|
}
|
|
238
|
-
function reactive(component, bindKeys) {
|
|
239
|
-
return createReactiveComponent(component, false, true, bindKeys);
|
|
247
|
+
function reactive(component, keys, bindKeys) {
|
|
248
|
+
return createReactiveComponent(component, false, true, keys, bindKeys);
|
|
240
249
|
}
|
|
241
|
-
function reactiveObserver(component, bindKeys) {
|
|
242
|
-
return createReactiveComponent(component, true, true, bindKeys);
|
|
250
|
+
function reactiveObserver(component, keys, bindKeys) {
|
|
251
|
+
return createReactiveComponent(component, true, true, keys, bindKeys);
|
|
243
252
|
}
|
|
244
253
|
function reactiveComponents(components) {
|
|
245
254
|
return new Proxy(
|
|
@@ -330,7 +339,10 @@ function For({
|
|
|
330
339
|
}
|
|
331
340
|
return out;
|
|
332
341
|
}
|
|
333
|
-
var Memo = memo(
|
|
342
|
+
var Memo = memo(
|
|
343
|
+
Computed,
|
|
344
|
+
(prev, next) => next.scoped ? prev.children === next.children : true
|
|
345
|
+
);
|
|
334
346
|
|
|
335
347
|
// src/react/configureReactive.ts
|
|
336
348
|
var ReactiveFns = /* @__PURE__ */ new Map();
|
|
@@ -365,7 +377,7 @@ var Reactive = new Proxy(
|
|
|
365
377
|
}
|
|
366
378
|
return createElement(Component, propsOut);
|
|
367
379
|
});
|
|
368
|
-
target[p] = reactive(render, ReactiveFnBinders.get(p));
|
|
380
|
+
target[p] = reactive(render, [], ReactiveFnBinders.get(p));
|
|
369
381
|
}
|
|
370
382
|
return target[p];
|
|
371
383
|
}
|
|
@@ -393,38 +405,6 @@ function Switch({
|
|
|
393
405
|
const child = children[useSelector(value)];
|
|
394
406
|
return (_b = child ? child() : (_a = children["default"]) == null ? void 0 : _a.call(children)) != null ? _b : null;
|
|
395
407
|
}
|
|
396
|
-
function useObservable(initialValue, deps) {
|
|
397
|
-
var _a;
|
|
398
|
-
const ref = useRef({});
|
|
399
|
-
ref.current.value = initialValue;
|
|
400
|
-
const depsObs$ = deps ? useObservable(deps) : void 0;
|
|
401
|
-
if (!((_a = ref.current) == null ? void 0 : _a.obs$)) {
|
|
402
|
-
const value = depsObs$ ? isFunction(initialValue) && initialValue.length === 1 ? (p) => {
|
|
403
|
-
depsObs$.get();
|
|
404
|
-
return ref.current.value(p);
|
|
405
|
-
} : () => {
|
|
406
|
-
depsObs$.get();
|
|
407
|
-
return computeSelector(ref.current.value);
|
|
408
|
-
} : initialValue;
|
|
409
|
-
ref.current.obs$ = observable(value);
|
|
410
|
-
}
|
|
411
|
-
if (depsObs$) {
|
|
412
|
-
depsObs$.set(deps);
|
|
413
|
-
}
|
|
414
|
-
return ref.current.obs$;
|
|
415
|
-
}
|
|
416
|
-
|
|
417
|
-
// src/react/useComputed.ts
|
|
418
|
-
function useComputed(get, set, deps) {
|
|
419
|
-
if (!deps && isArray(set)) {
|
|
420
|
-
deps = set;
|
|
421
|
-
set = void 0;
|
|
422
|
-
}
|
|
423
|
-
return useObservable(
|
|
424
|
-
set ? linked({ get, set: ({ value }) => set(value) }) : get,
|
|
425
|
-
deps
|
|
426
|
-
);
|
|
427
|
-
}
|
|
428
408
|
var useEffectOnce = (effect, deps) => {
|
|
429
409
|
if (process.env.NODE_ENV === "development" || process.env.NODE_ENV === "test") {
|
|
430
410
|
const refDispose = useRef({ num: 0 });
|
|
@@ -453,6 +433,8 @@ var useEffectOnce = (effect, deps) => {
|
|
|
453
433
|
useEffect(effect, deps);
|
|
454
434
|
}
|
|
455
435
|
};
|
|
436
|
+
|
|
437
|
+
// src/react/useMount.ts
|
|
456
438
|
function useMount(fn) {
|
|
457
439
|
return useEffectOnce(() => {
|
|
458
440
|
const ret = fn();
|
|
@@ -463,6 +445,54 @@ function useMount(fn) {
|
|
|
463
445
|
}
|
|
464
446
|
var useMountOnce = useMount;
|
|
465
447
|
|
|
448
|
+
// src/react/useUnmount.ts
|
|
449
|
+
function useUnmount(fn) {
|
|
450
|
+
return useMount(() => fn);
|
|
451
|
+
}
|
|
452
|
+
var useUnmountOnce = useUnmount;
|
|
453
|
+
|
|
454
|
+
// src/react/useObservable.ts
|
|
455
|
+
var { deactivateNode } = internal;
|
|
456
|
+
function useObservable(initialValue, deps) {
|
|
457
|
+
var _a;
|
|
458
|
+
const ref = useRef({});
|
|
459
|
+
ref.current.value = initialValue;
|
|
460
|
+
const depsObs$ = deps ? useObservable(deps) : void 0;
|
|
461
|
+
if (!((_a = ref.current) == null ? void 0 : _a.obs$)) {
|
|
462
|
+
const value = depsObs$ ? isFunction(initialValue) && initialValue.length === 1 ? (p) => {
|
|
463
|
+
depsObs$.get();
|
|
464
|
+
return ref.current.value(p);
|
|
465
|
+
} : () => {
|
|
466
|
+
depsObs$.get();
|
|
467
|
+
return computeSelector(ref.current.value);
|
|
468
|
+
} : initialValue;
|
|
469
|
+
ref.current.obs$ = observable(value);
|
|
470
|
+
}
|
|
471
|
+
if (depsObs$) {
|
|
472
|
+
depsObs$.set(deps);
|
|
473
|
+
}
|
|
474
|
+
useUnmount(() => {
|
|
475
|
+
const obs = ref.current.obs$;
|
|
476
|
+
if (obs) {
|
|
477
|
+
const node = getNode$1(obs);
|
|
478
|
+
deactivateNode(node);
|
|
479
|
+
}
|
|
480
|
+
});
|
|
481
|
+
return ref.current.obs$;
|
|
482
|
+
}
|
|
483
|
+
|
|
484
|
+
// src/react/useComputed.ts
|
|
485
|
+
function useComputed(get, set, deps) {
|
|
486
|
+
if (!deps && isArray(set)) {
|
|
487
|
+
deps = set;
|
|
488
|
+
set = void 0;
|
|
489
|
+
}
|
|
490
|
+
return useObservable(
|
|
491
|
+
set ? linked({ get, set: ({ value }) => set(value) }) : get,
|
|
492
|
+
deps
|
|
493
|
+
);
|
|
494
|
+
}
|
|
495
|
+
|
|
466
496
|
// src/react/useIsMounted.ts
|
|
467
497
|
function useIsMounted() {
|
|
468
498
|
const obs = useObservable(false);
|
|
@@ -482,14 +512,6 @@ function useObservableReducer(reducer, initializerArg, initializer) {
|
|
|
482
512
|
};
|
|
483
513
|
return [obs, dispatch];
|
|
484
514
|
}
|
|
485
|
-
|
|
486
|
-
// src/react/useUnmount.ts
|
|
487
|
-
function useUnmount(fn) {
|
|
488
|
-
return useMount(() => fn);
|
|
489
|
-
}
|
|
490
|
-
var useUnmountOnce = useUnmount;
|
|
491
|
-
|
|
492
|
-
// src/react/useObserve.ts
|
|
493
515
|
function useObserve(selector, reactionOrOptions, options) {
|
|
494
516
|
let reaction;
|
|
495
517
|
if (isFunction(reactionOrOptions)) {
|
|
@@ -510,7 +532,7 @@ function useObserve(selector, reactionOrOptions, options) {
|
|
|
510
532
|
ref.current.reaction = reaction;
|
|
511
533
|
if (!ref.current.dispose) {
|
|
512
534
|
ref.current.dispose = observe(
|
|
513
|
-
(e) => computeSelector(ref.current.selector, e),
|
|
535
|
+
(e) => computeSelector(ref.current.selector, void 0, e),
|
|
514
536
|
(e) => {
|
|
515
537
|
var _a, _b;
|
|
516
538
|
return (_b = (_a = ref.current).reaction) == null ? void 0 : _b.call(_a, e);
|
|
@@ -560,4 +582,4 @@ function useWhenReady(predicate, effect) {
|
|
|
560
582
|
return useMemo(() => whenReady(predicate, effect), []);
|
|
561
583
|
}
|
|
562
584
|
|
|
563
|
-
export { Computed, For, Memo, Reactive, Show, Switch, configureReactive, hasSymbol, observer, reactive, reactiveComponents, reactiveObserver, useComputed, useEffectOnce, useIsMounted, useMount, useMountOnce, useObservable, useObservableReducer, useObserve, useObserveEffect, usePauseProvider, useSelector, useUnmount, useUnmountOnce, useWhen, useWhenReady };
|
|
585
|
+
export { Computed, For, Memo, Reactive, Show, Switch, configureReactive, hasSymbol, observer, reactive, reactiveComponents, reactiveObserver, useSelector as use$, useComputed, useEffectOnce, useIsMounted, useMount, useMountOnce, useObservable, useObservableReducer, useObserve, useObserveEffect, usePauseProvider, useSelector, useUnmount, useUnmountOnce, useWhen, useWhenReady };
|
package/sync-plugins/crud.d.mts
CHANGED
|
@@ -1,17 +1,25 @@
|
|
|
1
1
|
import { WaitForSetFnParams, ObservableParam, ObservableEvent } from '@legendapp/state';
|
|
2
|
-
import { SyncedGetParams, SyncedOptions, SyncedSetParams, SyncedSubscribeParams } from '@legendapp/state/sync';
|
|
2
|
+
import { SyncedGetParams, SyncedErrorParams, SyncedOptions, SyncedSetParams, SyncedSubscribeParams } from '@legendapp/state/sync';
|
|
3
3
|
|
|
4
4
|
type CrudAsOption = 'Map' | 'object' | 'value' | 'array';
|
|
5
5
|
type CrudResult<T> = T;
|
|
6
|
+
interface SyncedCrudPropsNoRead<TLocal, TAsOption extends CrudAsOption> {
|
|
7
|
+
get?: never | undefined;
|
|
8
|
+
list?: never | undefined;
|
|
9
|
+
initial?: InitialValue<TLocal, TAsOption>;
|
|
10
|
+
as?: TAsOption;
|
|
11
|
+
}
|
|
6
12
|
interface SyncedCrudPropsSingle<TRemote extends object, TLocal> {
|
|
7
|
-
get
|
|
8
|
-
|
|
13
|
+
get: (params: SyncedGetParams<TRemote>) => Promise<CrudResult<TRemote | null>> | CrudResult<TRemote | null>;
|
|
14
|
+
list?: never | undefined;
|
|
15
|
+
initial?: InitialValue<Partial<NoInfer<TLocal>>, 'value'>;
|
|
9
16
|
as?: never | 'value';
|
|
10
17
|
}
|
|
11
18
|
interface SyncedCrudPropsMany<TRemote extends object, TLocal, TAsOption extends CrudAsOption> {
|
|
12
|
-
list
|
|
19
|
+
list: (params: SyncedGetParams<TRemote>) => Promise<CrudResult<TRemote[] | null>> | CrudResult<TRemote[] | null>;
|
|
20
|
+
get?: never | undefined;
|
|
13
21
|
as?: TAsOption;
|
|
14
|
-
initial?: InitialValue<TLocal
|
|
22
|
+
initial?: InitialValue<Partial<NoInfer<TLocal>>, TAsOption>;
|
|
15
23
|
}
|
|
16
24
|
interface SyncedCrudOnSavedParams<TRemote extends object, TLocal> {
|
|
17
25
|
saved: TLocal;
|
|
@@ -23,7 +31,11 @@ interface SyncedCrudOnSavedParams<TRemote extends object, TLocal> {
|
|
|
23
31
|
interface WaitForSetCrudFnParams<T> extends WaitForSetFnParams<T> {
|
|
24
32
|
type: 'create' | 'update' | 'delete';
|
|
25
33
|
}
|
|
26
|
-
interface
|
|
34
|
+
interface CrudErrorParams extends Omit<SyncedErrorParams, 'source'> {
|
|
35
|
+
source: 'list' | 'get' | 'create' | 'update' | 'delete' | 'unknown';
|
|
36
|
+
}
|
|
37
|
+
type CrudOnErrorFn = (error: Error, params: CrudErrorParams) => void;
|
|
38
|
+
interface SyncedCrudPropsBase<TRemote extends object, TLocal = TRemote> extends Omit<SyncedOptions<TRemote, TLocal>, 'get' | 'set' | 'initial' | 'subscribe' | 'waitForSet' | 'onError'> {
|
|
27
39
|
create?(input: TRemote, params: SyncedSetParams<TRemote>): Promise<CrudResult<TRemote> | null | undefined | void>;
|
|
28
40
|
update?(input: Partial<TRemote>, params: SyncedSetParams<TRemote>): Promise<CrudResult<Partial<TRemote> | null | undefined | void>>;
|
|
29
41
|
delete?(input: TRemote, params: SyncedSetParams<TRemote>): Promise<any>;
|
|
@@ -38,6 +50,7 @@ interface SyncedCrudPropsBase<TRemote extends object, TLocal = TRemote> extends
|
|
|
38
50
|
generateId?: () => string | number;
|
|
39
51
|
subscribe?: (params: SyncedSubscribeParams<TRemote[]>) => (() => void) | void;
|
|
40
52
|
waitForSet?: ((params: WaitForSetCrudFnParams<TLocal>) => any) | Promise<any> | ObservableParam<any> | ObservableEvent;
|
|
53
|
+
onError?: (error: Error, params: CrudErrorParams) => void;
|
|
41
54
|
}
|
|
42
55
|
type InitialValue<TLocal, TAsOption extends CrudAsOption> = TAsOption extends 'Map' ? Map<string | number, TLocal> : TAsOption extends 'object' ? Record<string | number, TLocal> : TAsOption extends 'value' ? TLocal : TLocal[];
|
|
43
56
|
type SyncedCrudReturnType<TLocal, TAsOption extends CrudAsOption> = TAsOption extends 'Map' ? Map<TLocal extends {
|
|
@@ -45,7 +58,9 @@ type SyncedCrudReturnType<TLocal, TAsOption extends CrudAsOption> = TAsOption ex
|
|
|
45
58
|
} ? number : string, TLocal> : TAsOption extends 'object' ? Record<TLocal extends {
|
|
46
59
|
id: number;
|
|
47
60
|
} ? number : string, TLocal> : TAsOption extends 'value' ? TLocal : TLocal[];
|
|
48
|
-
declare function syncedCrud<TRemote extends object, TLocal = TRemote>(props:
|
|
49
|
-
declare function syncedCrud<TRemote extends object, TLocal = TRemote
|
|
61
|
+
declare function syncedCrud<TRemote extends object, TLocal = TRemote, TAsOption extends CrudAsOption = 'object'>(props: SyncedCrudPropsNoRead<TRemote, TAsOption> & SyncedCrudPropsBase<TRemote, TLocal>): SyncedCrudReturnType<TLocal, TAsOption>;
|
|
62
|
+
declare function syncedCrud<TRemote extends object, TLocal = TRemote>(props: SyncedCrudPropsSingle<TRemote, TLocal> & SyncedCrudPropsBase<TRemote, TLocal>): SyncedCrudReturnType<TLocal, 'value'>;
|
|
63
|
+
declare function syncedCrud<TRemote extends object, TLocal = TRemote, TAsOption extends CrudAsOption = 'object'>(props: SyncedCrudPropsMany<TRemote, TLocal, TAsOption> & SyncedCrudPropsBase<TRemote, TLocal>): SyncedCrudReturnType<TLocal, Exclude<TAsOption, 'value'>>;
|
|
64
|
+
declare function syncedCrud<TRemote extends object, TLocal = TRemote, TAsOption extends CrudAsOption = 'object'>(props: (SyncedCrudPropsSingle<TRemote, TLocal> | SyncedCrudPropsMany<TRemote, TLocal, TAsOption>) & SyncedCrudPropsBase<TRemote, TLocal>): SyncedCrudReturnType<TLocal, TAsOption>;
|
|
50
65
|
|
|
51
|
-
export { type CrudAsOption, type CrudResult, type SyncedCrudOnSavedParams, type SyncedCrudPropsBase, type SyncedCrudPropsMany, type SyncedCrudPropsSingle, type SyncedCrudReturnType, type WaitForSetCrudFnParams, syncedCrud };
|
|
66
|
+
export { type CrudAsOption, type CrudErrorParams, type CrudOnErrorFn, type CrudResult, type SyncedCrudOnSavedParams, type SyncedCrudPropsBase, type SyncedCrudPropsMany, type SyncedCrudPropsNoRead, type SyncedCrudPropsSingle, type SyncedCrudReturnType, type WaitForSetCrudFnParams, syncedCrud };
|
package/sync-plugins/crud.d.ts
CHANGED
|
@@ -1,17 +1,25 @@
|
|
|
1
1
|
import { WaitForSetFnParams, ObservableParam, ObservableEvent } from '@legendapp/state';
|
|
2
|
-
import { SyncedGetParams, SyncedOptions, SyncedSetParams, SyncedSubscribeParams } from '@legendapp/state/sync';
|
|
2
|
+
import { SyncedGetParams, SyncedErrorParams, SyncedOptions, SyncedSetParams, SyncedSubscribeParams } from '@legendapp/state/sync';
|
|
3
3
|
|
|
4
4
|
type CrudAsOption = 'Map' | 'object' | 'value' | 'array';
|
|
5
5
|
type CrudResult<T> = T;
|
|
6
|
+
interface SyncedCrudPropsNoRead<TLocal, TAsOption extends CrudAsOption> {
|
|
7
|
+
get?: never | undefined;
|
|
8
|
+
list?: never | undefined;
|
|
9
|
+
initial?: InitialValue<TLocal, TAsOption>;
|
|
10
|
+
as?: TAsOption;
|
|
11
|
+
}
|
|
6
12
|
interface SyncedCrudPropsSingle<TRemote extends object, TLocal> {
|
|
7
|
-
get
|
|
8
|
-
|
|
13
|
+
get: (params: SyncedGetParams<TRemote>) => Promise<CrudResult<TRemote | null>> | CrudResult<TRemote | null>;
|
|
14
|
+
list?: never | undefined;
|
|
15
|
+
initial?: InitialValue<Partial<NoInfer<TLocal>>, 'value'>;
|
|
9
16
|
as?: never | 'value';
|
|
10
17
|
}
|
|
11
18
|
interface SyncedCrudPropsMany<TRemote extends object, TLocal, TAsOption extends CrudAsOption> {
|
|
12
|
-
list
|
|
19
|
+
list: (params: SyncedGetParams<TRemote>) => Promise<CrudResult<TRemote[] | null>> | CrudResult<TRemote[] | null>;
|
|
20
|
+
get?: never | undefined;
|
|
13
21
|
as?: TAsOption;
|
|
14
|
-
initial?: InitialValue<TLocal
|
|
22
|
+
initial?: InitialValue<Partial<NoInfer<TLocal>>, TAsOption>;
|
|
15
23
|
}
|
|
16
24
|
interface SyncedCrudOnSavedParams<TRemote extends object, TLocal> {
|
|
17
25
|
saved: TLocal;
|
|
@@ -23,7 +31,11 @@ interface SyncedCrudOnSavedParams<TRemote extends object, TLocal> {
|
|
|
23
31
|
interface WaitForSetCrudFnParams<T> extends WaitForSetFnParams<T> {
|
|
24
32
|
type: 'create' | 'update' | 'delete';
|
|
25
33
|
}
|
|
26
|
-
interface
|
|
34
|
+
interface CrudErrorParams extends Omit<SyncedErrorParams, 'source'> {
|
|
35
|
+
source: 'list' | 'get' | 'create' | 'update' | 'delete' | 'unknown';
|
|
36
|
+
}
|
|
37
|
+
type CrudOnErrorFn = (error: Error, params: CrudErrorParams) => void;
|
|
38
|
+
interface SyncedCrudPropsBase<TRemote extends object, TLocal = TRemote> extends Omit<SyncedOptions<TRemote, TLocal>, 'get' | 'set' | 'initial' | 'subscribe' | 'waitForSet' | 'onError'> {
|
|
27
39
|
create?(input: TRemote, params: SyncedSetParams<TRemote>): Promise<CrudResult<TRemote> | null | undefined | void>;
|
|
28
40
|
update?(input: Partial<TRemote>, params: SyncedSetParams<TRemote>): Promise<CrudResult<Partial<TRemote> | null | undefined | void>>;
|
|
29
41
|
delete?(input: TRemote, params: SyncedSetParams<TRemote>): Promise<any>;
|
|
@@ -38,6 +50,7 @@ interface SyncedCrudPropsBase<TRemote extends object, TLocal = TRemote> extends
|
|
|
38
50
|
generateId?: () => string | number;
|
|
39
51
|
subscribe?: (params: SyncedSubscribeParams<TRemote[]>) => (() => void) | void;
|
|
40
52
|
waitForSet?: ((params: WaitForSetCrudFnParams<TLocal>) => any) | Promise<any> | ObservableParam<any> | ObservableEvent;
|
|
53
|
+
onError?: (error: Error, params: CrudErrorParams) => void;
|
|
41
54
|
}
|
|
42
55
|
type InitialValue<TLocal, TAsOption extends CrudAsOption> = TAsOption extends 'Map' ? Map<string | number, TLocal> : TAsOption extends 'object' ? Record<string | number, TLocal> : TAsOption extends 'value' ? TLocal : TLocal[];
|
|
43
56
|
type SyncedCrudReturnType<TLocal, TAsOption extends CrudAsOption> = TAsOption extends 'Map' ? Map<TLocal extends {
|
|
@@ -45,7 +58,9 @@ type SyncedCrudReturnType<TLocal, TAsOption extends CrudAsOption> = TAsOption ex
|
|
|
45
58
|
} ? number : string, TLocal> : TAsOption extends 'object' ? Record<TLocal extends {
|
|
46
59
|
id: number;
|
|
47
60
|
} ? number : string, TLocal> : TAsOption extends 'value' ? TLocal : TLocal[];
|
|
48
|
-
declare function syncedCrud<TRemote extends object, TLocal = TRemote>(props:
|
|
49
|
-
declare function syncedCrud<TRemote extends object, TLocal = TRemote
|
|
61
|
+
declare function syncedCrud<TRemote extends object, TLocal = TRemote, TAsOption extends CrudAsOption = 'object'>(props: SyncedCrudPropsNoRead<TRemote, TAsOption> & SyncedCrudPropsBase<TRemote, TLocal>): SyncedCrudReturnType<TLocal, TAsOption>;
|
|
62
|
+
declare function syncedCrud<TRemote extends object, TLocal = TRemote>(props: SyncedCrudPropsSingle<TRemote, TLocal> & SyncedCrudPropsBase<TRemote, TLocal>): SyncedCrudReturnType<TLocal, 'value'>;
|
|
63
|
+
declare function syncedCrud<TRemote extends object, TLocal = TRemote, TAsOption extends CrudAsOption = 'object'>(props: SyncedCrudPropsMany<TRemote, TLocal, TAsOption> & SyncedCrudPropsBase<TRemote, TLocal>): SyncedCrudReturnType<TLocal, Exclude<TAsOption, 'value'>>;
|
|
64
|
+
declare function syncedCrud<TRemote extends object, TLocal = TRemote, TAsOption extends CrudAsOption = 'object'>(props: (SyncedCrudPropsSingle<TRemote, TLocal> | SyncedCrudPropsMany<TRemote, TLocal, TAsOption>) & SyncedCrudPropsBase<TRemote, TLocal>): SyncedCrudReturnType<TLocal, TAsOption>;
|
|
50
65
|
|
|
51
|
-
export { type CrudAsOption, type CrudResult, type SyncedCrudOnSavedParams, type SyncedCrudPropsBase, type SyncedCrudPropsMany, type SyncedCrudPropsSingle, type SyncedCrudReturnType, type WaitForSetCrudFnParams, syncedCrud };
|
|
66
|
+
export { type CrudAsOption, type CrudErrorParams, type CrudOnErrorFn, type CrudResult, type SyncedCrudOnSavedParams, type SyncedCrudPropsBase, type SyncedCrudPropsMany, type SyncedCrudPropsNoRead, type SyncedCrudPropsSingle, type SyncedCrudReturnType, type WaitForSetCrudFnParams, syncedCrud };
|