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


TypeScript lodash.memoize函數代碼示例

本文整理匯總了TypeScript中lodash.memoize函數的典型用法代碼示例。如果您正苦於以下問題:TypeScript memoize函數的具體用法?TypeScript memoize怎麽用?TypeScript memoize使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。


在下文中一共展示了memoize函數的10個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。

示例1: getSuggestionsProvider

export function getSuggestionsProvider(
  config: { get: (key: string) => any },
  fetch: (...options: any[]) => any
) {
  const requestSuggestions = memoize(
    (index: string, field: Field, query: string, boolFilter: any = []) => {
      return fetch({
        pathname: `/api/kibana/suggestions/values/${index}`,
        method: 'POST',
        body: JSON.stringify({ query, field: field.name, boolFilter }),
      });
    },
    resolver
  );

  return async (index: string, field: Field, query: string, boolFilter?: any) => {
    const shouldSuggestValues = config.get('filterEditor:suggestValues');
    if (field.type === 'boolean') {
      return [true, false];
    } else if (!shouldSuggestValues || !field.aggregatable || field.type !== 'string') {
      return [];
    }
    return await requestSuggestions(index, field, query, boolFilter);
  };
}
開發者ID:elastic,項目名稱:kibana,代碼行數:25,代碼來源:value_suggestions.ts

示例2: memoize

export const createMockServer = ({ settings = {} }: any) => {
  const mockServer = {
    expose: () => {
      ' ';
    },
    config: memoize(() => ({ get: jest.fn() })),
    info: {
      protocol: 'http',
    },
    plugins: {
      elasticsearch: {
        getCluster: memoize(() => {
          return {
            callWithRequest: jest.fn(),
          };
        }),
      },
    },
    savedObjects: {
      getScopedSavedObjectsClient: jest.fn(),
    },
    uiSettingsServiceFactory: jest.fn().mockReturnValue({ get: jest.fn() }),
  };

  const defaultSettings: any = {
    'xpack.reporting.encryptionKey': 'testencryptionkey',
    'server.basePath': '/sbp',
    'server.host': 'localhost',
    'server.port': 5601,
    'xpack.reporting.kibanaServer': {},
  };
  mockServer.config().get.mockImplementation((key: any) => {
    return key in settings ? settings[key] : defaultSettings[key];
  });

  return mockServer;
};
開發者ID:elastic,項目名稱:kibana,代碼行數:37,代碼來源:create_mock_server.ts

示例3: groupByNestedPropFilter

export function groupByNestedPropFilter() {
  'ngInject';

  return _.memoize(filter, resolver);

  function filter(input: any, property: string) {
    if (angular.isUndefined(property) || angular.isUndefined(input)) { return input; }

    return _.groupBy(input, property);
  }

  function resolver(input: any, property: string) {
    return angular.toJson(input) + property;
  }
}
開發者ID:blackbarlabs,項目名稱:ng1-typescript-starter,代碼行數:15,代碼來源:group-by-nested-prop.filter.ts

示例4: memoize

import * as execa from 'execa'
import { memoize } from 'lodash'

const exec = args => () => execa.shellSync(args.trim()).stdout
const mexec = memoize(exec)

export const gitRoot = mexec(`
  git rev-parse --show-toplevel
`)

export const gitShortHash = mexec(`
  git rev-parse --short HEAD
`)
開發者ID:borestad,項目名稱:playground,代碼行數:13,代碼來源:index.ts

示例5: groupSections

export function groupSections(sysInfoData: T.SysInfoValueObject) {
  const mainSection: T.SysInfoValueObject = {};
  const sections: T.SysInfoSection = {};
  each(sysInfoData, (item, key) => {
    if (typeof item !== 'object' || item instanceof Array) {
      mainSection[key] = item;
    } else {
      sections[key] = item;
    }
  });
  return { mainSection, sections };
}

export const parseQuery = memoize(
  (urlQuery: RawQuery): Query => ({
    expandedCards: parseAsArray(urlQuery.expand, parseAsString)
  })
);

export const serializeQuery = memoize(
  (query: Query): RawQuery =>
    cleanQuery({
      expand: serializeStringArray(query.expandedCards)
    })
);

