-
-
Notifications
You must be signed in to change notification settings - Fork 2k
refactor(effects): prepare for TS 3.5 #2191
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,15 @@ | ||
import { compose } from '@ngrx/store'; | ||
import { EffectMetadata, EffectConfig } from './models'; | ||
|
||
import { EffectConfig, EffectMetadata, EffectPropertyKey } from './models'; | ||
import { getSourceForInstance } from './utils'; | ||
|
||
const METADATA_KEY = '__@ngrx/effects__'; | ||
|
||
export function Effect<T>({ | ||
export function Effect({ | ||
dispatch = true, | ||
resubscribeOnError = true, | ||
}: EffectConfig = {}): PropertyDecorator { | ||
return function<K extends Extract<keyof T, string>>( | ||
}: EffectConfig = {}) { | ||
return function<T extends Object, K extends EffectPropertyKey<T>>( | ||
target: T, | ||
propertyName: K | ||
) { | ||
|
@@ -21,7 +22,7 @@ export function Effect<T>({ | |
resubscribeOnError, | ||
}; | ||
setEffectMetadataEntries<T>(target, [metadata]); | ||
} as (target: {}, propertyName: string | symbol) => void; | ||
}; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Woohoo! Love this change! There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 😃 |
||
} | ||
|
||
export function getEffectDecoratorMetadata<T>( | ||
|
@@ -35,7 +36,7 @@ export function getEffectDecoratorMetadata<T>( | |
return effectsDecorators; | ||
} | ||
|
||
function setEffectMetadataEntries<T>( | ||
function setEffectMetadataEntries<T extends object>( | ||
sourceProto: T, | ||
entries: EffectMetadata<T>[] | ||
) { | ||
|
@@ -50,8 +51,12 @@ function setEffectMetadataEntries<T>( | |
Array.prototype.push.apply(meta, entries); | ||
} | ||
|
||
function getEffectMetadataEntries<T>(sourceProto: T): EffectMetadata<T>[] { | ||
function getEffectMetadataEntries<T extends object>( | ||
sourceProto: T | ||
): EffectMetadata<T>[] { | ||
return sourceProto.constructor.hasOwnProperty(METADATA_KEY) | ||
? (sourceProto.constructor as any)[METADATA_KEY] | ||
? (sourceProto.constructor as typeof sourceProto.constructor & { | ||
[METADATA_KEY]: EffectMetadata<T>[]; | ||
})[METADATA_KEY] | ||
: []; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,7 +4,7 @@ import { Notification, Observable } from 'rxjs'; | |
|
||
export interface EffectNotification { | ||
effect: Observable<any> | (() => Observable<any>); | ||
propertyName: string; | ||
propertyName: PropertyKey; | ||
sourceName: string; | ||
sourceInstance: any; | ||
notification: Notification<Action | null | undefined>; | ||
|
@@ -46,7 +46,7 @@ function getEffectName({ | |
}: EffectNotification) { | ||
const isMethod = typeof sourceInstance[propertyName] === 'function'; | ||
|
||
return `"${sourceName}.${propertyName}${isMethod ? '()' : ''}"`; | ||
return `"${sourceName}.${String(propertyName)}${isMethod ? '()' : ''}"`; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why this change required? I thought Typescript knew that There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good question @L2jLiga ! I'm bringing the I probably should rename |
||
} | ||
|
||
function stringify(action: Action | null | undefined) { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
May be
T extends Record<keyof T, Object>
would be better?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, it's the same thing. Don't think we used
Record
at the codebase yet.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Then fine :)