added remove actions to streams state
This commit is contained in:
parent
730beea13a
commit
f891b7bdbe
|
@ -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}`;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue