@hairy/react-lib 1.34.0 → 1.35.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/dist/index.cjs +38 -32
- package/dist/index.d.ts +12 -7
- package/dist/index.global.js +34 -27
- package/dist/index.js +35 -30
- package/package.json +2 -2
package/dist/index.cjs
CHANGED
|
@@ -40,8 +40,9 @@ __export(index_exports, {
|
|
|
40
40
|
Trigger: () => Trigger,
|
|
41
41
|
Unless: () => Unless,
|
|
42
42
|
cls: () => cls,
|
|
43
|
-
|
|
43
|
+
defienAsyncStore: () => defienAsyncStore,
|
|
44
44
|
defineStore: () => defineStore,
|
|
45
|
+
defineStoreAsync: () => defineStoreAsync,
|
|
45
46
|
proxyWithPersistant: () => proxyWithPersistant,
|
|
46
47
|
track: () => track,
|
|
47
48
|
tryUseCallback: () => tryUseCallback,
|
|
@@ -567,9 +568,6 @@ function useWhenever(source, cb, options) {
|
|
|
567
568
|
useWatch(source, () => source && cb(source), options);
|
|
568
569
|
}
|
|
569
570
|
|
|
570
|
-
// src/storage/defineAsyncStore.ts
|
|
571
|
-
var import_utils11 = require("valtio/utils");
|
|
572
|
-
|
|
573
571
|
// src/storage/defineStore.ts
|
|
574
572
|
var import_react20 = require("react");
|
|
575
573
|
var import_valtio4 = require("valtio");
|
|
@@ -596,6 +594,32 @@ function proxyWithPersistant(keyOrOptions, initialObject) {
|
|
|
596
594
|
return state;
|
|
597
595
|
}
|
|
598
596
|
|
|
597
|
+
// src/storage/utils/index.ts
|
|
598
|
+
function track2(action, status) {
|
|
599
|
+
let loadings = 0;
|
|
600
|
+
const tracking = () => loadings++ === 0 && (status.loading = true);
|
|
601
|
+
const done = () => !--loadings && (status.loading = false);
|
|
602
|
+
const fulfilled = (value) => {
|
|
603
|
+
status.finished = true;
|
|
604
|
+
done();
|
|
605
|
+
return value;
|
|
606
|
+
};
|
|
607
|
+
const rejected = (error) => {
|
|
608
|
+
status.error = error;
|
|
609
|
+
done();
|
|
610
|
+
throw error;
|
|
611
|
+
};
|
|
612
|
+
return function(...args) {
|
|
613
|
+
tracking();
|
|
614
|
+
try {
|
|
615
|
+
const value = action(...args);
|
|
616
|
+
return value instanceof Promise ? value.then(fulfilled, rejected) : fulfilled(value);
|
|
617
|
+
} catch (error) {
|
|
618
|
+
rejected(error);
|
|
619
|
+
}
|
|
620
|
+
};
|
|
621
|
+
}
|
|
622
|
+
|
|
599
623
|
// src/storage/defineStore.ts
|
|
600
624
|
function defineStore(store, options = {}) {
|
|
601
625
|
const state = typeof store.state === "function" ? store.state() : store.state;
|
|
@@ -641,34 +665,13 @@ function defineStore(store, options = {}) {
|
|
|
641
665
|
...$actions
|
|
642
666
|
};
|
|
643
667
|
}
|
|
644
|
-
function track2(action, status) {
|
|
645
|
-
let loadings = 0;
|
|
646
|
-
const tracking = () => loadings++ === 0 && (status.loading = true);
|
|
647
|
-
const done = () => !--loadings && (status.loading = false);
|
|
648
|
-
const fulfilled = (value) => {
|
|
649
|
-
status.finished = true;
|
|
650
|
-
done();
|
|
651
|
-
return value;
|
|
652
|
-
};
|
|
653
|
-
const rejected = (error) => {
|
|
654
|
-
status.error = error;
|
|
655
|
-
done();
|
|
656
|
-
throw error;
|
|
657
|
-
};
|
|
658
|
-
return function(...args) {
|
|
659
|
-
tracking();
|
|
660
|
-
try {
|
|
661
|
-
const value = action(...args);
|
|
662
|
-
return value instanceof Promise ? value.then(fulfilled, rejected) : fulfilled(value);
|
|
663
|
-
} catch (error) {
|
|
664
|
-
rejected(error);
|
|
665
|
-
}
|
|
666
|
-
};
|
|
667
|
-
}
|
|
668
668
|
function setupActions($state, actions, $actions, $status) {
|
|
669
669
|
for (const key in actions) {
|
|
670
670
|
$status[key] = { finished: false, loading: false, error: null };
|
|
671
671
|
$actions[key] = track2(actions[key].bind($state), $status[key]);
|
|
672
|
+
Object.defineProperty($state, key, {
|
|
673
|
+
get: () => $actions[key]
|
|
674
|
+
});
|
|
672
675
|
}
|
|
673
676
|
}
|
|
674
677
|
function setupGetters(state, $state, getters, $getters) {
|
|
@@ -698,8 +701,9 @@ function setupStatus($actions, $status) {
|
|
|
698
701
|
});
|
|
699
702
|
}
|
|
700
703
|
|
|
701
|
-
// src/storage/
|
|
702
|
-
|
|
704
|
+
// src/storage/defineStoreAsync.ts
|
|
705
|
+
var import_utils12 = require("valtio/utils");
|
|
706
|
+
function defineStoreAsync(fetch, options = {}) {
|
|
703
707
|
const store = defineStore(
|
|
704
708
|
{
|
|
705
709
|
state: () => ({
|
|
@@ -719,7 +723,7 @@ function defineAsyncStore(fetch, options = {}) {
|
|
|
719
723
|
},
|
|
720
724
|
{ persist: options.persist ? { id: options.persist, pick: ["value"] } : void 0 }
|
|
721
725
|
);
|
|
722
|
-
(0,
|
|
726
|
+
(0, import_utils12.watch)((get) => {
|
|
723
727
|
const status = get(store.$status.fetch);
|
|
724
728
|
store.$state.error = status.error;
|
|
725
729
|
store.$state.loading = status.loading;
|
|
@@ -728,6 +732,7 @@ function defineAsyncStore(fetch, options = {}) {
|
|
|
728
732
|
options.immediate && store.fetch();
|
|
729
733
|
return store;
|
|
730
734
|
}
|
|
735
|
+
var defienAsyncStore = defineStoreAsync;
|
|
731
736
|
|
|
732
737
|
// src/storage/useStatus.tsx
|
|
733
738
|
var import_valtio5 = require("valtio");
|
|
@@ -752,8 +757,9 @@ function useStore(store) {
|
|
|
752
757
|
Trigger,
|
|
753
758
|
Unless,
|
|
754
759
|
cls,
|
|
755
|
-
|
|
760
|
+
defienAsyncStore,
|
|
756
761
|
defineStore,
|
|
762
|
+
defineStoreAsync,
|
|
757
763
|
proxyWithPersistant,
|
|
758
764
|
track,
|
|
759
765
|
tryUseCallback,
|
package/dist/index.d.ts
CHANGED
|
@@ -249,19 +249,21 @@ interface StorePatch<S, G extends Getters<S>> {
|
|
|
249
249
|
type Store<S, A extends Actions<S>, G extends Getters<S>> = {
|
|
250
250
|
$subscribe: StoreSubscribe<S, A, G>;
|
|
251
251
|
$patch: StorePatch<S, G>;
|
|
252
|
-
$state: S & GettersReturnType<G>;
|
|
252
|
+
$state: S & GettersReturnType<G> & ActionsOmitThisParameter<A>;
|
|
253
253
|
$actions: ActionsOmitThisParameter<A>;
|
|
254
254
|
$getters: GettersReturnType<G>;
|
|
255
255
|
$status: ActionsStatus<A>;
|
|
256
256
|
$signal: StoreSignal<S, A, G>;
|
|
257
257
|
} & ActionsOmitThisParameter<A>;
|
|
258
258
|
|
|
259
|
-
|
|
259
|
+
declare function defineStore<S extends object, A extends Actions<S>, G extends Getters<S>>(store: StoreDefine<S, A, G>, options?: StoreOptions): Store<S, A, G>;
|
|
260
|
+
|
|
261
|
+
interface StoreAsyncOptions<T extends AnyFn> {
|
|
260
262
|
initial?: ReturnType<T> extends Promise<infer U> ? U : undefined;
|
|
261
263
|
persist?: string;
|
|
262
264
|
immediate?: boolean;
|
|
263
265
|
}
|
|
264
|
-
declare function
|
|
266
|
+
declare function defineStoreAsync<T extends AnyFn>(fetch: T, options?: StoreAsyncOptions<T>): Store<{
|
|
265
267
|
value: (ReturnType<T> extends Promise<infer U> ? U : undefined) | undefined;
|
|
266
268
|
error: Error | null | undefined;
|
|
267
269
|
loading: boolean;
|
|
@@ -285,13 +287,16 @@ declare function defineAsyncStore<T extends AnyFn>(fetch: T, options?: AsyncStor
|
|
|
285
287
|
loading: boolean;
|
|
286
288
|
finished: boolean;
|
|
287
289
|
}>>;
|
|
288
|
-
|
|
289
|
-
|
|
290
|
+
/**
|
|
291
|
+
* @deprecated
|
|
292
|
+
* use defineStoreAsync instead
|
|
293
|
+
*/
|
|
294
|
+
declare const defienAsyncStore: typeof defineStoreAsync;
|
|
290
295
|
|
|
291
296
|
declare function useStatus<S extends object, A extends Actions<S>, G extends Getters<S>>(store: Store<S, A, G>): valtio.Snapshot<ActionsStatus<A>>;
|
|
292
297
|
|
|
293
|
-
declare function useStore<S extends object, A extends Actions<S>, G extends Getters<S>>(store: Store<S, A, G>): valtio.Snapshot<S & GettersReturnType<G>>;
|
|
298
|
+
declare function useStore<S extends object, A extends Actions<S>, G extends Getters<S>>(store: Store<S, A, G>): valtio.Snapshot<S & GettersReturnType<G> & ActionsOmitThisParameter<A>>;
|
|
294
299
|
|
|
295
300
|
type PropsWithDetailedHTML<T = HTMLDivElement> = DetailedHTMLProps<HTMLAttributes<T>, T>;
|
|
296
301
|
|
|
297
|
-
export { type Argument, type ArgumentArray,
|
|
302
|
+
export { type Argument, type ArgumentArray, Case, type CaseProps, Default, type DefaultProps, Else, type ElseProps, type EventBusListener, type Exposer, type FetchRequestInterceptCallback, type FetchResponseInterceptCallback, If, type IfProps, type InjectComponent, Injector, type InjectorProps, type Mapping, type PersistantOptions, type PropsWithDetailedHTML, type ReadonlyArgumentArray, type StoreAsyncOptions, Switch, type SwitchProps, Then, type ThenProps, Trigger, Unless, type UnlessProps, type UseAsyncStateOptions, type UseWatchCallback, type UseWatchOptions, type Value, type WrapperProps, type WrapperTag, cls, defienAsyncStore, defineStore, defineStoreAsync, proxyWithPersistant, track, tryUseCallback, tryUseEffect, tryUseInsertionEffect, tryUseReducer, tryUseRef, tryUseState, tryUseUpdate, useAsyncCallback, useAsyncState, useDebounce, useEventBus, useFetchRequestIntercept, useFetchResponseIntercept, useMounted, useStatus, useStore, useUpdate, useWatch, useWhenever, wrapper };
|
package/dist/index.global.js
CHANGED
|
@@ -52,8 +52,9 @@ var LibReact = (() => {
|
|
|
52
52
|
Trigger: () => Trigger,
|
|
53
53
|
Unless: () => Unless,
|
|
54
54
|
cls: () => cls,
|
|
55
|
-
|
|
55
|
+
defienAsyncStore: () => defienAsyncStore,
|
|
56
56
|
defineStore: () => defineStore,
|
|
57
|
+
defineStoreAsync: () => defineStoreAsync,
|
|
57
58
|
proxyWithPersistant: () => proxyWithPersistant,
|
|
58
59
|
track: () => track,
|
|
59
60
|
tryUseCallback: () => tryUseCallback,
|
|
@@ -1321,6 +1322,32 @@ var LibReact = (() => {
|
|
|
1321
1322
|
return state;
|
|
1322
1323
|
}
|
|
1323
1324
|
|
|
1325
|
+
// src/storage/utils/index.ts
|
|
1326
|
+
function track2(action, status) {
|
|
1327
|
+
let loadings = 0;
|
|
1328
|
+
const tracking = () => loadings++ === 0 && (status.loading = true);
|
|
1329
|
+
const done = () => !--loadings && (status.loading = false);
|
|
1330
|
+
const fulfilled = (value) => {
|
|
1331
|
+
status.finished = true;
|
|
1332
|
+
done();
|
|
1333
|
+
return value;
|
|
1334
|
+
};
|
|
1335
|
+
const rejected = (error) => {
|
|
1336
|
+
status.error = error;
|
|
1337
|
+
done();
|
|
1338
|
+
throw error;
|
|
1339
|
+
};
|
|
1340
|
+
return function(...args) {
|
|
1341
|
+
tracking();
|
|
1342
|
+
try {
|
|
1343
|
+
const value = action(...args);
|
|
1344
|
+
return value instanceof Promise ? value.then(fulfilled, rejected) : fulfilled(value);
|
|
1345
|
+
} catch (error) {
|
|
1346
|
+
rejected(error);
|
|
1347
|
+
}
|
|
1348
|
+
};
|
|
1349
|
+
}
|
|
1350
|
+
|
|
1324
1351
|
// src/storage/defineStore.ts
|
|
1325
1352
|
function defineStore(store, options = {}) {
|
|
1326
1353
|
const state = typeof store.state === "function" ? store.state() : store.state;
|
|
@@ -1366,34 +1393,13 @@ var LibReact = (() => {
|
|
|
1366
1393
|
...$actions
|
|
1367
1394
|
};
|
|
1368
1395
|
}
|
|
1369
|
-
function track2(action, status) {
|
|
1370
|
-
let loadings = 0;
|
|
1371
|
-
const tracking = () => loadings++ === 0 && (status.loading = true);
|
|
1372
|
-
const done = () => !--loadings && (status.loading = false);
|
|
1373
|
-
const fulfilled = (value) => {
|
|
1374
|
-
status.finished = true;
|
|
1375
|
-
done();
|
|
1376
|
-
return value;
|
|
1377
|
-
};
|
|
1378
|
-
const rejected = (error) => {
|
|
1379
|
-
status.error = error;
|
|
1380
|
-
done();
|
|
1381
|
-
throw error;
|
|
1382
|
-
};
|
|
1383
|
-
return function(...args) {
|
|
1384
|
-
tracking();
|
|
1385
|
-
try {
|
|
1386
|
-
const value = action(...args);
|
|
1387
|
-
return value instanceof Promise ? value.then(fulfilled, rejected) : fulfilled(value);
|
|
1388
|
-
} catch (error) {
|
|
1389
|
-
rejected(error);
|
|
1390
|
-
}
|
|
1391
|
-
};
|
|
1392
|
-
}
|
|
1393
1396
|
function setupActions($state, actions, $actions, $status) {
|
|
1394
1397
|
for (const key in actions) {
|
|
1395
1398
|
$status[key] = { finished: false, loading: false, error: null };
|
|
1396
1399
|
$actions[key] = track2(actions[key].bind($state), $status[key]);
|
|
1400
|
+
Object.defineProperty($state, key, {
|
|
1401
|
+
get: () => $actions[key]
|
|
1402
|
+
});
|
|
1397
1403
|
}
|
|
1398
1404
|
}
|
|
1399
1405
|
function setupGetters(state, $state, getters, $getters) {
|
|
@@ -1423,8 +1429,8 @@ var LibReact = (() => {
|
|
|
1423
1429
|
});
|
|
1424
1430
|
}
|
|
1425
1431
|
|
|
1426
|
-
// src/storage/
|
|
1427
|
-
function
|
|
1432
|
+
// src/storage/defineStoreAsync.ts
|
|
1433
|
+
function defineStoreAsync(fetch, options = {}) {
|
|
1428
1434
|
const store = defineStore(
|
|
1429
1435
|
{
|
|
1430
1436
|
state: () => ({
|
|
@@ -1453,6 +1459,7 @@ var LibReact = (() => {
|
|
|
1453
1459
|
options.immediate && store.fetch();
|
|
1454
1460
|
return store;
|
|
1455
1461
|
}
|
|
1462
|
+
var defienAsyncStore = defineStoreAsync;
|
|
1456
1463
|
|
|
1457
1464
|
// src/storage/useStatus.tsx
|
|
1458
1465
|
function useStatus(store) {
|
package/dist/index.js
CHANGED
|
@@ -498,9 +498,6 @@ function useWhenever(source, cb, options) {
|
|
|
498
498
|
useWatch(source, () => source && cb(source), options);
|
|
499
499
|
}
|
|
500
500
|
|
|
501
|
-
// src/storage/defineAsyncStore.ts
|
|
502
|
-
import { watch } from "valtio/utils";
|
|
503
|
-
|
|
504
501
|
// src/storage/defineStore.ts
|
|
505
502
|
import { createElement as createElement4 } from "react";
|
|
506
503
|
import { proxy as proxy2, subscribe as subscribe2, useSnapshot as useSnapshot2 } from "valtio";
|
|
@@ -527,6 +524,32 @@ function proxyWithPersistant(keyOrOptions, initialObject) {
|
|
|
527
524
|
return state;
|
|
528
525
|
}
|
|
529
526
|
|
|
527
|
+
// src/storage/utils/index.ts
|
|
528
|
+
function track2(action, status) {
|
|
529
|
+
let loadings = 0;
|
|
530
|
+
const tracking = () => loadings++ === 0 && (status.loading = true);
|
|
531
|
+
const done = () => !--loadings && (status.loading = false);
|
|
532
|
+
const fulfilled = (value) => {
|
|
533
|
+
status.finished = true;
|
|
534
|
+
done();
|
|
535
|
+
return value;
|
|
536
|
+
};
|
|
537
|
+
const rejected = (error) => {
|
|
538
|
+
status.error = error;
|
|
539
|
+
done();
|
|
540
|
+
throw error;
|
|
541
|
+
};
|
|
542
|
+
return function(...args) {
|
|
543
|
+
tracking();
|
|
544
|
+
try {
|
|
545
|
+
const value = action(...args);
|
|
546
|
+
return value instanceof Promise ? value.then(fulfilled, rejected) : fulfilled(value);
|
|
547
|
+
} catch (error) {
|
|
548
|
+
rejected(error);
|
|
549
|
+
}
|
|
550
|
+
};
|
|
551
|
+
}
|
|
552
|
+
|
|
530
553
|
// src/storage/defineStore.ts
|
|
531
554
|
function defineStore(store, options = {}) {
|
|
532
555
|
const state = typeof store.state === "function" ? store.state() : store.state;
|
|
@@ -572,34 +595,13 @@ function defineStore(store, options = {}) {
|
|
|
572
595
|
...$actions
|
|
573
596
|
};
|
|
574
597
|
}
|
|
575
|
-
function track2(action, status) {
|
|
576
|
-
let loadings = 0;
|
|
577
|
-
const tracking = () => loadings++ === 0 && (status.loading = true);
|
|
578
|
-
const done = () => !--loadings && (status.loading = false);
|
|
579
|
-
const fulfilled = (value) => {
|
|
580
|
-
status.finished = true;
|
|
581
|
-
done();
|
|
582
|
-
return value;
|
|
583
|
-
};
|
|
584
|
-
const rejected = (error) => {
|
|
585
|
-
status.error = error;
|
|
586
|
-
done();
|
|
587
|
-
throw error;
|
|
588
|
-
};
|
|
589
|
-
return function(...args) {
|
|
590
|
-
tracking();
|
|
591
|
-
try {
|
|
592
|
-
const value = action(...args);
|
|
593
|
-
return value instanceof Promise ? value.then(fulfilled, rejected) : fulfilled(value);
|
|
594
|
-
} catch (error) {
|
|
595
|
-
rejected(error);
|
|
596
|
-
}
|
|
597
|
-
};
|
|
598
|
-
}
|
|
599
598
|
function setupActions($state, actions, $actions, $status) {
|
|
600
599
|
for (const key in actions) {
|
|
601
600
|
$status[key] = { finished: false, loading: false, error: null };
|
|
602
601
|
$actions[key] = track2(actions[key].bind($state), $status[key]);
|
|
602
|
+
Object.defineProperty($state, key, {
|
|
603
|
+
get: () => $actions[key]
|
|
604
|
+
});
|
|
603
605
|
}
|
|
604
606
|
}
|
|
605
607
|
function setupGetters(state, $state, getters, $getters) {
|
|
@@ -629,8 +631,9 @@ function setupStatus($actions, $status) {
|
|
|
629
631
|
});
|
|
630
632
|
}
|
|
631
633
|
|
|
632
|
-
// src/storage/
|
|
633
|
-
|
|
634
|
+
// src/storage/defineStoreAsync.ts
|
|
635
|
+
import { watch } from "valtio/utils";
|
|
636
|
+
function defineStoreAsync(fetch, options = {}) {
|
|
634
637
|
const store = defineStore(
|
|
635
638
|
{
|
|
636
639
|
state: () => ({
|
|
@@ -659,6 +662,7 @@ function defineAsyncStore(fetch, options = {}) {
|
|
|
659
662
|
options.immediate && store.fetch();
|
|
660
663
|
return store;
|
|
661
664
|
}
|
|
665
|
+
var defienAsyncStore = defineStoreAsync;
|
|
662
666
|
|
|
663
667
|
// src/storage/useStatus.tsx
|
|
664
668
|
import { useSnapshot as useSnapshot3 } from "valtio";
|
|
@@ -682,8 +686,9 @@ export {
|
|
|
682
686
|
Trigger,
|
|
683
687
|
Unless,
|
|
684
688
|
cls,
|
|
685
|
-
|
|
689
|
+
defienAsyncStore,
|
|
686
690
|
defineStore,
|
|
691
|
+
defineStoreAsync,
|
|
687
692
|
proxyWithPersistant,
|
|
688
693
|
track,
|
|
689
694
|
tryUseCallback,
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hairy/react-lib",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "1.
|
|
4
|
+
"version": "1.35.0",
|
|
5
5
|
"description": "Library for react",
|
|
6
6
|
"author": "Hairyf <wwu710632@gmail.com>",
|
|
7
7
|
"license": "MIT",
|
|
@@ -38,7 +38,7 @@
|
|
|
38
38
|
"react-dom": "^19.1.0",
|
|
39
39
|
"react-i18next": "^14.1.2",
|
|
40
40
|
"react-use": "^17.6.0",
|
|
41
|
-
"@hairy/utils": "1.
|
|
41
|
+
"@hairy/utils": "1.35.0"
|
|
42
42
|
},
|
|
43
43
|
"scripts": {
|
|
44
44
|
"build": "tsup",
|