本文整理汇总了TypeScript中memoize-one.default函数的典型用法代码示例。如果您正苦于以下问题:TypeScript default函数的具体用法?TypeScript default怎么用?TypeScript default使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了default函数的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: memoizeOne
import { storesSelector } from '../inventory/reducer';
import { maxLightLoadout } from '../loadout/auto-loadouts';
import { itemTags } from '../inventory/dim-item-info';
import { characterSortSelector } from '../settings/character-sort';
import store from '../store/store';
import { loadoutsSelector } from '../loadout/reducer';
import { InventoryCuratedRoll } from '../curated-rolls/curatedRollService';
import { curationsSelector } from '../curated-rolls/reducer';
import { D2SeasonInfo } from '../inventory/d2-season-info';
import memoizeOne from 'memoize-one';
/** Make a Regexp that searches starting at a word boundary */
const startWordRegexp = memoizeOne((predicate: string) =>
// Only some languages effectively use the \b regex word boundary
['de', 'en', 'es', 'es-mx', 'fr', 'it', 'pl', 'pt-br'].includes(
store.getState().settings.language
)
? new RegExp(`\\b${escapeRegExp(predicate)}`, 'i')
: new RegExp(escapeRegExp(predicate), 'i')
);
export const searchConfigSelector = createSelector(
destinyVersionSelector,
buildSearchConfig
);
/**
* A selector for the search config for a particular destiny version.
*/
export const searchFiltersConfigSelector = createSelector(
searchConfigSelector,
storesSelector,
示例2: getActiveTimeMachine
export const getActiveTimeMachine = (state: AppState) => {
const {activeTimeMachineID, timeMachines} = state.timeMachines
const timeMachine = timeMachines[activeTimeMachineID]
return timeMachine
}
export const getActiveQuery = (state: AppState): DashboardDraftQuery => {
const {draftQueries, activeQueryIndex} = getActiveTimeMachine(state)
return draftQueries[activeQueryIndex]
}
const getTablesMemoized = memoizeOne(
(files: string[]): FluxTable[] => (files ? flatMap(files, parseResponse) : [])
)
export const getTables = (state: AppState): FluxTable[] =>
getTablesMemoized(getActiveTimeMachine(state).queryResults.files)
const getVisTableMemoized = memoizeOne(toMinardTable)
export const getVisTable = (state: AppState): Table => {
const fluxTables = getTables(state)
const {table} = getVisTableMemoized(fluxTables)
return table
}
const getNumericColumnsMemoized = memoizeOne(
示例3: add
import memoizeOne, { EqualityFn } from 'memoize-one';
declare function add(a: number, b: number): number ;
declare function lousyEqualityFn(a: any, b: any): boolean;
declare function strictEqualityFn<T>(a: T, b: T): boolean;
/**
* Accepts a second argument.
*/
memoizeOne(add); // $ExpectType (a: number, b: number) => number
memoizeOne(add, lousyEqualityFn); // $ExpectType (a: number, b: number) => number
memoizeOne(add, strictEqualityFn); // $ExpectType (a: number, b: number) => number
/**
* The second argument can be, but doesn't have to be strictly typed.
*/
memoizeOne(add, (a, b) => a === b); // $ExpectType (a: number, b: number) => number
memoizeOne(add, (a: string, b: string) => a === b); // $ExpectType (a: number, b: number) => number
/**
* Function passed as the second argument accepts exactly two arguments.
*/
memoizeOne(add, (a: number, b: number, c: number) => a === b || c); // $ExpectError
/**
* Function passed as the second argument returns a boolean.
*/
memoizeOne(add, (a: string, b: string) => 0); // $ExpectError
/**
* The `EqualityFn` type is publicly accessible.
示例4: memoizeOne
(notesById: NotesById) =>
memoizeOne((noteIds: string[]): Note[] => getNotes(notesById, noteIds))
示例5: add
import memoizeOne, { EqualityFn } from 'memoize-one';
declare function add(a: number, b: number): number ;
declare function lousyEqualityFn(a: any, b: any): boolean;
declare function strictEqualityFn<T>(a: T, b: T): boolean;
declare function equalityFnWithIndex<T>(a: T, b: T, index: number): boolean;
/**
* Accepts a second argument.
*/
memoizeOne(add); // $ExpectType (a: number, b: number) => number
memoizeOne(add, lousyEqualityFn); // $ExpectType (a: number, b: number) => number
memoizeOne(add, strictEqualityFn); // $ExpectType (a: number, b: number) => number
memoizeOne(add, equalityFnWithIndex); // $ExpectType (a: number, b: number) => number
/**
* The second argument can be, but doesn't have to be strictly typed.
*/
memoizeOne(add, (a, b) => a === b); // $ExpectType (a: number, b: number) => number
memoizeOne(add, (a: string, b: string) => a === b); // $ExpectType (a: number, b: number) => number
/**
* Function passed as the second argument accepts no more than three arguments.
*/
memoizeOne(add, (a: number, b: number, c: number, d: number) => Boolean(a && b && c && d)); // $ExpectError
/**
* Function passed as the second argument returns a boolean.
*/
memoizeOne(add, (a: string, b: string) => 0); // $ExpectError
示例6: getActiveTimeMachine
export const getActiveTimeMachine = (state: AppState) => {
const {activeTimeMachineID, timeMachines} = state.timeMachines
const timeMachine = timeMachines[activeTimeMachineID]
return timeMachine
}
export const getActiveQuery = (state: AppState): DashboardDraftQuery => {
const {draftQueries, activeQueryIndex} = getActiveTimeMachine(state)
return draftQueries[activeQueryIndex]
}
const getTablesMemoized = memoizeOne(
(files: string[]): FluxTable[] => (files ? flatMap(files, parseResponse) : [])
)
export const getTables = (state: AppState): FluxTable[] =>
getTablesMemoized(getActiveTimeMachine(state).queryResults.files)
const getVisTableMemoized = memoizeOne(fromFlux)
export const getVisTable = (state: AppState): Table => {
const files = getActiveTimeMachine(state).queryResults.files || []
const {table} = getVisTableMemoized(files.join('\n\n'))
return table
}
const getNumericColumnsMemoized = memoizeOne(