added remove actions to streams state

This commit is contained in:
Nicolas Constant 2019-01-29 22:33:31 -05:00
parent 730beea13a
commit f891b7bdbe
No known key found for this signature in database
GPG Key ID: 1E9F677FB01A5688
1 changed files with 30 additions and 1 deletions

View File

@ -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<StreamsStateModel>, 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<StreamsStateModel>, 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}`;
}
}