From f891b7bdbe14781834042235c49b87e3a8bc99d6 Mon Sep 17 00:00:00 2001 From: Nicolas Constant Date: Tue, 29 Jan 2019 22:33:31 -0500 Subject: [PATCH] added remove actions to streams state --- src/app/states/streams.state.ts | 31 ++++++++++++++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) diff --git a/src/app/states/streams.state.ts b/src/app/states/streams.state.ts index 8b2ee20b..517b10da 100644 --- a/src/app/states/streams.state.ts +++ b/src/app/states/streams.state.ts @@ -5,6 +5,16 @@ export class AddStream { constructor(public stream: StreamElement) {} } +export class RemoveAllStreams { + static readonly type = '[Streams] Remove all streams'; + constructor(public accountId :string) {} +} + +export class RemoveStream { + static readonly type = '[Streams] Remove stream'; + constructor(public streamId :string) {} +} + export interface StreamsStateModel { streams: StreamElement[]; } @@ -23,16 +33,35 @@ export class StreamsState { streams: [...state.streams, action.stream] }); } + @Action(RemoveAllStreams) + RemoveAllStreams(ctx: StateContext, action: RemoveAllStreams){ + const state = ctx.getState(); + const filteredStreams = state.streams.filter(x => x.accountId !== action.accountId); + ctx.patchState({ + streams: [...filteredStreams] + }); + } + @Action(RemoveStream) + RemoveStream(ctx: StateContext, action: RemoveStream){ + const state = ctx.getState(); + const filteredStreams = state.streams.filter(x => x.id !== action.streamId); + ctx.patchState({ + streams: [...filteredStreams] + }); + } } export class StreamElement { + public id: string; + constructor( public type: StreamTypeEnum, public name: string, public accountId: string, public tag: string, public list: string, - public displayableFullName: string) { + public displayableFullName: string) { + this.id = `${type}-${name}-${accountId}`; } }