本文整理汇总了TypeScript中@ngrx/store.createFeatureSelector函数的典型用法代码示例。如果您正苦于以下问题:TypeScript createFeatureSelector函数的具体用法?TypeScript createFeatureSelector怎么用?TypeScript createFeatureSelector使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了createFeatureSelector函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1:
import { RouterStateUrl } from './router/router.state';
export const reducers: ActionReducerMap<AppState> = {
auth: authReducer,
router: routerReducer
};
export const metaReducers: MetaReducer<AppState>[] = [
initStateFromLocalStorage
];
if (!environment.production) {
metaReducers.unshift(storeFreeze);
if (!environment.test) {
metaReducers.unshift(debug);
}
}
export const selectAuthState = createFeatureSelector<AppState, AuthState>(
'auth'
);
export const selectRouterState = createFeatureSelector<
AppState,
RouterReducerState<RouterStateUrl>
>('router');
export interface AppState {
auth: AuthState;
router: RouterReducerState<RouterStateUrl>;
}
示例2: createSelector
/**
* Our state is composed of a map of action reducer functions.
* These reducer functions are called with each dispatched action
* and the current or initial state and return a new immutable state.
*/
export const reducers: ActionReducerMap<State> = {
filters: fromFilters.reducer,
quarters: fromQuarter.reducer,
pai: fromPai.reducer,
search: fromSearch.reducer,
};
/**
* Layout Reducers
*/
export const getPaiState = createFeatureSelector<fromPai.State>('pai');
export const getFiltersState = createFeatureSelector<fromFilters.State>('filters');
export const getQuartersState = createFeatureSelector<fromQuarter.State>('quarters');
export const getSearchState = createFeatureSelector<fromSearch.State>('search');
export const getFiltersEntities = createSelector(
getFiltersState,
fromFilters.getEntities
);
export const getSelectedFilters = createSelector(
getFiltersState,
fromFilters.getSelectedFilters
);
export const getQuartersEntities = createSelector(
示例3: reducer
export interface PodcastState {
podcast: Podcast;
items: Page<Item>;
}
const initialState: PodcastState = {
podcast: null,
items: null
};
export function reducer(state = initialState, action: PodcastActions): PodcastState {
switch (action.type) {
case PodcastAction.FIND_ONE_SUCCESS: {
return { ...state, podcast: action.podcast };
}
case PodcastAction.FIND_ITEMS_SUCCESS: {
return { ...state, items: action.items };
}
default: {
return state;
}
}
}
const moduleSelector = createFeatureSelector<PodcastState>('podcast');
export const selectPodcast = createSelector(moduleSelector, (s: PodcastState) => s.podcast);
export const selectPodcastItems = createSelector(moduleSelector, (s: PodcastState) => s.items);
示例4: createSelector
// Ngrx
import { createSelector, createFeatureSelector, ActionReducerMap } from '@ngrx/store';
// Models
import { IProductModuleState } from '../../models';
// Reducers
import { ProductReducer } from './product.reducer';
export const reducers: ActionReducerMap<IProductModuleState> = {
products: ProductReducer
};
/* =============================== Feature Selector =========================== */
export const productModuleStateSelector = createFeatureSelector<IProductModuleState>('products');
/* =============================== Product Selectors =========================== */
export const productStateSelector = createSelector(
productModuleStateSelector,
state => state.products
);
export const productPageRequestSelector = createSelector(
productStateSelector,
state => state.pageRequest
);
export const productPageSelector = createSelector(
productStateSelector,
state => state.data
示例5: createSelector
import { createFeatureSelector, createSelector } from '@ngrx/store';
export interface CoreState {
language: string
}
export const initialState: CoreState = {
language: null
};
export const getCoreState = createFeatureSelector<CoreState>('coreReducer');
export const getLanguage = createSelector(getCoreState, (state: CoreState) => state.language);
示例6: floatingPlayer
export interface FloatingPlayerState {
item: Item;
display: DisplayState;
}
const initialState: FloatingPlayerState = {
item: null,
display: 'CLOSED'
};
export function floatingPlayer(state = initialState, action: FloatingPlayerActions): FloatingPlayerState {
switch (action.type) {
case FloatingPlayerAction.PLAY: {
return { ...state, item: action.item, display: 'OPENED' };
}
case FloatingPlayerAction.CLOSE: {
return { ...state, item: null, display: 'CLOSED' };
}
default: {
return state;
}
}
}
const moduleSelector = createFeatureSelector<FloatingPlayerState>('floatingPlayer');
export const item = createSelector(moduleSelector, (s: FloatingPlayerState) => s.item);
export const display = createSelector(moduleSelector, (s: FloatingPlayerState) => s.display);
示例7: fetchSelectedFilters
import { HomeState } from './index';
import { SearchState } from './search.state';
import { createSelector, createFeatureSelector } from '@ngrx/store';
/******************* Base Search State ******************/
export const getHomeState = createFeatureSelector<HomeState>('home');
export const getSearchState = createSelector(
getHomeState,
(state: HomeState) => state.search
);
/******************* Individual selectors ******************/
function fetchSelectedFilters(state: SearchState) {
return state.selectedFilters.toJS();
};
function fetchSelectedTaxonIds(state: SearchState) {
return state.selectedTaxonIds.toJS();
}
function fetchProductsByKeyword(state: SearchState) {
return state.productsByKeyword.toJS();
}
function fetchChildTaxons(state: SearchState) {
return state.getChildTaxons.toJS();
}
function fetchCategeoryLevel(state: SearchState) {
return state.categeoryLevel.toJS();
示例8: createFeatureSelector
'AddScatterChartData': scatterChart.AddScatterChartData,
'UpdateRealTimeScatterChartXRange': scatterChartRealTime.UpdateRealTimeScatterChartXRange,
'UpdateServerMapData': serverMap.UpdateServerMapData,
'UpdateServerMapLoadingState': serverMapLoadingState.UpdateServerMapLoadingState,
'UpdateServerMapTargetSelected': serverMapSelectedTarget.UpdateServerMapTargetSelected,
'UpdateServerMapSelectedTargetByList': targetList.UpdateServerMapSelectedTargetByList,
'UpdateFilterOfServerAndAgentList': serverAndAgent.UpdateFilterOfServerAndAgentList,
'UpdateAgentInfo': agentInfo.UpdateAgentInfo,
'UpdateAdminAgentList': admin.UpdateAdminAgentList,
'ChangeServerMapDisableState': uiState.ChangeServerMapDisableState,
'ChangeInfoPerServerVisibleState': uiState.ChangeInfoPerServerVisibleState,
'UpdateTimelineData': timeline.UpdateTimelineData,
'UpdateURLPath': urlPath.UpdateURLPath
};
const getUI = createFeatureSelector('uiState');
export const selectServerMapDisableState = createSelector(
getUI,
(state: IUIState) => state['serverMap']
);
export const selectInfoPerServerVisibleState = createSelector(
getUI,
(state: IUIState) => state['infoPerServer']
);
const getTimeline = createFeatureSelector('timeline');
export const selectTimelineRange = createSelector(
getTimeline,
(state: ITimelineInfo) => state['range']
);
export const selectTimelineSelectionRange = createSelector(
示例9: createSelector
import { createFeatureSelector, createSelector } from '@ngrx/store';
import { IIdentityState } from './states/index';
export const selectIdentityState = createFeatureSelector<IIdentityState>('identity');
export const getIdentity = createSelector(selectIdentityState, state => state.identity);
示例10:
import { ActionReducerMap, createFeatureSelector } from '@ngrx/store';
import * as fromRoot from '../../store';
import * as fromCandidate from './candidate.reducer';
export interface CandidateState {
candidate: fromCandidate.State;
}
export interface State extends fromRoot.State {
candidate: CandidateState;
}
export const reducers: ActionReducerMap<CandidateState> = {
candidate: fromCandidate.reducer
};
export const selectCandidateState = createFeatureSelector<CandidateState>(
'candidate'
);
示例11: sidenav
podcast: PodcastState;
item: ItemState;
}
export interface State {
open: boolean;
}
const initialState: State = {
open: false
};
export function sidenav(state = initialState, action: AppActions): State {
switch (action.type) {
case AppAction.OPEN_SIDE_NAV: {
return {...state, open: true };
}
case AppAction.CLOSE_SIDE_NAV: {
return {...state, open: false };
}
default: {return state; }
}
}
const sideNavFeature = createFeatureSelector('sidenav');
export const selectSideNavOpen = createSelector(sideNavFeature, (s: State) => s.open);
示例12: reducer
import { createFeatureSelector, createSelector } from '@ngrx/store';
import { UserActions, UserActionTypes } from './user.actions';
// State for this feature (User)
export interface UserState {
maskUserName: boolean;
currentUser: User;
}
const initialState: UserState = {
maskUserName: true,
currentUser: null
};
// Selector functions
const getProductFeatureState = createFeatureSelector<UserState>('users');
export const getMaskUserName = createSelector(
getProductFeatureState,
state => state.maskUserName
);
export const getCurrentUser = createSelector(
getProductFeatureState,
state => state.currentUser
);
export function reducer(state = initialState, action: UserActions): UserState {
switch (action.type) {
case UserActionTypes.MaskUserName:
return {
示例13: deleteBin
return Object.assign({}, state, {
selectedBinID: action.payload
});
}
function deleteBin(state: State, action: BinEstimatorActions.DeleteBinAction) {
if (action.payload === state.selectedBinID) {
return Object.assign({}, state, {
selectedBinID: null
})
} else {
return state;
}
}
export const selectBinEstimatorState = createFeatureSelector<State>('binEstimators');
export const selectAppState = createSelector(selectBinEstimatorState, (state: State) => state.appState);
export const selectLoadingBinEstimators = createSelector(selectBinEstimatorState, (state: State) => state.loadingBinEstimators);
export const selectBinEstimatorsLoaded = createSelector(selectBinEstimatorState, (state: State) => state.binEstimatorsLoaded);
export const selectActiveBinEstimatorID = createSelector(selectBinEstimatorState, (state: State) => state.activeBinEstimatorID);
export const selectActiveLocusBinSetID = createSelector(selectBinEstimatorState, (state: State) => state.activeLocusBinSetID);
export const selectSelectedBinID = createSelector(selectBinEstimatorState, (state: State) => state.selectedBinID);
export const selectActiveBinEstimator = createSelector(fromDB.selectBinEstimatorProjectEntities, selectActiveBinEstimatorID, (entities, id): BinEstimatorProject => entities[id]);
export const selectActiveLocusSet = createSelector(fromDB.selectLocusSetEntities, selectActiveBinEstimator, (locusSets, binEstimator): LocusSet => {
if (locusSets && binEstimator) {
return locusSets[binEstimator.locus_set];
} else {
return null;
}
});
示例14: setTask
return setTask(state, action);
}
function taskCompleted(state: State, action: TaskActions.TaskSuccessAction) {
return setTask(state, action);
}
function clearTask(state: State, action: TaskActions.ClearTaskAction) {
const taskId = action.payload;
const {[taskId]: taskToRemove, ...remainingTasks} = state.tasks;
return Object.assign({}, state, {
tasks: remainingTasks,
});
}
export const selectTasksState = createFeatureSelector<State>('tasks');
export function selectTask(id: string) {
return createSelector(selectTasksState, (state) => state.tasks[id])
}
export function selectActiveTasks(namespace: string = null, taskType: string = null) {
return createSelector(selectTasksState, fromDB.selectAnyGetsInFlight, (state: State, getsInFlight: boolean): Task[] => {
const activeTasks = Object.keys(state.tasks)
.filter(id => {
const e = state.tasks[id];
if (namespace && e.namespace !== namespace) {
return false;
}
if (taskType && e.task !== taskType) {
示例15: createSelector
import {createFeatureSelector, createSelector} from '@ngrx/store';
import {State} from './reducer';
export const getState = createFeatureSelector<State>('productState');
export const getQuantity = createSelector(getState, state => state.productQuantity);
export const getErrorMessage = createSelector(getState, state => state.error);