@@ -3,63 +3,32 @@ import { ignoreElements } from 'rxjs/operator/ignoreElements';
33import { Observable } from 'rxjs/Observable' ;
44import { compose } from '@ngrx/store' ;
55
6- const METADATA_KEY = '@ngrx/effects ' ;
6+ const METADATA_KEY = '__ @ngrx/effects__ ' ;
77const r : any = Reflect ;
88
99export interface EffectMetadata {
1010 propertyName : string ;
1111 dispatch : boolean ;
1212}
1313
14- function hasStaticMetadata ( sourceType : any ) : boolean {
15- return ! ! ( sourceType as any ) . propDecorators ;
16- }
17-
18- function getStaticMetadata ( sourceType : any ) : EffectMetadata [ ] {
19- const propDecorators = sourceType . propDecorators ;
20- return Object . keys ( propDecorators ) . reduce (
21- ( all , key ) => all . concat ( getStaticMetadataEntry ( propDecorators [ key ] , key ) ) ,
22- [ ]
23- ) ;
24- }
25-
26- function getStaticMetadataEntry ( metadataEntry : any , propertyName : string ) {
27- return metadataEntry
28- . filter ( ( entry : any ) => entry . type === Effect )
29- . map ( ( entry : any ) => {
30- let dispatch = true ;
31- if ( entry . args && entry . args . length ) {
32- dispatch = ! ! entry . args [ 0 ] . dispatch ;
33- }
34- return { propertyName, dispatch } ;
35- } ) ;
36- }
37-
3814function getEffectMetadataEntries ( sourceProto : any ) : EffectMetadata [ ] {
39- if ( hasStaticMetadata ( sourceProto . constructor ) ) {
40- return getStaticMetadata ( sourceProto . constructor ) ;
41- }
42-
43- if ( r . hasOwnMetadata ( METADATA_KEY , sourceProto ) ) {
44- return r . getOwnMetadata ( METADATA_KEY , sourceProto ) ;
45- }
46-
47- return [ ] ;
15+ return sourceProto . constructor [ METADATA_KEY ] || [ ] ;
4816}
4917
5018function setEffectMetadataEntries ( sourceProto : any , entries : EffectMetadata [ ] ) {
51- r . defineMetadata ( METADATA_KEY , entries , sourceProto ) ;
19+ const constructor = sourceProto . constructor ;
20+ const meta : EffectMetadata [ ] = constructor . hasOwnProperty ( METADATA_KEY )
21+ ? ( constructor as any ) [ METADATA_KEY ]
22+ : Object . defineProperty ( constructor , METADATA_KEY , { value : [ ] } ) [
23+ METADATA_KEY
24+ ] ;
25+ Array . prototype . push . apply ( meta , entries ) ;
5226}
5327
54- /**
55- * @Annotation
56- */
5728export function Effect ( { dispatch } = { dispatch : true } ) : PropertyDecorator {
5829 return function ( target : any , propertyName : string ) {
59- const effects : EffectMetadata [ ] = getEffectMetadataEntries ( target ) ;
6030 const metadata : EffectMetadata = { propertyName, dispatch } ;
61-
62- setEffectMetadataEntries ( target , [ ...effects , metadata ] ) ;
31+ setEffectMetadataEntries ( target , [ metadata ] ) ;
6332 } ;
6433}
6534
0 commit comments