本文整理匯總了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(