本文整理匯總了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"))
}
};
});