Skip to content

Instantly share code, notes, and snippets.

View arturovt's full-sized avatar
🎯

Artur arturovt

🎯
View GitHub Profile
@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
}))
if (!this.effectsSubscription) {
this.effectsSubscription = this.effectSources.toActions().subscribe(this.store);
}
@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
}))
@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]))
);
export interface EffectNotification {
effect: Observable<any> | (() => Observable<any>);
propertyName: string;
sourceName: string;
sourceInstance: any;
notification: Notification<Action | null | undefined>;
}
@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
}))
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);
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);
}
function ensureStoreMetadata(target) {
if (!target.hasOwnProperty(META_KEY)) {
const defaultMetadata = {
name: null,
actions: {},
defaults: {},
path: null,
selectFromAppState: null,
children: [],
instance: null
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(