How to use the @ngxs/store.State function in @ngxs/store

To help you get started, we’ve selected a few @ngxs/store examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github mvdicarlo / postybirb / src / app / postybirb / stores / states / posty-birb.state.ts View on Github external
if (aDate < bDate) return -1;
    if (aDate > bDate) return 1;
    return 0;
  } else {
    // Always prioritize scheduled if mixed scenario
    if (a.meta.schedule && !b.meta.schedule) return 1;
    else return -1;
  }
}

class SaveState {
  static readonly type: string = '[PostyBirb] Save State';
  constructor(public state: PostyBirbSubmissionStateModel) { }
}

@State({
  name: 'postybirb',
  defaults: {
    editing: [],
    submissions: [],
  }
})
export class PostyBirbState implements NgxsOnInit {

  private saveSubject: Subject;

  constructor(private translate: TranslateService, private snotify: SnotifyService, private viewSubmissionManager: ViewSubmissionsManagerService) {
    this.saveSubject = new Subject();
    this.saveSubject.pipe(debounceTime(200)).subscribe((state) => {
      if (isDevMode()) console.log('Saving State', state);
      db.set('PostyBirbState', state || {
        editing: [],
github mflorence99 / el-term / renderer / app / state / layout.ts View on Github external
badge?: string;
  directory?: string;
  startup?: string;
  title?: string;
}

export interface LayoutSearch {
  str?: string;
  wrap?: boolean;
}

export interface LayoutStateModel {
  [tab: string]: Layout;
}

@State({
  name: 'layout',
  defaults: {
    // NOTE: this is the well-known ID of the "permanent" tab
    '0': LayoutState.defaultLayout()
  }
}) export class LayoutState {

  /** Create the default layout */
  static defaultLayout(): Layout {
    return {
      direction: 'vertical',
      id: UUID.UUID(),
      prefs: { } as LayoutPrefs,
      root: true,
      search: { } as LayoutSearch,
      size: 100,
github openradiation / openradiation-mobile / src / app / states / user / user.state.ts View on Github external
import { Action, NgxsOnInit, Selector, State, StateContext } from '@ngxs/store';
import { tap } from 'rxjs/operators';
import { StorageService } from '../../services/storage.service';
import { InitUser, LogIn, LogOut, SetLanguage } from './user.action';
import { UserService } from './user.service';

export interface UserStateModel {
  login?: string;
  password?: string;
  language?: string;
}

@State({
  name: 'user'
})
export class UserState implements NgxsOnInit {
  constructor(private userService: UserService, private storageService: StorageService) {}

  @Selector()
  static login({ login }: UserStateModel): string | undefined {
    return login;
  }

  @Selector()
  static language({ language }: UserStateModel): string | undefined {
    return language;
  }

  ngxsOnInit({ dispatch, patchState }: StateContext) {
github berta-cms / berta / editor / src / app / shop / settings / shop-settings-config.state.ts View on Github external
import { State, StateContext, NgxsOnInit, Selector } from '@ngxs/store';
import { ShopStateService } from '../shop-state.service';
import { take } from 'rxjs/operators';
import { AppState } from '../../app-state/app.state';
import { AppStateModel } from '../../app-state/app-state.interface';
import { initSettingConfigGroup } from '../../shared/helpers';

interface ShopSettingsConfigModel {
  [site: string]: any;
}

const defaultState: ShopSettingsConfigModel = {};


@State({
  name: 'shopSettingsConfig',
  defaults: defaultState
})
export class ShopSettingsConfigState implements NgxsOnInit {

  constructor(
    private stateService: ShopStateService) {
  }


  ngxsOnInit({ setState }: StateContext) {
    return this.stateService.getInitialState('', 'settingsConfig').pipe(
      take(1)
    ).subscribe((settingsConfig) => {
      const settingGroups = {};
github ngxs / store / integration / app / counter / counter.state.ts View on Github external
import { Action, NgxsAfterBootstrap, NgxsOnInit, State, StateContext } from '@ngxs/store';
import { CounterStateChangeAction } from '@integration/counter/counter.actions';

export interface CounterStateModel {
  loaded: boolean;
  count: number;
}

@State({
  name: 'counter',
  defaults: {
    loaded: false,
    count: 0
  }
})
export class CounterState implements NgxsOnInit, NgxsAfterBootstrap {
  public ngxsOnInit(ctx: StateContext): void {
    this.incrementAfterLoad(ctx);
  }

  public ngxsAfterBootstrap(ctx: StateContext): void {
    this.incrementAfterLoad(ctx);
  }

  @Action(CounterStateChangeAction)
github T-Systems-MMS / phonebook / Phonebook.Frontend / src / app / shared / states / LastPersons.state.ts View on Github external
export class SetLastPersons {
  public static readonly type: string = '[Last Persons] Set Persons';
  constructor(public persons: Person[]) {}
}

export class ResetLastPersons {
  public static readonly type: string = '[Last Persons] Reset';
}

export class RemoveFromLastPersons {
  public static readonly type: string = '[Last Persons] Remove Person';
  constructor(public person: Person) {}
}

@State({
  name: 'lastpersons',
  defaults: []
})
export class LastPersonsState {
  @Action(AddToLastPersons)
  public incrementPerson(ctx: StateContext, action: AddToLastPersons) {
    const state = ctx.getState();
    const index = state.findIndex(p => {
      return p.Id === action.person.Id;
    });
    if (index > -1) {
      //already contained
      state.splice(index, 1); //remove element
    }
    state.unshift(action.person);
    ctx.setState([...state]);
github berta-cms / berta / editor / src / app / sites / sections / entries / entries-state / section-entries.state.ts View on Github external
AddSiteEntriesAction,
  AddSectionEntriesAction,
  ResetSectionEntriesAction,
  InitSectionEntriesAction,
  UpdateSectionEntryFromSyncAction,
  OrderSectionEntriesFromSyncAction,
  DeleteSectionEntryFromSyncAction,
  UpdateEntryGalleryFromSyncAction,
  AddSectionEntryFromSyncAction,
  MoveSectionEntryFromSyncAction} from './section-entries.actions';
import { UserLoginAction } from '../../../../user/user.actions';
import { UpdateSiteSectionAction } from '../../sections-state/site-sections.actions';
import { UpdateSectionTagsAction } from '../../tags/section-tags.actions';


@State({
  name: 'sectionEntries',
  defaults: {}
})
export class SectionEntriesState implements NgxsOnInit {

  @Selector([AppState.getSite])
  static getCurrentSiteEntries(state, site): SectionEntry[] {
    const entries = state[site] || [];
    return entries;
  }

  constructor(
    private actions$: Actions,
    private appStateService: AppStateService) {
  }
github ngxs / schematics / src / templates / starter-kit / store / dashboard / index.ts View on Github external
import { State } from '@ngxs/store';
import { DictionaryState } from './states/dictionary/dictionary.state';
import { UserState } from './states/user/user.state';

export const DashboardStates = [DictionaryState, UserState];

@State({
  name: 'dashboardStateModule',
  children: DashboardStates
})
export class DashboardStateModule {}
github abpframework / abp / npm / ng-packs / packages / core / src / lib / states / profile.state.ts View on Github external
import { State, Action, StateContext, Selector } from '@ngxs/store';
import { GetProfile, ChangePassword, UpdateProfile } from '../actions/profile.actions';
import { Profile } from '../models/profile';
import { ProfileService } from '../services/profile.service';
import { tap } from 'rxjs/operators';

@State({
  name: 'ProfileState',
  defaults: {} as Profile.State,
})
export class ProfileState {
  @Selector()
  static getProfile({ profile }: Profile.State): Profile.Response {
    return profile;
  }

  constructor(private profileService: ProfileService) {}

  @Action(GetProfile)
  profileGet({ patchState }: StateContext) {
    return this.profileService.get().pipe(
      tap(profile =>
        patchState({
github mflorence99 / el-file / renderer / app / state / clipboard.ts View on Github external
constructor(public readonly payload: { paths: string[] }) { }
}

export class ValidateClipboard {
  static readonly type = '[Clipboard] validate';
  constructor(public readonly payload?: any) { }
}

export type ClipboardOp = 'clear' | 'copy' | 'cut';

export interface ClipboardStateModel {
  op: ClipboardOp;
  paths: string[];
}

@State({
  name: 'clipboard',
  defaults: {
    op: 'clear',
    paths: [],
  }
}) export class ClipboardState implements NgxsOnInit {

  @Selector() static getOp(state: ClipboardStateModel): ClipboardOp {
    return state.op;
  }

  @Selector() static getPaths(state: ClipboardStateModel): string[] {
    return state.paths;
  }

  /** ctor */