Last active
March 26, 2018 19:27
-
-
Save beeman/4d650c1516e1b3ad2fc583d367c04501 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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