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

Commit dcaf6cd

Browse files
committed
fixed typos
1 parent 0e73f5c commit dcaf6cd

File tree

6 files changed

+94
-63
lines changed

6 files changed

+94
-63
lines changed

packages/event/tests/unit/event.observer.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ describe('EventObserver Tests', () => {
99
beforeEach(() => {
1010
LogMock.mockLogs();
1111

12-
dummyAgile = new Agile({ localStorage: false });
12+
dummyAgile = new Agile();
1313
dummyEvent = new Event(dummyAgile);
1414

1515
jest.clearAllMocks();

packages/event/tests/unit/event.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ describe('Event Tests', () => {
99
beforeEach(() => {
1010
LogMock.mockLogs();
1111

12-
dummyAgile = new Agile({ localStorage: false });
12+
dummyAgile = new Agile();
1313

1414
jest.clearAllMocks();
1515
});

packages/react/src/hooks/useAgile.ts

Lines changed: 5 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -59,15 +59,16 @@ export function useAgile<
5959
componentId: undefined,
6060
observerType: undefined,
6161
deps: [],
62-
handleReturn: (dep: Observer | undefined) => {
63-
return dep != null ? dep.value : undefined;
64-
},
6562
});
6663
const depsArray = extractRelevantObservers(
6764
normalizeArray(deps),
6865
config.observerType
6966
);
7067

68+
const handleReturn = (dep: Observer | undefined) => {
69+
return dep != null ? dep.value : undefined;
70+
};
71+
7172
useBaseAgile(
7273
depsArray,
7374
() => ({
@@ -79,38 +80,10 @@ export function useAgile<
7980
config.agileInstance
8081
);
8182

82-
return getReturnValue(
83-
depsArray,
84-
config.handleReturn as any,
85-
Array.isArray(deps)
86-
);
83+
return getReturnValue(depsArray, handleReturn, Array.isArray(deps));
8784
}
8885

8986
export interface AgileHookConfigInterface extends BaseAgileHookConfigInterface {
90-
/**
91-
* Whether to wrap a [Proxy](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Proxy)
92-
* around the bound Agile Instance value object,
93-
* to automatically constrain the way the selected Agile Instance
94-
* is compared to determine whether the Component needs to be re-rendered
95-
* based on the object's used properties.
96-
*
97-
* Requires an additional package called `@agile-ts/proxytree`!
98-
*
99-
* @default false
100-
*/
101-
// proxyBased?: boolean;
102-
/**
103-
* Equality comparison function
104-
* that allows you to customize the way the selected Agile Instance
105-
* is compared to determine whether the Component needs to be re-rendered.
106-
*
107-
* * Note that setting this property can destroy the useAgile type.
108-
* -> should only be used internal!
109-
*
110-
* @default undefined
111-
*/
112-
// selector?: SelectorMethodType;
113-
11487
/**
11588
* What type of Observer to be bound to the UI-Component.
11689
*
@@ -120,10 +93,6 @@ export interface AgileHookConfigInterface extends BaseAgileHookConfigInterface {
12093
* @default undefined
12194
*/
12295
observerType?: string;
123-
/**
124-
* TODO
125-
*/
126-
handleReturn?: (dep: Observer | undefined) => any;
12796
}
12897

12998
// Array Type

packages/react/src/hooks/useBaseAgile.ts

Lines changed: 33 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,19 @@ import Agile, {
1111
} from '@agile-ts/core';
1212
import { useIsomorphicLayoutEffect } from './useIsomorphicLayoutEffect';
1313

14+
/**
15+
* An internal used React Hook
16+
* to create a Callback based Subscription Container
17+
* based on the specified depsArray
18+
* and thus bind these dependencies to a Functional React Component.
19+
*
20+
* @internal
21+
* @param depsArray - Observers to be bound to the Functional Component.
22+
* @param getSubContainerConfig - Method to get the Subscription Container configuration object.
23+
* @param deps - Dependencies that determine, in addition to unmounting and remounting the React-Component,
24+
* when the specified Agile Sub Instances should be re-subscribed to the React-Component.
25+
* @param agileInstance - Agile Instance the to create Subscription Container belongs to.
26+
*/
1427
export const useBaseAgile = (
1528
depsArray: (Observer | undefined)[],
1629
getSubContainerConfig: (
@@ -30,11 +43,18 @@ export const useBaseAgile = (
3043

3144
const subContainerConfig = getSubContainerConfig(observers);
3245

33-
const _agileInstance = extractAgileInstance(observers, agileInstance);
34-
if (_agileInstance == null) return;
46+
// Try to extract Agile Instance from the specified Instance/s
47+
if (agileInstance == null) agileInstance = getAgileInstance(observers[0]);
48+
if (agileInstance == null || agileInstance.subController == null) {
49+
LogCodeManager.getLogger()?.error(
50+
'Failed to subscribe Component with deps because of missing valid Agile Instance.',
51+
deps
52+
);
53+
return;
54+
}
3555

3656
// Create Callback based Subscription
37-
const subscriptionContainer = _agileInstance.subController.subscribe(
57+
const subscriptionContainer = agileInstance.subController.subscribe(
3858
() => {
3959
forceRender();
4060
},
@@ -44,31 +64,20 @@ export const useBaseAgile = (
4464

4565
// Unsubscribe Callback based Subscription on unmount
4666
return () => {
47-
_agileInstance.subController.unsubscribe(subscriptionContainer);
67+
agileInstance?.subController.unsubscribe(subscriptionContainer);
4868
};
4969
}, deps);
5070
};
5171

52-
export const extractAgileInstance = (
53-
observers: Observer[],
54-
agileInstance?: Agile
55-
): Agile | undefined => {
56-
if (agileInstance != null) return agileInstance;
57-
58-
// Try to extract Agile Instance from the specified Observers
59-
agileInstance = getAgileInstance(observers[0]);
60-
if (!agileInstance || !agileInstance.subController) {
61-
LogCodeManager.getLogger()?.error(
62-
'Failed to subscribe to React Component because of missing valid Agile Instance.',
63-
observers
64-
);
65-
return undefined;
66-
}
67-
return agileInstance;
68-
};
69-
70-
// Builds return value,
71-
// depending on whether the deps were provided in array shape or not
72+
/**
73+
* Builds return value for Agile Instance 'binding' Hooks,
74+
* depending on whether the dependencies were provided in array shape or not.
75+
*
76+
* @internal
77+
* @param depsArray - Dependencies to extract the return value from.
78+
* @param handleReturn - Method to handle the return value.
79+
* @param wasProvidedAsArray - Whether the specified depsArray was provided as array in the Hook.
80+
*/
7281
export const getReturnValue = (
7382
depsArray: (Observer | undefined)[],
7483
handleReturn: (dep: Observer | undefined) => any,

packages/react/src/hooks/useProxy.ts

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,48 @@ try {
2424
// empty catch block
2525
}
2626

27+
/**
28+
* A React Hook for binding the most relevant value of multiple Agile Instances
29+
* (like the Collection's output or the State's value)
30+
* to a React Functional Component.
31+
*
32+
* This binding ensures that the Component re-renders
33+
* whenever the most relevant Observer of an Agile Instance mutates.
34+
*
35+
* In addition the the default 'useAgile' Hook,
36+
* the useProxy Hooks wraps a [Proxy](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Proxy)
37+
* around the to bind Agile Instance value objects,
38+
* to automatically constraint the way the selected Agile Instances
39+
* are compared to determine whether the React Component needs to be re-rendered
40+
* based on the object's used properties.
41+
*
42+
* @public
43+
* @param deps - Agile Sub Instances to be bound to the Functional Component.
44+
* @param config - Configuration object
45+
*/
2746
export function useProxy<X extends Array<SubscribableAgileInstancesType>>(
2847
deps: X | [],
2948
config?: AgileHookConfigInterface
3049
): AgileOutputHookArrayType<X>;
31-
50+
/**
51+
* A React Hook for binding the most relevant Agile Instance value
52+
* (like the Collection's output or the State's value)
53+
* to a React Functional Component.
54+
*
55+
* This binding ensures that the Component re-renders
56+
* whenever the most relevant Observer of the Agile Instance mutates.
57+
*
58+
* In addition the the default 'useAgile' Hook,
59+
* the useProxy Hooks wraps a [Proxy](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Proxy)
60+
* around the to bind Agile Instance value objects,
61+
* to automatically constraint the way the selected Agile Instances
62+
* are compared to determine whether the React Component needs to be re-rendered
63+
* based on the object's used properties.
64+
*
65+
* @public
66+
* @param dep - Agile Sub Instance to be bound to the Functional Component.
67+
* @param config - Configuration object
68+
*/
3269
export function useProxy<X extends SubscribableAgileInstancesType>(
3370
dep: X,
3471
config?: AgileHookConfigInterface
@@ -63,6 +100,7 @@ export function useProxy<
63100
proxyTreeWeakMap.set(dep, proxyTree);
64101
return proxyTree.proxy;
65102
} else {
103+
// TODO add LogCode Manager logcode
66104
console.error(
67105
'In order to use the Agile proxy functionality, ' +
68106
`the installation of an additional package called '@agile-ts/proxytree' is required!`

packages/react/src/hooks/useSelector.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,21 @@ export function useSelector<
2424
config?: BaseAgileHookConfigInterface
2525
): ReturnType;
2626

27+
/**
28+
* A React Hook for binding a selected value of an Agile Instance
29+
* (like the Collection's output or the State's value)
30+
* to a React Functional Component.
31+
*
32+
* This binding ensures that the Component re-renders
33+
* whenever the selected value of an Agile Instance mutates.
34+
*
35+
* @public
36+
* @param dep - Agile Sub Instance to be bound to the Functional Component.
37+
* @param selector - Equality comparison function
38+
* that allows you to customize the way the selected Agile Instance
39+
* is compared to determine whether the Component needs to be re-rendered.
40+
* @param config - Configuration object
41+
*/
2742
export function useSelector<ValueType = any, ReturnType = any>(
2843
dep: SubscribableAgileInstancesType,
2944
selector: SelectorMethodType<ValueType>,

0 commit comments

Comments
 (0)