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

Commit 71648dd

Browse files
committed
fixed typo
1 parent 6600cd5 commit 71648dd

File tree

4 files changed

+33
-11
lines changed

4 files changed

+33
-11
lines changed

examples/plainjs/develop/tree-shaking/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
"license": "ISC",
1414
"devDependencies": {
1515
"webpack": "^5.47.0",
16-
"webpack-cli": "^4.7.2"
16+
"webpack-cli": "^4.8.0"
1717
},
1818
"dependencies": {
1919
"@agile-ts/core": "file:.yalc/@agile-ts/core"

packages/core/src/logCodeManager.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ const logCodeTypes = {
2525
// ---
2626
// 00:00:|00| third digits are based on the Log Message (ascending counted)
2727

28-
const logCodeMessages = {
28+
const niceLogCodeMessages = {
2929
// Agile
3030
'10:00:00': 'Created new AgileInstance.',
3131
'10:02:00':
@@ -167,6 +167,13 @@ const logCodeMessages = {
167167
'00:03:01': "'${0}' has to be of the type ${1}!",
168168
};
169169

170+
// Note: Not outsource the 'production' env check,
171+
// because then webpack can't treeshake based on the current env
172+
const logCodeMessages: typeof niceLogCodeMessages =
173+
typeof process === 'object' && process.env.NODE_ENV !== 'production'
174+
? niceLogCodeMessages
175+
: ({} as any);
176+
170177
/**
171178
* Returns the log message according to the specified log code.
172179
*

packages/react/src/hocs/AgileHOC.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ import Agile, {
99
extractRelevantObservers,
1010
normalizeArray,
1111
} from '@agile-ts/core';
12-
import type { Collection } from '@agile-ts/core';
13-
import { LogCodeManager } from '../logCodeManager'; // Only import Collection and Group type for better Treeshaking
12+
import type { Collection } from '@agile-ts/core'; // Only import Collection and Group type for better Treeshaking
13+
import { LogCodeManager } from '../logCodeManager';
1414

1515
/**
1616
* A Higher order Component for binding the most relevant value of multiple Agile Instances

packages/react/src/hooks/useSelector.ts

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,16 +14,30 @@ import {
1414
} from './useBaseAgile';
1515
import { AgileValueHookType } from './useValue';
1616

17+
/**
18+
* A React Hook for binding a selected value of an Agile Instance
19+
* (like the Collection's output or the State's value)
20+
* to a React Functional Component.
21+
*
22+
* This binding ensures that the Component re-renders
23+
* whenever the selected value of an Agile Instance mutates.
24+
*
25+
* @public
26+
* @param dep - Agile Sub Instance to be bound to the Functional Component.
27+
* @param selectorMethod - Equality comparison function.
28+
* that allows you to customize the way the selected Agile Instance
29+
* is compared to determine whether the Component needs to be re-rendered.
30+
* @param config - Configuration object
31+
*/
1732
export function useSelector<
1833
ReturnType,
1934
X extends SubscribableAgileInstancesType,
2035
ValueType extends AgileValueHookType<X>
2136
>(
2237
dep: X,
23-
selector: SelectorMethodType<ValueType>,
38+
selectorMethod: SelectorMethodType<ValueType>,
2439
config?: BaseAgileHookConfigInterface
2540
): ReturnType;
26-
2741
/**
2842
* A React Hook for binding a selected value of an Agile Instance
2943
* (like the Collection's output or the State's value)
@@ -34,14 +48,14 @@ export function useSelector<
3448
*
3549
* @public
3650
* @param dep - Agile Sub Instance to be bound to the Functional Component.
37-
* @param selector - Equality comparison function
51+
* @param selectorMethod - Equality comparison function.
3852
* that allows you to customize the way the selected Agile Instance
3953
* is compared to determine whether the Component needs to be re-rendered.
4054
* @param config - Configuration object
4155
*/
4256
export function useSelector<ValueType = any, ReturnType = any>(
4357
dep: SubscribableAgileInstancesType,
44-
selector: SelectorMethodType<ValueType>,
58+
selectorMethod: SelectorMethodType<ValueType>,
4559
config?: BaseAgileHookConfigInterface
4660
): ReturnType;
4761

@@ -51,13 +65,14 @@ export function useSelector<
5165
ReturnType = any
5266
>(
5367
dep: X,
54-
selector: SelectorMethodType<ValueType>,
68+
selectorMethod: SelectorMethodType<ValueType>,
5569
config: BaseAgileHookConfigInterface = {}
5670
): ReturnType {
5771
config = defineConfig(config, {
5872
key: generateId(),
5973
agileInstance: null as any,
6074
componentId: undefined,
75+
deps: [],
6176
});
6277
const depsArray = extractRelevantObservers([dep]);
6378

@@ -70,7 +85,7 @@ export function useSelector<
7085
// (Destroys the type of the useAgile hook,
7186
// however the type can be adjusted in the useSelector hook)
7287
if (isValidObject(value, true)) {
73-
return selector(value);
88+
return selectorMethod(value);
7489
}
7590

7691
return value;
@@ -83,7 +98,7 @@ export function useSelector<
8398
let selectorWeakMap: SelectorWeakMapType | undefined = undefined;
8499
selectorWeakMap = new WeakMap();
85100
for (const observer of observers) {
86-
selectorWeakMap.set(observer, { methods: [selector] });
101+
selectorWeakMap.set(observer, { methods: [selectorMethod] });
87102
}
88103

89104
return {

0 commit comments

Comments
 (0)