当前位置: 首页>>代码示例>>TypeScript>>正文


TypeScript lodash.once函数代码示例

本文整理汇总了TypeScript中lodash.once函数的典型用法代码示例。如果您正苦于以下问题:TypeScript once函数的具体用法?TypeScript once怎么用?TypeScript once使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了once函数的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。

示例1: setup

 public setup() {
   return {
     ui: {
       SearchBar,
     },
     loadLegacyDirectives: once(setupSearchBarDirective),
   };
 }
开发者ID:elastic,项目名称:kibana,代码行数:8,代码来源:search_service.ts

示例2:

export const experimentalMethod = (methodName: string, className: string): void => {
	if (!warnings.experimental[methodName + className]) {
		warnings.experimental[methodName + className] = _.once(() => {
			// tslint:disable-next-line:no-console
			const log = (console.warn || console.log || _.noop).bind(console);
			log(`Method ${className}.${methodName} is experimental, use with caution.`);
		});
	}
	warnings.experimental[methodName + className]();
};
开发者ID:appnexus,项目名称:anx-api,代码行数:10,代码来源:stability.ts

示例3: function

        $q.all([modelPromise, vuosiluokatPromise]).then(function(data) {
            // Add addable items to menu
            $scope.vuosiluokkakokonaisuudet = data[1];
            $scope.vuosiluokkakokonaisuudet = _.sortBy($scope.vuosiluokkakokonaisuudet, VlkUtils.orderFn);
            if (_.size($scope.vuosiluokkakokonaisuudet) > 0) {
                $scope.data.options.fields.push({ divider: true, order: 99 });
            }
            var menuItems = [];
            _.each($scope.vuosiluokkakokonaisuudet, function(item) {
                menuItems.push({
                    path: "vuosiluokkakokonaisuudet",
                    localeKey: item.nimi,
                    id: item.id,
                    empty: function() {
                        var vlk = {
                            _vuosiluokkaKokonaisuus: item.id,
                            sisaltoAlueet: [],
                            tavoitteet: []
                        };
                        _.each(["tehtava", "tyotavat", "ohjaus", "arviointi"], function(osio) {
                            vlk[osio] = { otsikko: getTitle(osio), teksti: {} };
                        });
                        return vlk;
                    },
                    order: 10,
                    visibleFn: function() {
                        updateChosen();
                        return _.indexOf($scope.chosenVuosiluokat, item.id) > -1;
                    },
                    remove: function() {
                        var index = _.findIndex($scope.editableModel.vuosiluokkakokonaisuudet, function(vlk: any) {
                            return parseInt(vlk._vuosiluokkaKokonaisuus, 10) === item.id;
                        });
                        $scope.editableModel.vuosiluokkakokonaisuudet.splice(index, 1);
                    }
                });
            });
            _(menuItems)
                .each(function(item, index) {
                    item.order += index;
                })
                .value();
            $scope.data.options.fields = menuItems.concat($scope.data.options.fields);

            // Jos t채t채 ei ole tabit vaihtelee satunnaisesti poistoilla ja lis채yksill채
            var valitseTabi = _.once(_.bind($scope.chooseTab, {}, $scope.activeTab, true));
            $scope.$watch(
                "editableModel.vuosiluokkakokonaisuudet",
                function() {
                    mapVuosiluokat();
                    valitseTabi();
                },
                true
            );
        });
开发者ID:Opetushallitus,项目名称:eperusteet,代码行数:55,代码来源:oppiaine.ts

示例4: Promise

  return new Promise((resolve, reject) => {
    const { url, method, headers } = opts;

    // There are several paths by which the promise may resolve or reject. We wrap this
    // in "once" as a safeguard against cases where we attempt more than one call. (e.g.
    // a batch handler fails, so we reject the promise, but then new data comes in for
    // a subsequent batch item)
    const complete = once((err: Error | undefined = undefined) =>
      err ? reject(err) : resolve(req)
    );

    // Begin the request
    req.open(method || 'POST', `${basePath}/${url.replace(/^\//, '')}`);
    req.withCredentials = true;

    // Set the HTTP headers
    Object.entries(Object.assign({}, defaultHeaders, headers)).forEach(([k, v]) =>
      req.setRequestHeader(k, v)
    );

    const batchHandler = processBatchResponseStream(opts.onResponse);
    const processBatch = () => {
      try {
        batchHandler(req.responseText);
      } catch (err) {
        req.abort();
        complete(err);
      }
    };

    req.onprogress = processBatch;

    req.onreadystatechange = () => {
      // Older browsers don't support onprogress, so we need
      // to call this here, too. It's safe to call this multiple
      // times even for the same progress event.
      processBatch();

      // 4 is the magic number that means the request is done
      if (req.readyState === 4) {
        // 0 indicates a network failure. 400+ messages are considered server errors
        if (req.status === 0 || req.status >= 400) {
          complete(new Error(`Batch request failed with status ${req.status}`));
        } else {
          complete();
        }
      }
    };

    // Send the payload to the server
    req.send(opts.body);
  });
