-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
089abdc
commit 38fc2f1
Showing
33 changed files
with
528 additions
and
568 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
import 'rxjs/add/operator/concat'; | ||
import { cold } from 'jasmine-marbles'; | ||
import { of } from 'rxjs/observable/of'; | ||
import { never } from 'rxjs/observable/never'; | ||
import { Effect, EffectSources } from '../'; | ||
|
||
|
||
describe('EffectSources', () => { | ||
let effectSources: EffectSources; | ||
|
||
beforeEach(() => { | ||
effectSources = new EffectSources(); | ||
}); | ||
|
||
it('should have an "addEffects" method to push new source instances', () => { | ||
const effectSource = { }; | ||
spyOn(effectSources, 'next'); | ||
|
||
effectSources.addEffects(effectSource); | ||
|
||
expect(effectSources.next).toHaveBeenCalledWith(effectSource); | ||
}); | ||
|
||
describe('toActions() Operator', () => { | ||
const a = { type: 'From Source A' }; | ||
const b = { type: 'From Source B' }; | ||
const c = { type: 'From Source C that completes' }; | ||
|
||
class SourceA { | ||
@Effect() a$ = alwaysOf(a); | ||
} | ||
|
||
class SourceB { | ||
@Effect() b$ = alwaysOf(b); | ||
} | ||
|
||
class SourceC { | ||
@Effect() c$ = of(c); | ||
} | ||
|
||
it('should resolve effects from instances', () => { | ||
const sources$ = cold('--a--', { a: new SourceA() }); | ||
const expected = cold('--a--', { a }); | ||
|
||
const output = toActions(sources$); | ||
|
||
expect(output).toBeObservable(expected); | ||
}); | ||
|
||
it('should ignore duplicate sources', () => { | ||
const sources$ = cold('--a--b--c--', { | ||
a: new SourceA(), | ||
b: new SourceA(), | ||
c: new SourceA(), | ||
}); | ||
const expected = cold('--a--------', { a }); | ||
|
||
const output = toActions(sources$); | ||
|
||
expect(output).toBeObservable(expected); | ||
}); | ||
|
||
function toActions(source: any) { | ||
return effectSources.toActions.call(source); | ||
} | ||
}); | ||
|
||
function alwaysOf<T>(value: T) { | ||
return of(value).concat(never<T>()); | ||
} | ||
}); |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
import { Effect, getSourceMetadata, getSourceForInstance } from '../src/effects_metadata'; | ||
|
||
describe('Effect Metadata', () => { | ||
describe('getSourceMetadata', () => { | ||
it('should get the effects metadata for a class instance', () => { | ||
class Fixture { | ||
@Effect() a: any; | ||
@Effect() b: any; | ||
@Effect({ dispatch: false }) c: any; | ||
} | ||
|
||
const mock = new Fixture(); | ||
|
||
expect(getSourceMetadata(mock)).toEqual([ | ||
{ propertyName: 'a', dispatch: true }, | ||
{ propertyName: 'b', dispatch: true }, | ||
{ propertyName: 'c', dispatch: false } | ||
]); | ||
}); | ||
|
||
it('should return an empty array if the class has not been decorated', () => { | ||
class Fixture { | ||
a: any; | ||
b: any; | ||
c: any; | ||
} | ||
|
||
const mock = new Fixture(); | ||
|
||
expect(getSourceMetadata(mock)).toEqual([]); | ||
}); | ||
}); | ||
|
||
describe('getSourceProto', () => { | ||
it('should get the prototype for an instance of a source', () => { | ||
class Fixture { } | ||
const instance = new Fixture(); | ||
|
||
const proto = getSourceForInstance(instance); | ||
|
||
expect(proto).toBe(Fixture.prototype); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import 'rxjs/add/observable/of'; | ||
import { Observable } from 'rxjs/Observable'; | ||
import { Effect, mergeEffects } from '../'; | ||
|
||
|
||
describe('mergeEffects', () => { | ||
|
||
}); |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
import { Observable } from 'rxjs/Observable'; | ||
import { of } from 'rxjs/observable/of'; | ||
import { NgModule, Component, Injectable } from '@angular/core'; | ||
import { platformDynamicServer } from '@angular/platform-server'; | ||
import { BrowserModule } from '@angular/platform-browser'; | ||
import { Store, StoreModule, combineReducers } from '../../../store'; | ||
import { EffectsModule, Effect, Actions } from '../../'; | ||
|
||
|
||
@Injectable() | ||
export class NgcSpecFeatureEffects { | ||
constructor(actions$: Actions) { } | ||
|
||
@Effect() run$ = of({ type: 'NgcSpecFeatureAction' }); | ||
} | ||
|
||
@NgModule({ | ||
imports: [ | ||
EffectsModule.forFeature([ NgcSpecFeatureEffects ]), | ||
] | ||
}) | ||
export class NgcSpecFeatureModule { } | ||
|
||
@Injectable() | ||
export class NgcSpecRootEffects { | ||
constructor(actions$: Actions) { } | ||
|
||
@Effect() run$ = of({ type: 'NgcSpecRootAction' }); | ||
} | ||
|
||
|
||
export interface AppState { | ||
count: number; | ||
} | ||
|
||
@Component({ | ||
selector: 'ngc-spec-component', | ||
template: ` | ||
<h1>Hello Effects</h1> | ||
` | ||
}) | ||
export class NgcSpecComponent { | ||
|
||
} | ||
|
||
@NgModule({ | ||
imports: [ | ||
BrowserModule, | ||
StoreModule.forRoot({ }), | ||
EffectsModule.forRoot([ NgcSpecRootEffects ]), | ||
NgcSpecFeatureModule, | ||
], | ||
declarations: [ | ||
NgcSpecComponent, | ||
], | ||
bootstrap: [ | ||
NgcSpecComponent, | ||
] | ||
}) | ||
export class NgcSpecModule {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
{ | ||
"compilerOptions": { | ||
"target": "ES5", | ||
"emitDecoratorMetadata": true, | ||
"experimentalDecorators": true, | ||
"module": "commonjs", | ||
"moduleResolution": "node", | ||
"outDir": "./output", | ||
"lib": ["es2015", "dom"], | ||
"baseUrl": ".", | ||
"paths": { | ||
"@ngrx/store": ["../../../store"] | ||
} | ||
}, | ||
"files": [ | ||
"ngc.spec.ts" | ||
], | ||
"angularCompilerOptions": { | ||
"genDir": "ngfactory" | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.