Skip to content

Commit

Permalink
Simplify Effects
Browse files Browse the repository at this point in the history
  • Loading branch information
MikeRyanDev committed May 10, 2017
1 parent 089abdc commit 38fc2f1
Show file tree
Hide file tree
Showing 33 changed files with 528 additions and 568 deletions.
2 changes: 1 addition & 1 deletion modules/effects/spec/actions.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import 'rxjs/add/operator/map';
import 'rxjs/add/observable/of';
import { ReflectiveInjector } from '@angular/core';
import { Action, StoreModule, ScannedActionsSubject, ActionsSubject } from '@ngrx/store';
import { Actions } from '../src/actions';
import { Actions } from '../';


describe('Actions', function() {
Expand Down
71 changes: 71 additions & 0 deletions modules/effects/spec/effect_sources.spec.ts
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>());
}
});
67 changes: 0 additions & 67 deletions modules/effects/spec/effects-subscription.spec.ts

This file was deleted.

26 changes: 0 additions & 26 deletions modules/effects/spec/effects.spec.ts

This file was deleted.

44 changes: 44 additions & 0 deletions modules/effects/spec/effects_metadata.spec.ts
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);
});
});
});
8 changes: 8 additions & 0 deletions modules/effects/spec/effects_resolver.spec.ts
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', () => {

});
3 changes: 0 additions & 3 deletions modules/effects/spec/index.spec.ts

This file was deleted.

31 changes: 0 additions & 31 deletions modules/effects/spec/metadata.spec.ts

This file was deleted.

60 changes: 60 additions & 0 deletions modules/effects/spec/ngc/ngc.spec.ts
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 {}
21 changes: 21 additions & 0 deletions modules/effects/spec/ngc/tsconfig.ngc.json
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"
}
}
32 changes: 0 additions & 32 deletions modules/effects/spec/singleton-effects.service.spec.ts

This file was deleted.

Loading

0 comments on commit 38fc2f1

Please sign in to comment.