@@ -3,63 +3,32 @@ import { ignoreElements } from 'rxjs/operator/ignoreElements';
3
3
import { Observable } from 'rxjs/Observable' ;
4
4
import { compose } from '@ngrx/store' ;
5
5
6
- const METADATA_KEY = '@ngrx/effects ' ;
6
+ const METADATA_KEY = '__ @ngrx/effects__ ' ;
7
7
const r : any = Reflect ;
8
8
9
9
export interface EffectMetadata {
10
10
propertyName : string ;
11
11
dispatch : boolean ;
12
12
}
13
13
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
-
38
14
function 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 ] || [ ] ;
48
16
}
49
17
50
18
function 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 ) ;
52
26
}
53
27
54
- /**
55
- * @Annotation
56
- */
57
28
export function Effect ( { dispatch } = { dispatch : true } ) : PropertyDecorator {
58
29
return function ( target : any , propertyName : string ) {
59
- const effects : EffectMetadata [ ] = getEffectMetadataEntries ( target ) ;
60
30
const metadata : EffectMetadata = { propertyName, dispatch } ;
61
-
62
- setEffectMetadataEntries ( target , [ ...effects , metadata ] ) ;
31
+ setEffectMetadataEntries ( target , [ metadata ] ) ;
63
32
} ;
64
33
}
65
34
0 commit comments