This file contains hidden or 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
@Injectable() | |
export class TodosEffects { | |
@Effect() | |
public setTodos$ = this.actions$.pipe( | |
ofType(Actions.GET_TODOS), | |
exhaustMap(() => someService.getTodos()), | |
map((todos) => ({ | |
type: Actions.SET_TODOS, | |
payload: todos | |
})) |
This file contains hidden or 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
if (!this.effectsSubscription) { | |
this.effectsSubscription = this.effectSources.toActions().subscribe(this.store); | |
} |
This file contains hidden or 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
@Injectable() | |
export class TodosEffects { | |
@Effect() | |
public setTodos$ = this.actions$.pipe( | |
ofType(Actions.GET_TODOS), | |
exhaustMap(() => someService.getTodos()), | |
map((todos) => ({ | |
type: Actions.SET_TODOS, | |
payload: todos | |
})) |
This file contains hidden or 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
@Injectable() | |
export class AppEffects { | |
@Effect() | |
public setAppInformation$ = this.actions$.pipe( | |
ofType(Actions.GET_APP_INFORMATION), | |
tap(() => { | |
console.log(NgZone.isInAngularZone()); // true | |
}), | |
exhaustMap(() => forkJoin([apiRequest1, apiRequest2, apiRequest3])) | |
); |
This file contains hidden or 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
export interface EffectNotification { | |
effect: Observable<any> | (() => Observable<any>); | |
propertyName: string; | |
sourceName: string; | |
sourceInstance: any; | |
notification: Notification<Action | null | undefined>; | |
} |
This file contains hidden or 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
@Injectable() | |
export class TodosEffects { | |
@Effect() | |
public setTodos$ = this.actions$.pipe( | |
ofType(Actions.GET_TODOS), | |
exhaustMap(() => someService.getTodos()), | |
map((todos) => ({ | |
type: Actions.SET_TODOS, | |
payload: todos | |
})) |
This file contains hidden or 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
Promise.all([ | |
import('@ngxs/store'), | |
import('@ngxs/logger-plugin'), | |
import('@ngrx/store'), | |
import('@ngrx/effects'), | |
import('@ngrx/entity'), | |
import('@ngrx/store-devtools') | |
]).then((modules) => { | |
console.log(modules); |
This file contains hidden or 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
const META_KEY = 'NGXS_META'; | |
function State(options) { | |
return (target) => { | |
const meta = ensureStoreMetadata(target); | |
// Handle inheritance | |
if (Object.getPrototypeOf(target).hasOwnProperty(META_KEY)) { | |
const parentMeta = Object.getPrototypeOf(target)[META_KEY]; | |
meta.actions = Object.assign({}, meta.actions, parentMeta.actions); | |
} |
This file contains hidden or 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
function ensureStoreMetadata(target) { | |
if (!target.hasOwnProperty(META_KEY)) { | |
const defaultMetadata = { | |
name: null, | |
actions: {}, | |
defaults: {}, | |
path: null, | |
selectFromAppState: null, | |
children: [], | |
instance: null |
This file contains hidden or 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
function Action(actions, options) { | |
return function(target, name, descriptor) { | |
const meta = ensureStoreMetadata(target.constructor); | |
if (!Array.isArray(actions)) { | |
actions = [actions]; | |
} | |
for (const action of actions) { | |
const type = action.type; | |
if (!action.type) { | |
throw new Error( |