export function sortUpgrades(upgrades: T.SystemUpgrade[]): T.SystemUpgrade[] {
  return sortBy(upgrades, [
    (upgrade: T.SystemUpgrade) => -Number(upgrade.version.split('.')[0]),
    (upgrade: T.SystemUpgrade) => -Number(upgrade.version.split('.')[1] || 0),
    (upgrade: T.SystemUpgrade) => -Number(upgrade.version.split('.')[2] || 0)
開發者ID:SonarSource,項目名稱:sonarqube,代碼行數:31,代碼來源:utils.ts

示例6: memoize

/*
 * This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
 */

import { memoize } from 'lodash';

const cache = memoize((s: string) => {
  return new RegExp('^' + s.replace(/./g, (x) => {
    return /[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/.test(x) ? '\\' + x + '?' : x + '?';
  }) + '$', 'i');
});

export default (s: string, pattern: string) => {
  return cache(s).test(pattern);
};
開發者ID:Mehuge,項目名稱:Camelot-Unchained,代碼行數:17,代碼來源:stringContains.ts

示例7: memoize

    return false;
  }

  for (let i = 0; i < pathTokens.length; i++) {
    if (pathTokens[i] !== splatTokens[i]) {
      return false;
    }
  }

  return true;
};

export const parseQuery = memoize(
  (urlQuery: RawQuery): Query => ({
    search: parseAsString(urlQuery['query']),
    deprecated: parseAsOptionalBoolean(urlQuery['deprecated']) || false,
    internal: parseAsOptionalBoolean(urlQuery['internal']) || false
  })
);

export const serializeQuery = memoize(
  (query: Partial<Query>): RawQuery =>
    cleanQuery({
      query: query.search ? serializeString(query.search) : undefined,
      deprecated: query.deprecated || undefined,
      internal: query.internal || undefined
    })
);

export function parseVersion(version: string) {
  const match = /(\d+)\.(\d+)/.exec(version);
開發者ID:SonarSource,項目名稱:sonarqube,代碼行數:31,代碼來源:utils.ts

示例8: memoize

  asDecimal,
  asMillis,
  asPercent,
  tpmUnit
} from '../../utils/formatters';
import { IUrlParams } from '../urlParams';

export const getEmptySerie = memoize(
  (start = Date.now() - 3600000, end = Date.now()) => {
    const dates = d3.time
      .scale()
      .domain([new Date(start), new Date(end)])
      .ticks();

    return [
      {
        data: dates.map(x => ({
          x: x.getTime(),
          y: 1
        }))
      }
    ];
  },
  (start: number, end: number) => [start, end].join('_')
);

interface IEmptySeries {
  data: Coordinate[];
}

export interface ITpmBucket {
  title: string;
開發者ID:liuyepiaoxiang,項目名稱:kibana,代碼行數:32,代碼來源:chartSelectors.ts

示例9: memoize

  RawQuery,
  parseAsBoolean,
  serializeOptionalBoolean,
  parseAsOptionalString,
  serializeString
} from '../../../helpers/query';

export interface Query {
  error?: string;
  manual: boolean;
  organization?: string;
}

export const parseQuery = memoize(
  (urlQuery: RawQuery): Query => {
    return {
      error: parseAsOptionalString(urlQuery['error']),
      manual: parseAsBoolean(urlQuery['manual'], false),
      organization: parseAsOptionalString(urlQuery['organization'])
    };
  }
);

export const serializeQuery = memoize(
  (query: Query): RawQuery =>
    cleanQuery({
      manual: serializeOptionalBoolean(query.manual || undefined),
      organization: serializeString(query.organization)
    })
);
開發者ID:flopma,項目名稱:sonarqube,代碼行數:30,代碼來源:utils.ts

示例10: memoize

		default:
			return EmojiStyleCode.Facebook30;
	}
}

/**
Renders the given emoji in the renderer process and returns a PNG `data:` URL.
*/
const renderEmoji = memoize(
	async (emoji: string): Promise<string> =>
		new Promise(resolve => {
			const listener = (_event: ElectronEvent, arg: {emoji: string; dataUrl: string}): void => {
				if (arg.emoji !== emoji) {
					return;
				}

				ipcMain.removeListener('native-emoji', listener);
				resolve(arg.dataUrl);
			};

			ipcMain.on('native-emoji', listener);
			sendBackgroundAction('render-native-emoji', emoji);
		})
);

/**
@param url - A Facebook emoji URL like `https://static.xx.fbcdn.net/images/emoji.php/v9/tae/2/16/1f471_1f3fb_200d_2640.png`.
*/
function urlToEmoji(url: string): string {
	const codePoints = url
		.split('/')
		.pop()!
開發者ID:nikteg,項目名稱:caprine,代碼行數:32,代碼來源:emoji.ts


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