Skip to content
This repository was archived by the owner on Oct 16, 2024. It is now read-only.

Commit 088ac24

Browse files
committed
fixed freezing issue when using useProxy
1 parent 327bffb commit 088ac24

File tree

6 files changed

+17
-27
lines changed

6 files changed

+17
-27
lines changed

packages/core/src/collection/collection.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,7 @@ import { GroupIngestConfigInterface } from './group/group.observer';
2323
import { StorageKey } from '../storages';
2424
import { CollectionPersistent } from './collection.persistent';
2525

26-
export class Collection<
27-
DataType extends DefaultItem = DefaultItem,
28-
GroupValueType = Array<ItemKey> // To extract the Group Type Value in Integration methods like 'useValue()'
29-
> {
26+
export class Collection<DataType extends DefaultItem = DefaultItem> {
3027
// Agile Instance the Collection belongs to
3128
public agileInstance: () => Agile;
3229

packages/core/src/collection/group/group.observer.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,12 @@ export class GroupObserver<
1616
// Group the Observer belongs to
1717
public group: () => Group<DataType>;
1818

19-
// Next output applied to the Group
19+
// Next vale (output) applied to the Group
2020
public nextGroupValue: DataType[];
2121

22-
// Current value of the Group (shared with the UI)
22+
// Current value (output) of the Group (shared with the UI)
2323
public value?: DataType[];
24-
// Previous value of the Group (for handling selectors)
24+
// Previous value (output) of the Group (for handling selectors)
2525
public previousValue?: DataType[];
2626

2727
/**
@@ -123,7 +123,7 @@ export class GroupObserver<
123123

124124
// Assign new public output to the Observer (output used by the Integrations)
125125
observer.previousValue = Object.freeze(copy(observer.value)) as any;
126-
observer.value = Object.freeze(copy(group._output)) as any;
126+
observer.value = copy(group._output); // Object.freeze(copy(group._output)); // Not freezing because of 'useProxy' hook
127127
}
128128
}
129129

packages/core/src/state/state.observer.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ export class StateObserver<ValueType = any> extends Observer {
154154

155155
// Assign new public value to the Observer (value used by the Integrations)
156156
job.observer.previousValue = Object.freeze(copy(observer.value));
157-
job.observer.value = Object.freeze(copy(state._value));
157+
job.observer.value = copy(state._value); // Object.freeze(copy(state._value)); // Not freezing because of 'useProxy' hook
158158
}
159159

160160
/**

packages/react/src/core/hooks/useBaseAgile.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ export const getReturnValue = (
9393

9494
export type SubscribableAgileInstancesType =
9595
| State
96-
| Collection<any, any> //https://stackoverflow.com/questions/66987727/type-classa-id-number-name-string-is-not-assignable-to-type-classar
96+
| Collection<any> //https://stackoverflow.com/questions/66987727/type-classa-id-number-name-string-is-not-assignable-to-type-classar
9797
| Observer
9898
| undefined;
9999

packages/react/src/core/hooks/useValue.ts

Lines changed: 9 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import {
22
Collection,
33
Group,
4-
Observer,
54
State,
65
defineConfig,
6+
ItemKey,
77
} from '@agile-ts/core';
88
import { useAgile } from './useAgile';
99
import {
@@ -39,35 +39,28 @@ export function useValue<
3939
// Array Type
4040
// https://www.typescriptlang.org/docs/handbook/release-notes/typescript-2-1.html
4141
export type AgileValueHookArrayType<T> = {
42-
[K in keyof T]: T[K] extends
43-
| Collection<infer U, infer Z>
44-
| Group<infer U, infer Z>
45-
? Z
42+
[K in keyof T]: T[K] extends Collection | Group
43+
? Array<ItemKey>
4644
: T[K] extends State<infer U>
4745
? U
4846
: T[K] extends undefined
4947
? undefined
50-
: T[K] extends
51-
| Collection<infer U, infer Z>
52-
| Group<infer U, infer Z>
53-
| undefined
54-
? Z | undefined
48+
: T[K] extends Collection | Group | undefined
49+
? Array<ItemKey> | undefined
5550
: T[K] extends State<infer U> | undefined
5651
? U | undefined
5752
: never;
5853
};
5954

6055
// No Array Type
61-
export type AgileValueHookType<T> = T extends
62-
| Collection<infer U, infer Z>
63-
| Group<infer U, infer Z>
64-
? Z
56+
export type AgileValueHookType<T> = T extends Collection | Group
57+
? Array<ItemKey>
6558
: T extends State<infer U>
6659
? U
6760
: T extends undefined
6861
? undefined
69-
: T extends Collection<infer U, infer Z> | Group<infer U, infer Z> | undefined
70-
? Z | undefined
62+
: T extends Collection | Group | undefined
63+
? Array<ItemKey> | undefined
7164
: T extends State<infer U> | undefined
7265
? U | undefined
7366
: never;

packages/react/src/proxy/hooks/useProxy.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ export function useProxy<
8787

8888
const handleReturn = (dep: Observer | undefined) => {
8989
if (dep == null) return undefined as any;
90-
const value = dep.value;
90+
const value = dep['value'];
9191

9292
// If proxyBased and the value is of the type object.
9393
// Wrap a Proxy around the object to track the accessed properties.

0 commit comments

Comments
 (0)