本文整理汇总了TypeScript中react-router-redux.replace函数的典型用法代码示例。如果您正苦于以下问题:TypeScript replace函数的具体用法?TypeScript replace怎么用?TypeScript replace使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了replace函数的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: received
function* received(response: AuthResponse) {
storeAuthToken(response.token);
yield put<Action>({ type: 'RECEIVED_REGISTRATION', token: response.token });
const state: Store.All = yield select();
if (state.location.referrer) {
yield put(replace(state.location.referrer));
} else {
yield put(replace('/'));
}
}
示例2: async
export const getDashboardAsync = (dashboardID: string) => async (
dispatch
): Promise<void> => {
try {
// Fetch the dashboard and all variables a user has access to
const [dashboard] = await Promise.all([
getDashboardAJAX(dashboardID),
dispatch(getVariables()),
])
// Fetch all the views in use on the dashboard
const views = await Promise.all(
dashboard.cells.map(cell => getViewAJAX(dashboard.id, cell.id))
)
dispatch(setViews(RemoteDataState.Done, views))
// Ensure the values for the variables in use on the dashboard are populated
await dispatch(refreshDashboardVariableValues(dashboard, views))
// Now that all the necessary state has been loaded, set the dashboard
dispatch(setDashboard(dashboard))
} catch {
dispatch(replace(`/dashboards`))
dispatch(notify(copy.dashboardGetFailed(dashboardID)))
return
}
dispatch(updateTimeRangeFromQueryParams(dashboardID))
}
示例3: dispatch
action.then(dispatch => {
const atHeader = action.sectionName === "header";
if (state.activeSection !== action.sectionName) {
dispatch(new SetRemoteMenuButtonVisibility(!atHeader));
const urlSegment = atHeader ? "" : action.sectionName;
dispatch(replace(urlSegment));
}
});
示例4: tryOrNotify
tryOrNotify(async () => {
if (token) {
try {
await Api.registerToken(listId, token)
} catch (error) {
showError(error)
dispatch(replace('/'))
return
}
}
const accessStatus = await Api.checkSharedListAccess(listId)
switch (accessStatus) {
case AccessStatus.NotInvited:
showError('Du er ikke invitert til denne listen')
// TODO: Egen side for å be om tilgang
dispatch(replace('/'))
return
case AccessStatus.Owner:
dispatch(replace('/'))
return
case AccessStatus.Invited:
dispatch(setAuthorized())
break
}
dispatch(loadSharedList(listId))
const idToken = loadIdToken()
listHub = new HubConnection(`${document.location.origin}/listHub?id_token=${idToken}`)
const updateUsers = (data) => {
dispatch(setUsers(Immutable(normalize(data.currentUsers, schemas.users))))
}
listHub.on('updateUsers', updateUsers)
listHub.on('refresh', () => {
dispatch(loadSharedList(listId))
dispatch(loadMessages(listId))
})
await listHub.start()
const users = await listHub.invoke('subscribe', listId)
updateUsers(users)
})
示例5: handleError
export function* handleError(error: IUnkownError, prefix?: string) {
if (error.status === 401) {
yield storeCurrentLocation();
yield loggedOut();
yield put(showError('Authentication expired'));
yield put(replace('/login'));
} else {
const label = prefix ? `${prefix}: ` : '';
const message = `${label}${JSON.stringify(error.result)}`;
yield put(showError(message));
}
}
示例6: async
export const getDashboardAsync = (dashboardID: string) => async (
dispatch
): Promise<void> => {
try {
const dashboard = await getDashboardAJAX(dashboardID)
dispatch(loadDashboard(dashboard))
} catch {
dispatch(replace(`/dashboards`))
dispatch(notify(copy.dashboardNotFound(dashboardID)))
return
}
dispatch(updateTimeRangeFromQueryParams(dashboardID))
}
示例7: stripPrefix
export const updateQueryParams = (updatedQueryParams: object): RouterAction => {
const {search, pathname} = window.location
const strippedPathname = stripPrefix(pathname)
const newQueryParams = _.pickBy(
{
...qs.parse(search, {ignoreQueryPrefix: true}),
...updatedQueryParams,
},
v => !!v
)
const newSearch = qs.stringify(newQueryParams)
const newLocation = {pathname: strippedPathname, search: `?${newSearch}`}
return replace(newLocation)
}
示例8: gameSaga
/**
* game-saga负责管理整体游戏进度
* 负责管理游戏开始界面, 游戏结束界面
* game-stage调用stage-saga来运行不同的关卡
* 并根据stage-saga返回的结果选择继续下一个关卡, 或是选择游戏结束
*/
export default function* gameSaga(action: actions.StartGame | actions.ResetGame) {
if (action.type === A.ResetGame) {
DEV.LOG && console.log('GAME RESET')
return
}
// 这里的 delay(0) 是为了「异步执行」后续的代码
// 以保证后续代码执行前已有的cancel逻辑执行完毕
yield delay(0)
DEV.LOG && console.log('GAME STARTED')
const players = [playerSaga('player-1', PLAYER_CONFIGS.player1)]
if (yield select(selectors.isInMultiPlayersMode)) {
players.push(playerSaga('player-2', PLAYER_CONFIGS.player2))
}
const result = yield race({
tick: tickEmitter({ bindESC: true }),
players: all(players),
ai: botMasterSaga(),
powerUp: powerUpManager(),
bullets: bulletsSaga(),
// 上面几个 saga 在一个 gameSaga 的生命周期内被认为是后台服务
// 当 stage-flow 退出(或者是用户直接离开了game-scene)的时候,自动取消上面几个后台服务
flow: stageFlow(action.stageIndex),
leave: take(A.LeaveGameScene),
})
if (DEV.LOG) {
if (result.leave) {
console.log('LEAVE GAME SCENE')
}
}
if (result.flow) {
DEV.LOG && console.log('GAME ENDED')
const { router }: State = yield select()
yield put(replace(`/gameover${router.location.search}`))
}
yield put(actions.beforeEndGame())
yield put(actions.endGame())
}
示例9: stageSaga
/**
* stage-saga的一个实例对应一个关卡
* 在关卡开始时, 一个stage-saga实例将会启动, 负责关卡地图生成
* 在关卡过程中, 该saga负责统计该关卡中的战斗信息
* 当玩家清空关卡时stage-saga退出, 并向game-saga返回该关卡结果
*/
export default function* stageSaga(stage: StageConfig) {
const { router }: State = yield select()
yield put(replace(`/stage/${stage.name}${router.location.search}`))
try {
yield animateCurtainAndLoadMap(stage)
yield put(actions.beforeStartStage(stage))
yield put(actions.showHud())
yield put(actions.startStage(stage))
while (true) {
const action: actions.Action = yield take([A.SetTankToDead, A.DestroyEagle])
if (action.type === A.SetTankToDead) {
const tank: TankRecord = yield select(selectors.tank, action.tankId)
if (tank.side === 'bot') {
if (yield select(selectors.isAllBotDead)) {
yield Timing.delay(DEV.FAST ? 1000 : 4000)
yield animateStatistics()
yield put(actions.beforeEndStage())
yield put(actions.endStage())
return { pass: true } as StageResult
}
} else {
if (yield select(selectors.isAllPlayerDead)) {
yield Timing.delay(DEV.FAST ? 1000 : 3000)
yield animateStatistics()
// 因为 gameSaga 会 put END_GAME 所以这里不需要 put END_STAGE
return { pass: false, reason: 'dead' } as StageResult
}
}
} else if (action.type === A.DestroyEagle) {
// 因为 gameSaga 会 put END_GAME 所以这里不需要 put END_STAGE
return { pass: false, reason: 'eagle-destroyed' } as StageResult
}
}
} finally {
yield put(actions.hideHud())
}
}
示例10: Date
"signup", (input: ISignupInput, dispatch, getState, deps) => {
const birthdate = new Date(input.year, input.month, input.day);
const ageDiffMs = Date.now() - birthdate.getTime();
const ageDate = new Date(ageDiffMs);
const age = Math.abs(ageDate.getUTCFullYear() - 1970);
if (age < 13) {
dispatch(replace({
pathname: "/",
state: {
keepMessage: true
}
}));
dispatch(show(__("You have to be 13 years or older to play Impera."), MessageType.error));
// Set cookie
document.cookie = `age_block=${input.username};path=/`;
return;
}
return {
payload: {
promise: deps.getCachedClient(FixedAccountClient).register({
userName: input.username,
password: input.password,
confirmPassword: input.passwordConfirm,
email: input.email,
language: getState().session.language || "en",
callbackUrl: `${baseUri}activate/userId/code`
})
},
options: {
useMessage: true,
afterSuccess: d => d(replace("/signup/confirmation"))
}
};
});