开发者ID:elastic,项目名称:kibana,代码行数:52,代码来源:ajax_stream.ts

示例5: setup

 public setup() {
   return {
     loadLegacyDirectives: once(setupQueryBarDirective),
     helpers: {
       fromUser,
       toUser,
     },
     ui: {
       QueryBar,
       QueryBarInput,
     },
   };
 }
开发者ID:elastic,项目名称:kibana,代码行数:13,代码来源:query_service.ts

示例6: it

 it('should implement the interface', done => {
     done = once(done);
     const server = new StdioDriver({
         projectPath: resolve(__dirname, '../'),
         onEvent: noop,
         onState(v) {
             // tslint:disable-next-line:no-unused-expression
             expect(server.currentState).to.be.not.null;
             // tslint:disable-next-line:no-unused-expression
             expect(server.outstandingRequests).to.be.not.null;
             server.disconnect();
             done();
         },
         onCommand: noop
     });
     server.connect();
 });
开发者ID:OmniSharp,项目名称:omnisharp-node-client,代码行数:17,代码来源:stdio-spec.ts

示例7: get

  lazyTables.forEach((tableShort) => {
    const table = `Destiny${tableShort}Definition`;
    defs[tableShort] = {
      get(name: number) {
        if (this.hasOwnProperty(name)) {
          return this[name];
        }
        const val = D2ManifestService.getRecord(db, table, name);
        this[name] = val;
        return val;
      },

      getAll: _.once(function() {
        const allRecords = D2ManifestService.getAllRecords(db, table);
        // Cache all the results individually
        Object.assign(this, allRecords);
        return allRecords;
      })
    };
  });
开发者ID:w1cked,项目名称:DIM,代码行数:20,代码来源:d2-definitions.service.ts

示例8: Error

export const registerPlugin = function<V = void>(
  plugin_metadata: PluginMetadata,
  enable: PluginEnableFn<V>,
  disable: PluginDisableFn<V>,
) {
  plugin_metadata.version = plugin_metadata.version || 1;
  plugin_metadata.author = plugin_metadata.author || 'anonymous';

  // Create the plugin object
  // Plugin stores all data about a plugin, including metadata
  // plugin.value contains the actual resolved value
  const plugin: RegisteredPlugin<V> = {
    ..._.cloneDeep(plugin_metadata),
    enable,
    disable: disable || _.once(function(api: PluginApi) {
      api.deregisterAll();
      throw new Error(
        `The plugin '${plugin.name}' was disabled but doesn't support online disable functionality. Refresh to disable.`
      );
    }),
  };
  PLUGINS[plugin.name] = plugin;
};
开发者ID:WuTheFWasThat,项目名称:vimflowy,代码行数:23,代码来源:plugins.ts

示例9: once

}

export const initTestDb = once(async () => {
  await mongooseUtil.connect();
  await clear();

  const tourneyId = await initNewTourney({
    name: 'Test Tourney',
    startDate: new Date(),
    par: -1,
    scoresSync: {
      syncType: 'test',
      url: 'test',
      nameMap: {},
    },
    draftOrder: [],
    wgr: {
      url: 'test',
      nameMap: {},
    }
  });
  const appState = new models.AppState({
    activeTourneyId: tourneyId,
    isDraftPaused: true,
    allowClock: true,
    draftHasStarted: false,
    autoPickUsers: []
  });
  await appState.save();
});

export const closeTestDb = async () => {
开发者ID:odetown,项目名称:golfdraft,代码行数:32,代码来源:initTestConfig.ts


注:本文中的lodash.once函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。