• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

TypeScript lodash.memoize函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了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;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
TypeScript lodash.merge函数代码示例发布时间:2022-05-25
下一篇:
TypeScript lodash.maxBy函数代码示例发布时间:2022-05-25
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap