本文整理汇总了TypeScript中lodash.once函数的典型用法代码示例。如果您正苦于以下问题:TypeScript once函数的具体用法?TypeScript once怎么用?TypeScript once使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了once函数的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: setup
public setup() {
return {
ui: {
SearchBar,
},
loadLegacyDirectives: once(setupSearchBarDirective),
};
}
示例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]();
};
示例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
);
});
示例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);
});
示例5: setup
public setup() {
return {
loadLegacyDirectives: once(setupQueryBarDirective),
helpers: {
fromUser,
toUser,
},
ui: {
QueryBar,
QueryBarInput,
},
};
}
示例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();
});
示例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;
})
};
});
示例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;
};
示例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 () => {