本文整理汇总了TypeScript中@ngxs/store.StateContext类的典型用法代码示例。如果您正苦于以下问题:TypeScript StateContext类的具体用法?TypeScript StateContext怎么用?TypeScript StateContext使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了StateContext类的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: updateSelectedStorage
@Action(BrowseStoragesSelectStorage)
updateSelectedStorage(ctx: StateContext<BrowseStoragesStateModel>, {payload}: BrowseStoragesSelectStorage) {
ctx.patchState({
...ctx.getState(),
selectedStorage: payload
});
}
示例2: receiveEvent
@Action(ObsDispatchEvent)
receiveEvent(ctx: StateContext<SourceModel[]>, action: ObsDispatchEvent) {
if (action.payload['update-type']) {
this.processUpdateEvent(ctx, action);
return;
}
const { id, actionType } = this.service.getActionType(action.payload);
const state = ctx.getState();
switch (actionType) {
case 'GetSceneList':
action.payload.scenes
.filter(s => s.name === action.payload['current-scene'])
.map(scene => ctx.setState([...scene.sources]));
ctx.dispatch(new GetSourceMuteState());
break;
case 'GetCurrentScene':
ctx.setState([...action.payload.sources]);
ctx.dispatch(new GetSourceMuteState());
break;
case 'ToggleMute':
case 'GetMute':
const sources = state.map(source => {
if (source.name === action.payload.name) {
source.muted = action.payload.muted;
}
return source;
});
ctx.setState([...sources]);
break;
}
}
示例3: processUpdateEvent
private processUpdateEvent(
ctx: StateContext<SourceModel[]>,
action: ObsDispatchEvent
) {
const state = ctx.getState();
switch (action.payload['update-type']) {
case 'SwitchScenes':
ctx.setState([...action.payload.sources]);
ctx.dispatch(new GetSourceMuteState());
break;
case 'SceneItemVisibilityChanged':
const newstate = state.map(x => {
if (x.name === action.payload['item-name']) {
x.render = action.payload['item-visible'];
}
return x;
});
ctx.setState([...newstate]);
break;
case 'SceneItemAdded':
case 'SceneItemRemoved':
case 'SourceOrderChanged':
ctx.dispatch(new GetCurrentScene());
break;
}
}
示例4: toggleStorageSearchInput
@Action(BrowseStoragesToggleStoragesSearchInput)
toggleStorageSearchInput(ctx: StateContext<BrowseStoragesStateModel>) {
ctx.patchState({
...ctx.getState(),
showStoragesSearch: !ctx.getState().showStoragesSearch
});
}
示例5: gettDisplayUrl
@Action(SetDisplayUrl)
gettDisplayUrl(ctx: StateContext<CaptionPanelModel>, action: SetDisplayUrl) {
const currentState = ctx.getState();
ctx.setState({
...currentState,
displayUrl: `${location.origin}/main/caption/display/${currentState.uid}`
});
}
示例6: logout
@Action(LogoutAction)
logout(ctx: StateContext<SessionStateModel>) {
if (ctx.getState().state === 'authenticated') {
ctx.setState(defaultSessionState);
localStorage.setItem('session', JSON.stringify(defaultSessionState));
this.store.dispatch(new HideSideNavAction());
this.store.dispatch(new Navigate(['/']));
}
}
示例7: deleteStorage
@Action(BrowseStoragesDeleteStorage)
deleteStorage(ctx: StateContext<BrowseStoragesStateModel>, {id}: BrowseStoragesDeleteStorage) {
ctx.patchState({
...ctx.getState(),
storages: [
...ctx.getState().storages.filter((s) => s.id !== id)
]
});
}
示例8: addStorage
@Action(BrowseStoragesAddStorage)
addStorage(ctx: StateContext<BrowseStoragesStateModel>, {storage}: BrowseStoragesAddStorage) {
ctx.patchState({
...ctx.getState(),
storages: [
...ctx.getState().storages,
storage
].sort((a, b) => a.id.toLocaleLowerCase().localeCompare(b.id.toLocaleLowerCase()))
});
}
示例9: getPurchase
@Action(GetPurchaseAction)
async getPurchase(ctx: StateContext<PurchaseStateModel>, action: GetPurchaseAction) {
let purchases: Array<Purchase> = await this.purchaseService.getPurchase(action.date);
const state = ctx.getState();
ctx.setState({
...state,
purchases
});
}
示例10: tap
tap((storages: StorageEntity[]) => {
const state = ctx.getState();
ctx.patchState({
...state,
storages: storages,
loadingStorages: false,
});
})