resourcerer 2.0.2 → 2.0.4
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.
|
@@ -53,45 +53,45 @@ export default class Collection<T extends Record<string, any> = object, O extend
|
|
|
53
53
|
} & SyncOptions & CSetOptions): Promise<[InstanceType<this["Model"]>, Response]>;
|
|
54
54
|
parse(response: any, options: SyncOptions & CSetOptions): T[];
|
|
55
55
|
_getModelClass<T extends Record<string, any>, O extends Record<string, any>>(): {
|
|
56
|
-
new (attributes?:
|
|
56
|
+
new (attributes?: T_1 | undefined, options?: O_1 & SetOptions & ConstructorOptions): {
|
|
57
57
|
cid: string;
|
|
58
58
|
id: string | number;
|
|
59
|
-
attributes:
|
|
60
|
-
readonly urlOptions:
|
|
61
|
-
collection?: Collection;
|
|
62
|
-
lazy?: boolean;
|
|
63
|
-
refetching?: boolean;
|
|
64
|
-
measure?: boolean | ((config: ResourceConfigObj) => boolean);
|
|
65
|
-
isEmptyModel?: boolean;
|
|
66
|
-
toJSON():
|
|
59
|
+
attributes: T_1;
|
|
60
|
+
readonly urlOptions: O_1;
|
|
61
|
+
collection?: Collection<object, object> | undefined;
|
|
62
|
+
lazy?: boolean | undefined;
|
|
63
|
+
refetching?: boolean | undefined;
|
|
64
|
+
measure?: boolean | ((config: ResourceConfigObj) => boolean) | undefined;
|
|
65
|
+
isEmptyModel?: boolean | undefined;
|
|
66
|
+
toJSON(): T_1;
|
|
67
67
|
sync(model: Model<Record<string, any>, Record<string, any>> | Collection<object, object>, options?: SyncOptions | undefined): Promise<[any, Response]>;
|
|
68
|
-
get<K extends keyof
|
|
69
|
-
pick<
|
|
70
|
-
has(attr: keyof
|
|
71
|
-
set(attrs?: Partial<
|
|
72
|
-
unset(attr: keyof
|
|
73
|
-
clear(options?: SetOptions): any;
|
|
68
|
+
get<K extends keyof T_1>(attr: K): T_1[K];
|
|
69
|
+
pick<K_1 extends keyof T_1>(...attrs: K_1[]): Pick<T_1, K_1>;
|
|
70
|
+
has(attr: keyof T_1): boolean;
|
|
71
|
+
set(attrs?: Partial<T_1>, options?: SetOptions): any;
|
|
72
|
+
unset(attr: keyof T_1, options?: SetOptions | undefined): any;
|
|
73
|
+
clear(options?: SetOptions | undefined): any;
|
|
74
74
|
fetch(options?: SyncOptions & SetOptions): Promise<readonly [any, Response]>;
|
|
75
|
-
save(attrs: Partial<
|
|
76
|
-
wait?: boolean;
|
|
77
|
-
patch?: boolean;
|
|
75
|
+
save(attrs: Partial<T_1>, options?: {
|
|
76
|
+
wait?: boolean | undefined;
|
|
77
|
+
patch?: boolean | undefined;
|
|
78
78
|
} & SyncOptions & SetOptions): Promise<[any, Response]>;
|
|
79
79
|
destroy(options?: {
|
|
80
|
-
wait?: boolean;
|
|
80
|
+
wait?: boolean | undefined;
|
|
81
81
|
} & SyncOptions & SetOptions): Promise<[any, Response]>;
|
|
82
|
-
url(options?:
|
|
83
|
-
parse(response: any, options: SyncOptions & SetOptions):
|
|
82
|
+
url(options?: O_2): string;
|
|
83
|
+
parse(response: any, options: SyncOptions & SetOptions): T_1;
|
|
84
84
|
isNew(): boolean;
|
|
85
85
|
_callbacks: {
|
|
86
86
|
callback: (...args: any[]) => void;
|
|
87
|
-
context:
|
|
87
|
+
context: {};
|
|
88
88
|
}[];
|
|
89
89
|
triggerUpdate(): void;
|
|
90
90
|
onUpdate(callback: (...args: any[]) => void, context: {}): void;
|
|
91
91
|
offUpdate(ctx: {}): void;
|
|
92
92
|
};
|
|
93
93
|
idAttribute: string;
|
|
94
|
-
dependencies:
|
|
94
|
+
dependencies: (string | ((attrs: Record<string, any>) => Record<string, any>))[];
|
|
95
95
|
cacheTimeout: number;
|
|
96
96
|
defaults: {};
|
|
97
97
|
measure: boolean | ((config: ResourceConfigObj) => boolean);
|
|
@@ -12,6 +12,6 @@ export declare function useResources<T extends ResourceKeys, O extends Record<st
|
|
|
12
12
|
[Key in T as `${T}Status`]: number;
|
|
13
13
|
};
|
|
14
14
|
export declare const withResources: (getResources: ExecutorFunction) => (Component: ComponentClass<Record<string, any>>) => (props: Record<string, any>) => React.CElement<{
|
|
15
|
-
children: React.ReactElement
|
|
15
|
+
children: React.ReactElement<any, string | React.JSXElementConstructor<any>>;
|
|
16
16
|
}, ErrorBoundary>;
|
|
17
17
|
export declare function getCacheKey({ resourceKey, params, path, data, }: InternalResourceConfigObj): string;
|
package/build/lib/resourcerer.js
CHANGED
|
@@ -18,7 +18,10 @@ export function useResources(getResources, _props) {
|
|
|
18
18
|
hasInitiallyLoaded: hasLoaded(getCriticalLoadingStates(initialLoadingStates, resources)),
|
|
19
19
|
});
|
|
20
20
|
const criticalLoadingStates = getCriticalLoadingStates(loadingStates, resources);
|
|
21
|
-
const [models, setModels] = useState(
|
|
21
|
+
const [models, setModels] = useState(() => {
|
|
22
|
+
const result = modelAggregator(resources.filter(withoutPrefetch));
|
|
23
|
+
return typeof result === "function" ? result({}) : result;
|
|
24
|
+
});
|
|
22
25
|
const isMountedRef = useIsMounted();
|
|
23
26
|
const componentRef = useRef({});
|
|
24
27
|
const prevPropsRef = useRef();
|
|
@@ -35,6 +38,7 @@ export function useResources(getResources, _props) {
|
|
|
35
38
|
const previousCacheKey = prevConfig && getCacheKey(prevConfig);
|
|
36
39
|
return (!previousCacheKey ||
|
|
37
40
|
previousCacheKey !== getCacheKey(config) ||
|
|
41
|
+
!models[getResourcePropertyName(name, config.resourceKey)] ||
|
|
38
42
|
!hasAllDependencies(["", prevConfig]) ||
|
|
39
43
|
(config.refetch &&
|
|
40
44
|
(hasLoaded(loadingStates[getResourceState(name)]) ||
|
|
@@ -323,6 +327,7 @@ function partitionResources(resourcesToUpdate, loadingStates) {
|
|
|
323
327
|
return resourcesToUpdate.reduce((memo, [name, config]) => (config.refetch ||
|
|
324
328
|
config.force ||
|
|
325
329
|
config.prefetch ||
|
|
330
|
+
config.lazy ||
|
|
326
331
|
!hasLoaded(loadingStates[getResourceState(name)]) ||
|
|
327
332
|
getModelFromCache(config)?.lazy) ?
|
|
328
333
|
[memo[0], memo[1].concat([[name, config]])]
|