本文整理匯總了TypeScript中typescript-fsa-reducers.reducerWithInitialState函數的典型用法代碼示例。如果您正苦於以下問題:TypeScript reducerWithInitialState函數的具體用法?TypeScript reducerWithInitialState怎麽用?TypeScript reducerWithInitialState使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了reducerWithInitialState函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。
示例1: reducers
export default function reducers(workerProxy: WorkerProxy): Reducer<FrameState> {
const state = initialState(workerProxy)
const tempReducer = reducerWithInitialState(state.temp)
.case(actions.didReceiveMnemonic, actions.didReceiveMnemonicHandler)
.case(actions.didStoreMnemonic, actions.didStoreMnemonicHandler)
.case(actions.didAcknowledgeDeposit, actions.didAcknowledgeDepositHandler)
.case(actions.setWorkerProxy, actions.setWorkerProxyHandler)
const sharedReducer = reducerWithInitialState(state.shared)
.case(actions.setSharedState, actions.setSharedStateHandler)
.case(actions.setPending, actions.setPendingHandler)
const walletReducer = reducerWithInitialState(state.wallet)
.case(actions.updateBalance, actions.updateBalanceHandler)
.case(actions.updateAddress, actions.updateAddressHandler)
return redux.combineReducers({
temp: tempReducer,
shared: sharedReducer,
menu: topmenu,
wallet: walletReducer,
});
}
示例2: fitBounds
Math.min(...geos.map(g => g.southwest.lon)),
Math.min(...geos.map(g => g.southwest.lat)),
],
];
const { latitude, longitude, zoom } = fitBounds({
bounds,
height,
width,
});
dispatch(transitionViewport({ latitude, longitude, zoom }));
}
},
);
export const reducer = reducerWithInitialState(SAFE_INIT)
.case(
addFilter,
(original, filters) => {
const result = { ...original };
Object.keys(filters).forEach(filterName => {
result[filterName] = result[filterName].add(filters[filterName]);
});
return result;
},
)
.case(
removeFilter,
(original, filters) => {
const result = { ...original };
Object.keys(filters).forEach(filterName => {
示例3: reducerWithInitialState
import { InfraNodeType } from '../../../../server/lib/adapters/nodes';
import { changeGroupBy, changeMetric, changeNodeType } from './actions';
export interface WaffleOptionsState {
metric: InfraMetricInput;
groupBy: InfraPathInput[];
nodeType: InfraNodeType;
}
export const initialWaffleOptionsState: WaffleOptionsState = {
metric: { type: InfraMetricType.cpu },
groupBy: [],
nodeType: InfraNodeType.host,
};
const currentMetricReducer = reducerWithInitialState(initialWaffleOptionsState.metric).case(
changeMetric,
(current, target) => target
);
const currentGroupByReducer = reducerWithInitialState(initialWaffleOptionsState.groupBy).case(
changeGroupBy,
(current, target) => target
);
const currentNodeTypeReducer = reducerWithInitialState(initialWaffleOptionsState.nodeType).case(
changeNodeType,
(current, target) => target
);
export const waffleOptionsReducer = combineReducers<WaffleOptionsState>({
示例4: reducerWithInitialState
},
users: {
limit: DEFAULT_TABLE_LIMIT,
usersSortField: {
field: UsersFields.name,
direction: Direction.asc,
},
},
},
filterQuery: null,
filterQueryDraft: null,
flowTarget: FlowTarget.source,
},
};
export const networkReducer = reducerWithInitialState(initialNetworkState)
.case(updateDnsLimit, (state, { limit, networkType }) => ({
...state,
[networkType]: {
...state[networkType],
queries: {
...state[networkType].queries,
dns: {
...state[NetworkType.page].queries.dns,
limit,
},
},
},
}))
.case(updateDnsSort, (state, { dnsSortField, networkType }) => ({
...state,
示例5: reducerWithInitialState
import { State } from './index';
export const defaultState: State = {
token: null,
scopes: null,
expiration: null,
loggedInAsCustomer: false
};
const {
token: tokenInLocalStorage,
scopes: scopesInLocalStorage,
expire: expiryInLocalStorage
} = authentication;
const reducer = reducerWithInitialState(defaultState)
.case(handleStartSession, (state, payload) => {
const { scopes, token, expires } = payload;
/** set local storage */
scopesInLocalStorage.set(scopes || '');
tokenInLocalStorage.set(token || '');
expiryInLocalStorage.set(expires || '');
/** set redux state */
return {
...state,
token: token || null,
scopes: scopes || null,
expiration: expires || null
};
示例6: characterReducer
const summonMinionHandler = (state: EntityContainer, payload: Minion): EntityContainer =>
R.assoc(payload.id, payload, state);
const processDeathsHandler = R.reject(
R.whereEq({ destroyed: true, type: CardType.Minion })
);
// TODO: refactor
const characterHandler = (
state: EntityContainer,
action: Action<EntityPayload<Object>>
): EntityContainer =>
R.evolve(
{
[action.payload.id]: (character: Character) =>
characterReducer(character, action),
},
state
);
export default reducerWithInitialState<EntityContainer>(board)
.case(nextTurn, nextTurnHandler)
.case(summonMinion, summonMinionHandler)
.case(processDeaths, processDeathsHandler)
// TODO: we can give 4 elements maximum to casesWithAction method in order to make inference possible
.casesWithAction([attackCharacter, dealDamage, exhaust, destroyWeapon], characterHandler)
.casesWithAction(
[equipWeapon, gainMana, restoreMana, spendMana],
characterHandler
);
示例7: dispatch
if (
player.playState === PlayState.Lost ||
opponent.playState === PlayState.Lost
) {
dispatch(finishGame());
}
};
export const endTurn = (): ThunkAction<void, Game, {}> => (
dispatch,
getState
) => {
dispatch(nextTurn());
const state = getState();
const player = activeHero(state);
dispatch(gainMana({ id: player.id }));
dispatch(restoreMana({ id: player.id }));
const cards = R.values(selectCards(player.owner, getDeck(state)));
if (cards.length > 0) {
dispatch(drawCard(cards[0].id));
}
};
export default reducerWithInitialState<State>(initialState.state)
.case(nextTurn, nextTurnHandler)
.case(finishGame, finishGameHandler);
示例8: reducerWithInitialState
customOptions: InfraGroupByOptions[];
boundsOverride: InfraWaffleMapBounds;
autoBounds: boolean;
}
export const initialWaffleOptionsState: WaffleOptionsState = {
metric: { type: InfraSnapshotMetricType.cpu },
groupBy: [],
nodeType: InfraNodeType.host,
view: 'map',
customOptions: [],
boundsOverride: { max: 1, min: 0 },
autoBounds: true,
};
const currentMetricReducer = reducerWithInitialState(initialWaffleOptionsState.metric).case(
changeMetric,
(current, target) => target
);
const currentCustomOptionsReducer = reducerWithInitialState(
initialWaffleOptionsState.customOptions
).case(changeCustomOptions, (current, target) => target);
const currentGroupByReducer = reducerWithInitialState(initialWaffleOptionsState.groupBy).case(
changeGroupBy,
(current, target) => target
);
const currentNodeTypeReducer = reducerWithInitialState(initialWaffleOptionsState.nodeType).case(
changeNodeType,
示例9: if
if (queryParams.type.includes('one-click')) {
return 'fromApp';
} else if (queryParams.type.includes('images')) {
return 'fromImage';
} else {
return 'fromImage';
}
}
}
/** always backup to 'fromImage' */
return 'fromImage';
};
export const defaultState: State = {
type: getInitialType()
};
const reducer: Reducer<State> = reducerWithInitialState(
defaultState
).caseWithAction(handleChangeCreateType, (state, action) => {
const { payload } = action;
return {
...state,
type: payload
};
});
export default reducer;
示例10: reducerWithInitialState
import { reducerWithInitialState } from 'typescript-fsa-reducers';
import { increment, decrement } from './actions';
export type State = { count: number };
const initialState: State = {
count: 0
};
export const reducer = reducerWithInitialState(initialState)
.case(increment, (state, payload) => {
return {
...state,
count: state.count + payload.incrementBy
};
})
.case(decrement, (state, payload) => {
return {
...state,
count: state.count - payload.incrementBy
};
});
示例11: reducerWithInitialState
import { reducerWithInitialState } from 'typescript-fsa-reducers';
import { loadAnimals } from './actions';
export interface Animal {
id: number;
name: string;
}
export type State = Animal[];
export const reducer = reducerWithInitialState([] as Animal[])
.case(loadAnimals.async.done, (state, payload) => {
return payload.result;
});
示例12: omit
}
export const registerProviderHandler = ({
provider,
dataProviders,
}: RegisterProviderHandlerParams): IdToDataProvider => ({
...dataProviders,
[provider.id]: provider,
});
interface UnRegisterProviderHandlerParams {
id: string;
dataProviders: IdToDataProvider;
}
export const unRegisterProviderHandler = ({
id,
dataProviders,
}: UnRegisterProviderHandlerParams): IdToDataProvider => omit(id, dataProviders);
export const dragAndDropReducer = reducerWithInitialState(initialDragAndDropState)
.case(registerProvider, (state, { provider }) => ({
...state,
dataProviders: registerProviderHandler({ provider, dataProviders: state.dataProviders }),
}))
.case(unRegisterProvider, (state, { id }) => ({
...state,
dataProviders: unRegisterProviderHandler({ id, dataProviders: state.dataProviders }),
}))
.build();
示例13: reducerWithInitialState
import { reducerWithInitialState } from 'typescript-fsa-reducers';
import { setVisibilityFilter } from '../actions';
import { Filter } from '../types';
const reducer = reducerWithInitialState(Filter.SHOW_ALL)
.case(setVisibilityFilter, setVisibilityFilterHandler);
function setVisibilityFilterHandler(state: string, filter: Filter) {
return filter;
}
export default reducer;
示例14: reducerWithInitialState
import { hideFlyout, setFlyoutItem, showFlyout } from './actions';
export enum FlyoutVisibility {
hidden = 'hidden',
visible = 'visible',
}
export interface FlyoutOptionsState {
visibility: FlyoutVisibility;
itemId: string;
}
export const initialFlyoutOptionsState: FlyoutOptionsState = {
visibility: FlyoutVisibility.hidden,
itemId: '',
};
const currentFlyoutReducer = reducerWithInitialState(initialFlyoutOptionsState.itemId).case(
setFlyoutItem,
(current, target) => target
);
const currentFlyoutVisibilityReducer = reducerWithInitialState(initialFlyoutOptionsState.visibility)
.case(hideFlyout, () => FlyoutVisibility.hidden)
.case(showFlyout, () => FlyoutVisibility.visible);
export const flyoutOptionsReducer = combineReducers<FlyoutOptionsState>({
itemId: currentFlyoutReducer,
visibility: currentFlyoutVisibilityReducer,
});
示例15: suggestionReducer
suggestions: suggestionReducer(undefined, "" as any),
};
export const GUEST_USER_ID = 0;
/**
* Determine if a user fragment is a guest.
*/
export function isUserGuest(user: IUserFragment | null | undefined) {
return user && user.userID === GUEST_USER_ID;
}
/**
* Reducer for user related data.
*/
export const usersReducer = produce(
reducerWithInitialState(INITIAL_STATE)
.case(UserActions.getMeACs.started, state => {
state.current.status = LoadStatus.LOADING;
return state;
})
.case(UserActions.getMeACs.done, (state, payload) => {
state.current.data = payload.result;
state.current.status = LoadStatus.SUCCESS;
return state;
})
.case(UserActions.getMeACs.failed, (state, payload) => {
state.current.status = LoadStatus.ERROR;
state.current.error = payload.error;
return state;
})
.case(UserActions.getCountsACs.started, state => {