How to use @ngxs/store - 10 common examples

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-aws / renderer / app / pages / s3 / ctrl.ts View on Github external
private handleActions(): void {
    // listen for open prefs
    this.subToShowPagePrefs = this.actions$.pipe(ofAction(ShowPagePrefs))
      .subscribe(() => this.openView.emit());
    // clean up on a reset
    this.subToReset = this.actions$.pipe(ofAction(Reset))
      .subscribe(() => this.store.dispatch(new ClearPaths()));
    // cancel long-running operation
    this.subToCancel = this.actions$.pipe(ofAction(Canceled))
      .subscribe(() => {
        this.zone.run(() => {
          this.store.dispatch(new Progress({ state: 'completed' }));
          this.s3Svc.cancelUpload();
        });
      });
  }
github mflorence99 / el-aws / renderer / app / pages / s3 / ctrl.ts View on Github external
private handleActions(): void {
    // listen for open prefs
    this.subToShowPagePrefs = this.actions$.pipe(ofAction(ShowPagePrefs))
      .subscribe(() => this.openView.emit());
    // clean up on a reset
    this.subToReset = this.actions$.pipe(ofAction(Reset))
      .subscribe(() => this.store.dispatch(new ClearPaths()));
    // cancel long-running operation
    this.subToCancel = this.actions$.pipe(ofAction(Canceled))
      .subscribe(() => {
        this.zone.run(() => {
          this.store.dispatch(new Progress({ state: 'completed' }));
          this.s3Svc.cancelUpload();
        });
      });
  }
github mflorence99 / el-aws / renderer / app / pages / s3 / ctrl.ts View on Github external
private handleActions(): void {
    // listen for open prefs
    this.subToShowPagePrefs = this.actions$.pipe(ofAction(ShowPagePrefs))
      .subscribe(() => this.openView.emit());
    // clean up on a reset
    this.subToReset = this.actions$.pipe(ofAction(Reset))
      .subscribe(() => this.store.dispatch(new ClearPaths()));
    // cancel long-running operation
    this.subToCancel = this.actions$.pipe(ofAction(Canceled))
      .subscribe(() => {
        this.zone.run(() => {
          this.store.dispatch(new Progress({ state: 'completed' }));
          this.s3Svc.cancelUpload();
        });
      });
  }
github mflorence99 / el-aws / renderer / app / pages / ddb / ctrl.ts View on Github external
private handleActions(): void {
    // listen for open prefs
    this.subToShowPagePrefs = this.actions$.pipe(ofAction(ShowPagePrefs))
      .subscribe(() => this.openView.emit());
  }
github ngxs / store / packages / devtools-plugin / src / devtools.plugin.ts View on Github external
private sendToDevTools(state: any, action: any, newState: any) {
    const type = getActionTypeFromInstance(action);
    // if init action, send initial state to dev tools
    const isInitAction = type === '@@INIT';
    if (isInitAction) {
      this.devtoolsExtension!.init(state);
    } else {
      this.devtoolsExtension!.send({ ...action, type }, newState);
    }
  }
github phucan1108 / letportal / src / web-portal / src / app / modules / portal / modules / chat / components / chat-warpper / chat-wrapper.component.ts View on Github external
ngOnInit(): void {
        
        this.sup.add(this.actions$.pipe(
            ofActionCompleted(GotHubChatProblem)
        ).subscribe(() => {
            // Display error about chat server's problem
        }))
        this.sup.add(
            this.actions$.pipe(
                ofActionSuccessful(ActiveDoubleChatRoom),
            ).subscribe(
                () => {
                    if(!this.isShowChatBox)
                        this.isShowChatBox = true
                }
            )
        )
        this.sup.add(this.chatState$.pipe(
            filter(state => ObjectUtils.isNotNull(state.currentUser)),
            tap(
github berta-cms / berta / editor / src / app / sites / settings / site-settings.state.ts View on Github external
if (child.slug !== slug) {
                      return child;
                    }

                    return { ...child, value: response.value };
                  });
                })};
              })
            };
          })});
        }
      })
    );
  }

  @Action(RenameSiteSettingsSitenameAction)
  renameSiteSettingsSitename({ setState, getState }: StateContext, action: RenameSiteSettingsSitenameAction) {
    const state = getState();
    const newState = {};

    /* Using the loop to retain the element order in the map */
    for (const siteName in state) {
      if (siteName === action.site.name) {
        newState[action.siteName] = state[siteName];
      } else {
        newState[siteName] = state[siteName];
      }
    }

    setState(newState);
  }
github mflorence99 / el-aws / renderer / app / pages / s3 / components / select-bucket.ts View on Github external
changeDetection: ChangeDetectionStrategy.OnPush,
  selector: 'elaws-select-bucket',
  templateUrl: 'select-bucket.html',
  styleUrls: ['select-bucket.scss']
})

export class SelectBucketComponent implements ControlValueAccessor,
                                              MatFormFieldControl,
                                              OnDestroy {

  static nextID = 0;

  @HostBinding('attr.aria-describedby') describedBy = '';
  @HostBinding() id = `elaws-select-bucket-${SelectBucketComponent.nextID++}`;

  @Select(S3State.getBuckets) buckets$: Observable;

  // @see MatFormFieldControl
  controlType = 'elaws-select-bucket';
  focused = false;
  shouldLabelFloat = false;
  stateChanges = new Subject();

  selectBucketForm: FormGroup;

  // disabled accessor / mutator

  @Input() get disabled(): boolean {
    return this._disabled;
  }

  set disabled(disabled: boolean) {
github fisenkodv / itinerary / src / app / modules / places / state / filter.state.ts View on Github external
name: 'filter',
  defaults: {
    location: { latitude: 39.833333, longitude: -98.583333 }, // default location is 'Geographic center of the contiguous United States'
    distance: 50,
    rating: 4,
    reviews: 100
  },
  children: [AutocompleteState]
})
export class FilterState {
  @Selector()
  public static filter(state: FilterStateModel): FilterStateModel {
    return state;
  }

  @Selector()
  public static location(state: FilterStateModel): Location {
    return state.location;
  }

  @Selector()
  public static distance(state: FilterStateModel): number {
    return state.distance;
  }

  @Action(SetLocation)
  setLocation({ getState, setState }: StateContext, { payload }: SetLocation) {
    setState({ ...getState(), location: payload });
  }

  @Action(SetDistance)
  setDistance({ getState, setState }: StateContext, { payload }: SetDistance) {