本文整理汇总了TypeScript中reselect.createSelector函数的典型用法代码示例。如果您正苦于以下问题:TypeScript createSelector函数的具体用法?TypeScript createSelector怎么用?TypeScript createSelector使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了createSelector函数的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: globalizeSelectors
*/
const selectRemote = (state: State) => state.remote;
export const logEntriesSelectors = globalizeSelectors(selectRemote, remoteLogEntriesSelectors);
export const logSummarySelectors = globalizeSelectors(selectRemote, remoteLogSummarySelectors);
export const sourceSelectors = globalizeSelectors(selectRemote, remoteSourceSelectors);
/**
* shared selectors
*/
export const sharedSelectors = {
selectFirstVisibleLogEntry: createSelector(
logEntriesSelectors.selectEntries,
logPositionSelectors.selectFirstVisiblePosition,
(entries, firstVisiblePosition) =>
firstVisiblePosition ? getLogEntryAtTime(entries, firstVisiblePosition) : null
),
selectMiddleVisibleLogEntry: createSelector(
logEntriesSelectors.selectEntries,
logPositionSelectors.selectMiddleVisiblePosition,
(entries, middleVisiblePosition) =>
middleVisiblePosition ? getLogEntryAtTime(entries, middleVisiblePosition) : null
),
selectLastVisibleLogEntry: createSelector(
logEntriesSelectors.selectEntries,
logPositionSelectors.selectLastVisiblePosition,
(entries, lastVisiblePosition) =>
lastVisiblePosition ? getLogEntryAtTime(entries, lastVisiblePosition) : null
),
selectLogFilterQueryAsJson: createSelector(
示例2: createSelector
export const makeIsApplyDisabledSelector = (nodeTypesRegistry: NodeTypesRegistry, validatorRegistry: ValidatorRegistry) => createSelector(
[
isDirty,
makeValidationErrorsSelector(nodeTypesRegistry, validatorRegistry)
],
(
isDirty,
validationErrors
) => {
return !isDirty || (isDirty && validationErrors !== null);
}
);
示例3: createSelector
/* eslint import/prefer-default-export: 0 */
import { AppState } from 'AppState';
import { createSelector } from 'reselect';
import { filter } from 'lodash';
const device = (state: AppState) => state.device;
const devicesSelector = createSelector(
device,
d => d.devices
);
const layerSelector = createSelector(
device,
d => d.layer
);
export const filteredDevices = createSelector(
devicesSelector,
layerSelector,
(devices, layer) => filter(devices, d => d.layer === layer)
);
示例4: asChildFunctionRenderer
);
export const WithStreamItems = asChildFunctionRenderer(withStreamItems, {
onInitialize: props => {
if (!props.isReloading && !props.isLoadingMore) {
props.reloadEntries();
}
},
});
const selectItems = createSelector(
logEntriesSelectors.selectEntries,
logEntriesSelectors.selectIsReloadingEntries,
logPositionSelectors.selectIsAutoReloading,
// searchResultsSelectors.selectSearchResultsById,
(logEntries, isReloading, isAutoReloading /* , searchResults */) =>
isReloading && !isAutoReloading
? []
: logEntries.map(logEntry =>
createLogEntryStreamItem(logEntry /* , searchResults[logEntry.gid] || null */)
)
);
const createLogEntryStreamItem = (logEntry: LogEntry, searchResult?: SearchResult) => ({
kind: 'logEntry' as 'logEntry',
logEntry: {
gid: logEntry.gid,
origin: {
id: logEntry.gid,
index: '',
type: '',
},
示例5: createSelector
import {ApplicationState} from "../store/application-state";
import {MessageVM} from "./message.vm";
import {Message} from "../../../shared/model/message";
import * as _ from 'lodash';
import {Participant} from "../../../shared/model/participant";
import { createSelector } from 'reselect';
// createSelector will rerender the ui only if participants or messages have been changed and the outcome will be
// mapMessagesToMessagesVM, this a pure function implements memoization (results stored in the cache)
export const messagesSelector = createSelector(getParticipants, getMessagesForCurrentThread, mapMessagesToMessagesVM);
function getMessagesForCurrentThread(state: ApplicationState): Message[] {
const currentThread = state.storeData.threads[state.uiState.currentThreadId];
// if the messageIds array is empty map will return an empty array
return currentThread? currentThread.messageIds.map(messageId => state.storeData.messages[messageId]):
[];
}
function getParticipants(state: ApplicationState) {
return state.storeData.participants;
}
function mapMessagesToMessagesVM(participants: {[key: number]: Participant}, messages:Message[]){
return messages.map(message=> {
const participantName = participants[message.participantId].name;
return mapMessageToMessageVM(participantName, message)
});
}
示例6: buildGraph
.value();
}
function buildGraph(rootId) {
var typeIds = [rootId];
var nodes = [];
var types = _.keyBy(schema.types, 'id');
for (var i = 0; i < typeIds.length; ++i) {
var id = typeIds[i];
if (typeIds.indexOf(id) < i)
continue;
var type = types[id];
nodes.push(type);
typeIds.push(...getEdgeTargets(type));
}
return {
rootId,
nodes: _.keyBy(nodes, 'id'),
};
}
}
export const getTypeGraphSelector = createSelector(
getSchemaSelector,
state => state.displayOptions.rootTypeId,
getTypeGraph
);
示例7: createSelector
import { PathAnimationBlock } from 'app/model/timeline';
import { createDeepEqualSelector, getAppState } from 'app/store/selectors';
import * as _ from 'lodash';
import { createSelector } from 'reselect';
const getTimelineState = createSelector(getAppState, s => s.timeline);
export const getAnimation = createSelector(getTimelineState, t => t.animation);
export const isAnimationSelected = createSelector(getTimelineState, t => t.isAnimationSelected);
export const getSelectedBlockIds = createDeepEqualSelector(
getTimelineState,
t => t.selectedBlockIds,
);
export const getSingleSelectedBlockId = createSelector(
getSelectedBlockIds,
blockIds => (blockIds.size === 1 ? blockIds.values().next().value : undefined),
);
export const getSingleSelectedPathBlock = createSelector(
[getAnimation, getSingleSelectedBlockId],
(anim, blockId) => {
if (!blockId) {
return undefined;
}
return _.find(
anim.blocks,
b => b.id === blockId && b instanceof PathAnimationBlock,
) as PathAnimationBlock;
},
);
export const getSelectedBlockLayerIds = createDeepEqualSelector(
[getAnimation, getSelectedBlockIds],
(anim, blockIds) => {
示例8: createSelector
import { BLACK, WHITE } from './consts'
import { State } from './reducer'
import { createSelector } from 'reselect'
const selectBoard = (state: State) => state.board
const selectPlayer = (state: State) => state.player
export const createScoreSelector = () =>
createSelector([selectBoard], board => {
var black = 0
var white = 0
board.forEach(row => {
row.forEach(col => {
if (col === BLACK) {
black += 1
} else if (col === WHITE) {
white += 1
}
})
})
return { black, white }
})
export const startedSelector = createSelector([selectPlayer], player => !!player)
示例9: createSelector
// case StatActions.REMOVE_ALL_NETWORK_ERROR:
// case StatActions.REMOVE_ALL_NETWORK_SUCCESS:
// case StatActions.UPDATE_ERROR:
// case StatActions.UPDATE_NETWORK:
// case StatActions.UPDATE_NETWORK_ERROR:
// case StatActions.UPDATE_NETWORK_SUCCESS:
// case StatActions.SELECT_ERROR:
default:
return state;
}
}
export const getIds = (s: StatState) => s.ids;
export const getEntities = (s: StatState) => s.entities;
export const getSelectedId = (s: StatState) => s.selectedStatId;
export const getLastAdded = (s: StatState) => {
const lastElement = s.ids.length - 1;
return s.entities[s.ids[lastElement]];
};
export const getStat = createSelector(getSelectedId, getEntities, (id, stats) => stats[id]);
export const getStats = createSelector(getIds, getEntities, (ids, entities) => {
return ids.map(id => entities[id]);
});
export const getMeta = createSelector(getIds, getSelectedId, (ids, selectedId) => {
return {ids, selectedId};
});
export const getAddedMeta = createSelector(getLastAdded, getMeta, (stat, meta) => {
return {stat, meta};
});