當前位置: 首頁>>代碼示例>>TypeScript>>正文


TypeScript memoize-one.default函數代碼示例

本文整理匯總了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,
開發者ID:w1cked,項目名稱:DIM,代碼行數:32,代碼來源:search-filters.ts

示例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(
開發者ID:sebito91,項目名稱:influxdb,代碼行數:30,代碼來源:index.ts

示例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.
開發者ID:CNBoland,項目名稱:DefinitelyTyped,代碼行數:31,代碼來源:memoize-one-tests.ts

示例4: memoizeOne

 (notesById: NotesById) =>
   memoizeOne((noteIds: string[]): Note[] => getNotes(notesById, noteIds))
開發者ID:,項目名稱:,代碼行數:2,代碼來源:

示例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
開發者ID:Jeremy-F,項目名稱:DefinitelyTyped,代碼行數:30,代碼來源:memoize-one-tests.ts

示例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(
開發者ID:influxdata,項目名稱:influxdb,代碼行數:30,代碼來源:index.ts


注:本文中的memoize-one.default函數示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。