Skip to content

Instantly share code, notes, and snippets.

@beeman
Last active March 26, 2018 19:27
Show Gist options
  • Save beeman/4d650c1516e1b3ad2fc583d367c04501 to your computer and use it in GitHub Desktop.
Save beeman/4d650c1516e1b3ad2fc583d367c04501 to your computer and use it in GitHub Desktop.
import { Action, State } from '@ngxs/store';
export type alertTypes = 'info' | 'success' | 'danger' | 'warning';
export interface AlertPayload {
title: string;
type: alertTypes;
}
export class Alert {
constructor(private payload: AlertPayload) {}
}
export class AlertDismiss {
constructor(private payload: AlertPayload) {}
}
@State({
name: 'alerts',
defaults: []
})
export class AlertState {
@Action(Alert)
alert({ getState, setState}, { payload }) {
setState([...getState(), payload]);
}
@Action(AlertDismiss)
alertDismiss({ getState, setState}, { payload }) {
setState([...getState().filter(alert => alert !== payload)]);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment