Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@ngxs-labs/select-snapshot

Package Overview
Dependencies
Maintainers
3
Versions
8
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@ngxs-labs/select-snapshot

  • 1.2.0
  • Source
  • npm
  • Socket score

Version published
Maintainers
3
Created
Source


Flexibile decorator, an alternative for the @Select but selects a snapshot of the state

@ngxs-labs/select-snapshot NPM License

📦 Install

To install @ngxs-labs/select-snapshot run the following command:

npm install @ngxs-labs/select-snapshot
# of if you use yarn
yarn add @ngxs-labs/select-snapshot

🔨 Usage

Import the NgxsSelectSnapshotModule into your root application module:

import { NgModule } from '@angular/core';
import { NgxsModule } from '@ngxs/store';
import { NgxsSelectSnapshotModule } from '@ngxs-labs/select-snapshot';

@NgModule({
  imports: [NgxsModule.forRoot(states), NgxsSelectSnapshotModule.forRoot()],
})
export class AppModule {}

Selecting snapshot

The @SelectSnapshot is just a simple decorator same as @Select. It allows you to decorate properties of your classes applying new getter and lets you to avoid injecting Store class everywhere. Simple example, let's create some tiny pandas state:

import { State, Action, StateContext } from '@ngxs/store';

class AddPanda {
  static type = '[Pandas] Add panda';
  constructor(public panda: string) {}
}

@State<string[]>({
  name: 'pandas',
  defaults: [],
})
export class PandasState {
  @Action(AddPanda)
  addPanda(ctx: StateContext<string[]>, action: AddPanda): void {
    const pandas = ctx.getState();
    ctx.setState([...pandas, action.panda]);
  }
}

Assume you've provided this state into your root NgxsModule and want already to try the @SelectSnapshot decorator:

import { Component } from '@angular/core';
import { SelectSnapshot } from '@ngxs-labs/select-snapshot';

import { PandasState } from './pandas.state';

@Component({
  selector: 'app-root',
  template: '<app-panda *ngFor="let panda of pandas" [panda]="panda"></app-panda>',
})
export class AppComponent {
  @SelectSnapshot(PandasState) pandas: string[];
}

The @SelectSnapshot decorator has the same API as the @Select decorator. It accepts state class, selector function, string or nothing as an argument.

Keywords

FAQs

Package last updated on 18 Apr 2020

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc