本文整理汇总了TypeScript中common/reducers/reducer.default函数的典型用法代码示例。如果您正苦于以下问题:TypeScript default函数的具体用法?TypeScript default怎么用?TypeScript default使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了default函数的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: on
export default reducer<SetupState>(initialState, on => {
on(actions.setupStatus, (state, action) => {
const blockingOperation = action.payload;
return {
...state,
errors: [],
blockingOperation,
};
});
on(actions.setupOperationProgress, (state, action) => {
let { blockingOperation } = state;
const { progress } = action.payload;
if (blockingOperation) {
blockingOperation = {
...blockingOperation,
progressInfo: progress,
};
}
return {
...state,
blockingOperation,
};
});
on(actions.setupDone, (state, action) => {
return {
...state,
done: true,
errors: [],
blockingOperation: null,
};
});
});
示例2: on
import { actions } from "common/actions";
import reducer from "common/reducers/reducer";
const initialState: string[] = [];
export default reducer<string[]>(initialState, on => {
on(actions.pushItchioURI, (state, action) => {
const { uri } = action.payload;
return [...state, uri];
});
on(actions.clearItchioURIs, (state, action) => {
return [];
});
});
示例3: on
import { actions } from "common/actions";
import reducer from "common/reducers/reducer";
import { CommonsState } from "common/types";
const initialState: CommonsState = {
downloadKeys: {},
downloadKeyIdsByGameId: {},
caves: {},
caveIdsByGameId: {},
locationSizes: {},
};
export default reducer<CommonsState>(initialState, on => {
// TODO: be much smarter+faster here.
// this is a good place to dedupe updates if records
// are deepEqual
on(actions.commonsUpdated, (state, action) => {
const data = action.payload;
return {
...state,
...data,
};
});
});
示例4: reject
import { reject } from "underscore";
import { IModalsState } from "common/types";
import { actions } from "common/actions";
import reducer from "common/reducers/reducer";
const initialState: IModalsState = [];
export default reducer<IModalsState>(initialState, on => {
on(actions.openModal, (state, action) => {
const modal = action.payload;
return [modal, ...state];
});
on(actions.updateModalWidgetParams, (state, action) => {
const { id, widgetParams } = action.payload;
return state.map(modal => {
if (modal.id === id) {
return { ...modal, widgetParams };
}
return modal;
});
});
on(actions.modalClosed, (state, action) => {
const { id } = action.payload;
return reject(state, modal => modal.id === id);
});
});
示例5: on
const OFFLINE_MODE = process.env.OFFLINE_MODE === "1";
export const initialState = {
downloadSelfUpdates: true,
offlineMode: OFFLINE_MODE,
installLocations: {},
defaultInstallLocation: "appdata",
isolateApps: false,
closeToTray: true,
readyNotification: true,
showAdvanced: false,
openAtLogin: false,
openAsHidden: false,
manualGameUpdates: false,
preventDisplaySleep: true,
preferOptimizedPatches: false,
disableBrowser: env.integrationTests ? true : false,
enableTabs: false,
} as PreferencesState;
export default reducer<PreferencesState>(initialState, on => {
on(actions.updatePreferences, (state, action) => {
const record = action.payload;
return {
...state,
...record,
};
});
});
示例6: on
import { actions } from "common/actions";
import reducer from "common/reducers/reducer";
import { SystemTasksState } from "common/types";
const seconds = 1000;
const initialState = {
nextComponentsUpdateCheck: Date.now() + 15 * seconds,
nextGameUpdateCheck: Date.now() + 30 * seconds,
} as SystemTasksState;
export default reducer<SystemTasksState>(initialState, on => {
on(actions.scheduleSystemTask, (state, action) => {
const { payload } = action;
return {
...state,
...payload,
};
});
});
示例7: on
export default reducer<NavigationState>(initialState, on => {
on(actions.tabOpened, (state, action) => {
const { tab, background } = action.payload;
if (!tab) {
return state;
}
// Try to open the new tab to the right of the current tab.
// Note that, at the time of this writing, Chrome 69 does something
// smarter. It behaves as if it keeps track of which tab has been
// opened by whom. So if you have
// - A B C
// And B opens two tabs, you'll have:
// - A B C
// - A B B1 C
// - A B B1 B2 C
// Whereas the following code doesn't keep track of that, so we'll have:
// - A B C
// - A B B1 C
// - A B B2 B1 C
// and so on. Fixing that would require changing the structure of the app's
// state, so let's not worry about it for now.
const { openTabs } = state;
let newOpenTabs = [];
let added = false;
for (const openTab of openTabs) {
newOpenTabs.push(openTab);
if (openTab === state.tab) {
added = true;
newOpenTabs.push(tab);
}
}
if (!added) {
// if we didn't find the current tab
// then we just append it
newOpenTabs.push(tab);
}
return {
...state,
tab: background ? state.tab : tab,
openTabs: newOpenTabs,
};
});
on(actions.tabFocused, (state, action) => {
const { tab } = action.payload;
return {
...state,
tab,
};
});
on(actions.moveTab, (state, action) => {
const { before, after } = action.payload;
const { openTabs } = state;
const newOpenTabs = arrayMove(openTabs, before, after);
return {
...state,
openTabs: newOpenTabs,
};
});
on(actions.tabsClosed, (state, action) => {
const { tabs, andFocus } = action.payload;
return {
...state,
openTabs: difference(state.openTabs, tabs),
tab: andFocus ? andFocus : state.tab,
};
});
on(actions.tabsRestored, (state, action) => {
const { snapshot } = action.payload;
const tab = snapshot.current || state.tab;
const openTabs = filter(
map(snapshot.items, (tab: TabDataSave) => {
return tab.id;
}),
x => !!x
);
return {
...state,
tab,
openTabs,
};
});
on(actions.loggedOut, (state, action) => {
return initialState;
});
});
示例8: on
export default reducer<GameUpdatesState>(initialState, on => {
on(actions.gameUpdateCheckStatus, (state, action) => {
const { checking, progress } = action.payload;
return {
...state,
checking,
progress,
};
});
on(actions.gameUpdateAvailable, (state, action) => {
const { update } = action.payload;
return {
...state,
updates: {
...state.updates,
[update.caveId]: update,
},
};
});
on(actions.queueGameUpdate, (state, action) => {
const { update } = action.payload;
return {
...state,
updates: omit(state.updates, update.caveId),
};
});
on(actions.snoozeCave, (state, action) => {
const { caveId } = action.payload;
return {
...state,
updates: omit(state.updates, caveId),
};
});
});
示例9: on
const baseReducer = reducer<TasksState>(initialState, on => {
on(actions.taskStarted, (state, action) => {
const task = action.payload;
return {
...state,
tasks: {
...state.tasks,
[task.id]: {
...task,
progress: 0,
},
},
};
});
on(actions.taskProgress, (state, action) => {
const record = action.payload;
const { id } = record;
const task = state.tasks[id];
if (!task) {
return state;
}
return {
...state,
tasks: {
...state.tasks,
[id]: {
...task,
...record,
},
},
};
});
on(actions.taskEnded, (state, action) => {
const { id } = action.payload;
return {
...state,
tasks: omit(state.tasks, id),
finishedTasks: [state.tasks[id], ...state.finishedTasks],
};
});
});
示例10: trimHistory
const baseReducer = reducer<TabInstance>(initialState, on => {
on(actions.tabPageUpdate, (state, action) => {
const { page } = action.payload;
let oldPage = state.history[state.currentIndex];
if (page.url && oldPage.url && page.url !== oldPage.url) {
// ignore page update for another URL
return state;
}
let newHistory = [...state.history];
newHistory[state.currentIndex] = { ...oldPage, ...page };
return {
...omit(state, "sleepy"),
history: newHistory,
};
});
on(actions.evolveTab, (state, action) => {
const { onlyIfMatchingURL } = action.payload;
let { url, resource, label, replace } = action.payload;
let { history, currentIndex } = state;
if (history[currentIndex].url === url) {
replace = true;
} else if (onlyIfMatchingURL) {
return state;
}
if (resource && /^collections\//.test(resource)) {
url = `itch://${resource}`;
}
if (!resource && replace) {
// keep the resource in case it's not specified
resource = history[currentIndex].resource;
}
if (!label && replace) {
label = history[currentIndex].label;
}
if (replace) {
history = [...history];
history[currentIndex] = {
...history[currentIndex],
url,
resource: resource || history[currentIndex].resource,
};
} else {
history = [
...history.slice(0, currentIndex + 1),
{ url, resource, label },
];
currentIndex = history.length - 1;
}
// merge old & new data
let newState: TabInstance = {
...state,
history,
currentIndex,
};
return trimHistory(newState);
});
on(actions.tabWentToIndex, (state, action) => {
const { index } = action.payload;
if (index >= 0 && index < state.history.length) {
let newState = {
...state,
currentIndex: index,
};
let newPage = newState.history[newState.currentIndex];
newState.history = [...newState.history];
newState.history[newState.currentIndex] = {
...newPage,
restoredScrollTop: newPage.scrollTop,
};
// now I know what you're thinking "whoa hold on, that code above looks silly"
// well, we can't just assign `newState.history` without making it a new
// object - if we don't have reference equality, we have nothing.
return newState;
}
return state;
});
on(actions.tabLosingWebContents, (state, action) => {
return {
...state,
loading: false,
};
});
on(actions.tabLoadingStateChanged, (state, action) => {
const { loading } = action.payload;
return {
//.........这里部分代码省略.........