Skip to content

Commit

Permalink
fix(store): get descriptor explicitly when considered as class prop
Browse files Browse the repository at this point in the history
  • Loading branch information
arturovt committed Jan 9, 2023
1 parent 5f9405c commit 40f9b91
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 11 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@
"lint-staged": "^9.5.0",
"mock-socket": "^8.1.0",
"ng-packagr": "^12.2.7",
"prettier": "1.19.1",
"prettier": "2.8.2",
"rxjs": "6.6.7",
"start-server-and-test": "^1.11.0",
"ts-loader": "^6.2.1",
Expand Down
1 change: 1 addition & 0 deletions packages/store/src/decorators/selector-options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ export function SelectorOptions(options: SharedSelectorOptions) {
descriptor: TypedPropertyDescriptor<T>
) {
if (methodName) {
descriptor ||= Object.getOwnPropertyDescriptor(target, methodName)!;
// Method Decorator
const originalFn = descriptor.value || (<any>descriptor).originalFn;
if (originalFn) {
Expand Down
13 changes: 7 additions & 6 deletions packages/store/src/decorators/selector/selector.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,29 +11,30 @@ export function Selector<T>(selectors?: T[]): SelectorType<T> {
key: string | symbol,
descriptor: TypedPropertyDescriptor<SelectorSpec<T, U>>
): TypedPropertyDescriptor<SelectorSpec<T, U>> | void => {
descriptor ||= Object.getOwnPropertyDescriptor(target, key)!;

const originalFn = descriptor?.value;

// Caretaker note: we have still left the `typeof` condition in order to avoid
// creating a breaking change for projects that still use the View Engine.
if (typeof ngDevMode === 'undefined' || ngDevMode) {
const isNotMethod = !(descriptor && descriptor.value !== null);

if (isNotMethod) {
if (originalFn && typeof originalFn !== 'function') {
throwSelectorDecoratorError();
}
}

const originalFn = descriptor.value;
const memoizedFn = createSelector(selectors, originalFn as any, {
containerClass: target,
selectorName: key.toString(),
getSelectorOptions() {
return {};
}
},
});
const newDescriptor = {
configurable: true,
get() {
return memoizedFn;
}
},
};
// Add hidden property to descriptor
(<any>newDescriptor)['originalFn'] = originalFn;
Expand Down
8 changes: 4 additions & 4 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -9975,10 +9975,10 @@ preserve@^0.2.0:
resolved "https://registry.npmjs.org/preserve/-/preserve-0.2.0.tgz#815ed1f6ebc65926f865b310c0713bcb3315ce4b"
integrity sha512-s/46sYeylUfHNjI+sA/78FAHlmIuKqI9wNnzEOGehAlUUYeObv5C2mOinXBjyUyWmJ2SfcS2/ydApH4hTF4WXQ==

prettier@1.19.1:
version "1.19.1"
resolved "https://registry.npmjs.org/prettier/-/prettier-1.19.1.tgz#f7d7f5ff8a9cd872a7be4ca142095956a60797cb"
integrity sha512-s7PoyDv/II1ObgQunCbB9PdLmUcBZcnWOcxDh7O0N/UwDEsHyqkW+Qh28jW+mVuCdx7gLB0BotYI1Y6uI9iyew==
prettier@2.8.2:
version "2.8.2"
resolved "https://registry.npmjs.org/prettier/-/prettier-2.8.2.tgz#c4ea1b5b454d7c4b59966db2e06ed7eec5dfd160"
integrity sha512-BtRV9BcncDyI2tsuS19zzhzoxD8Dh8LiCx7j7tHzrkz8GFXAexeWFdi22mjE1d16dftH2qNaytVxqiRTGlMfpw==

pretty-bytes@^5.3.0:
version "5.6.0"
Expand Down

0 comments on commit 40f9b91

Please sign in to comment.