當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。