本文整理匯總了TypeScript中@angular/core/src/di.provide函數的典型用法代碼示例。如果您正苦於以下問題:TypeScript provide函數的具體用法?TypeScript provide怎麽用?TypeScript provide使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了provide函數的8個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。
示例1: _markName
_markName(index) { return `${_MARK_NAME_PREFIX}${index}`; }
}
var _MICRO_ITERATIONS_REGEX = /(.+)\*(\d+)$/g;
var _MAX_RETRY_COUNT = 20;
var _MARK_NAME_PREFIX = 'benchpress';
var _SET_TIMEOUT = new OpaqueToken('PerflogMetric.setTimeout');
var _MARK_NAME_FRAME_CAPUTRE = 'frameCapture';
// using 17ms as a somewhat looser threshold, instead of 16.6666ms
var _FRAME_TIME_SMOOTH_THRESHOLD = 17;
var _PROVIDERS = [
bind(PerflogMetric)
.toFactory(
(driverExtension, setTimeout, microMetrics, forceGc, captureFrames, receivedData,
requestCount) => new PerflogMetric(driverExtension, setTimeout, microMetrics, forceGc,
captureFrames, receivedData, requestCount),
[
WebDriverExtension,
_SET_TIMEOUT,
Options.MICRO_METRICS,
Options.FORCE_GC,
Options.CAPTURE_FRAMES,
Options.RECEIVED_DATA,
Options.REQUEST_COUNT
]),
provide(_SET_TIMEOUT, {useValue: (fn, millis) => TimerWrapper.setTimeout(fn, millis)})
];
示例2: validate
validate(completeSample: MeasureValues[]): MeasureValues[] {
if (completeSample.length >= this._sampleSize) {
var latestSample = ListWrapper.slice(completeSample, completeSample.length - this._sampleSize,
completeSample.length);
var xValues = [];
var yValues = [];
for (var i = 0; i < latestSample.length; i++) {
// For now, we only use the array index as x value.
// TODO(tbosch): think about whether we should use time here instead
xValues.push(i);
yValues.push(latestSample[i].values[this._metric]);
}
var regressionSlope = Statistic.calculateRegressionSlope(
xValues, Statistic.calculateMean(xValues), yValues, Statistic.calculateMean(yValues));
return regressionSlope >= 0 ? latestSample : null;
} else {
return null;
}
}
}
var _SAMPLE_SIZE = new OpaqueToken('RegressionSlopeValidator.sampleSize');
var _METRIC = new OpaqueToken('RegressionSlopeValidator.metric');
var _PROVIDERS = [
bind(RegressionSlopeValidator)
.toFactory((sampleSize, metric) => new RegressionSlopeValidator(sampleSize, metric),
[_SAMPLE_SIZE, _METRIC]),
provide(_SAMPLE_SIZE, {useValue: 10}),
provide(_METRIC, {useValue: 'scriptTime'})
];
示例3: _printStringRow
this._printStringRow(this._metricNames.map(metricName => {
var samples = validSamples.map(measureValues => measureValues.values[metricName]);
var mean = Statistic.calculateMean(samples);
var cv = Statistic.calculateCoefficientOfVariation(samples, mean);
var formattedMean = ConsoleReporter._formatNum(mean)
// Note: Don't use the unicode character for +- as it might cause
// hickups for consoles...
return NumberWrapper.isNaN(cv) ?
formattedMean :
`${formattedMean}+-${Math.floor(cv)}%`;
}));
return PromiseWrapper.resolve(null);
}
_printStringRow(parts: any[], fill = ' ') {
this._print(
parts.map(part => ConsoleReporter._lpad(part, this._columnWidth, fill)).join(' | '));
}
}
var _PRINT = new OpaqueToken('ConsoleReporter.print');
var _COLUMN_WIDTH = new OpaqueToken('ConsoleReporter.columnWidth');
var _PROVIDERS = [
bind(ConsoleReporter)
.toFactory((columnWidth, sampleDescription, print) =>
new ConsoleReporter(columnWidth, sampleDescription, print),
[_COLUMN_WIDTH, SampleDescription, _PRINT]),
provide(_COLUMN_WIDTH, {useValue: 18}),
provide(_PRINT, {useValue: print})
];
示例4: CAPTURE_FRAMES
static get CAPTURE_FRAMES() { return _CAPTURE_FRAMES; }
}
var _SAMPLE_ID = new OpaqueToken('Options.sampleId');
var _DEFAULT_DESCRIPTION = new OpaqueToken('Options.defaultDescription');
var _SAMPLE_DESCRIPTION = new OpaqueToken('Options.sampleDescription');
var _FORCE_GC = new OpaqueToken('Options.forceGc');
var _PREPARE = new OpaqueToken('Options.prepare');
var _EXECUTE = new OpaqueToken('Options.execute');
var _CAPABILITIES = new OpaqueToken('Options.capabilities');
var _USER_AGENT = new OpaqueToken('Options.userAgent');
var _MICRO_METRICS = new OpaqueToken('Options.microMetrics');
var _NOW = new OpaqueToken('Options.now');
var _WRITE_FILE = new OpaqueToken('Options.writeFile');
var _RECEIVED_DATA = new OpaqueToken('Options.receivedData');
var _REQUEST_COUNT = new OpaqueToken('Options.requestCount');
var _CAPTURE_FRAMES = new OpaqueToken('Options.frameCapture');
var _DEFAULT_PROVIDERS = [
bind(_DEFAULT_DESCRIPTION)
.toValue({}),
provide(_SAMPLE_DESCRIPTION, {useValue: {}}),
provide(_FORCE_GC, {useValue: false}),
provide(_PREPARE, {useValue: false}),
provide(_MICRO_METRICS, {useValue: {}}),
provide(_NOW, {useValue: () => DateWrapper.now()}),
provide(_RECEIVED_DATA, {useValue: false}),
provide(_REQUEST_COUNT, {useValue: false}),
provide(_CAPTURE_FRAMES, {useValue: false})
];
示例5: PROVIDERS
// TODO(tbosch): use static values when our transpiler supports them
static get PROVIDERS(): Provider[] { return _PROVIDERS; }
// TODO(tbosch): use static values when our transpiler supports them
static get SAMPLE_SIZE() { return _SAMPLE_SIZE; }
_sampleSize: number;
constructor(size) {
super();
this._sampleSize = size;
}
describe(): {[key: string]: any} { return {'sampleSize': this._sampleSize}; }
validate(completeSample: MeasureValues[]): MeasureValues[] {
if (completeSample.length >= this._sampleSize) {
return ListWrapper.slice(completeSample, completeSample.length - this._sampleSize,
completeSample.length);
} else {
return null;
}
}
}
var _SAMPLE_SIZE = new OpaqueToken('SizeValidator.sampleSize');
var _PROVIDERS = [
bind(SizeValidator)
.toFactory((size) => new SizeValidator(size), [_SAMPLE_SIZE]),
provide(_SAMPLE_SIZE, {useValue: 10})
];
示例6: reportMeasureValues
this._description = sampleDescription;
this._path = path;
this._writeFile = writeFile;
this._now = now;
}
reportMeasureValues(measureValues: MeasureValues): Promise<any> {
return PromiseWrapper.resolve(null);
}
reportSample(completeSample: MeasureValues[], validSample: MeasureValues[]): Promise<any> {
var content = Json.stringify({
'description': this._description,
'completeSample': completeSample,
'validSample': validSample
});
var filePath =
`${this._path}/${this._description.id}_${DateWrapper.toMillis(this._now())}.json`;
return this._writeFile(filePath, content);
}
}
var _PATH = new OpaqueToken('JsonFileReporter.path');
var _PROVIDERS = [
bind(JsonFileReporter)
.toFactory((sampleDescription, path, writeFile, now) =>
new JsonFileReporter(sampleDescription, path, writeFile, now),
[SampleDescription, _PATH, Options.WRITE_FILE, Options.NOW]),
provide(_PATH, {useValue: '.'})
];
示例7: OpaqueToken
import {topmost, Frame} from 'ui/frame';
import {Page} from 'ui/page';
import {provide, Provider, OpaqueToken} from '@angular/core/src/di';
import {device} from "platform";
import {NativeScriptAnimationDriver} from './animation-driver';
import {AnimationDriver} from "@angular/core/src/animation/animation_driver";
export const APP_ROOT_VIEW = new OpaqueToken('App Root View');
export const DEVICE = new OpaqueToken('platfrom device');
export const defaultPageProvider = provide(Page, { useFactory: getDefaultPage });
export function getDefaultPage(): Page {
const frame = topmost();
if (frame) {
return frame.currentPage;
} else {
return null;
}
}
export const defaultFrameProvider = provide(Frame, { useFactory: topmost });
export const defaultDeviceProvider = provide(DEVICE, { useValue: device });
export const defaultAnimationDriverProvider = provide(AnimationDriver, { useClass: NativeScriptAnimationDriver });
示例8: OpaqueToken
import {topmost} from 'ui/frame';
import {Page} from 'ui/page';
import {provide, Provider, OpaqueToken} from '@angular/core/src/di';
import {Device, ScreenMetrics, device, screen} from "platform";
export const APP_ROOT_VIEW = new OpaqueToken('App Root View');
export const DEVICE = new OpaqueToken('platfrom device');
export const defaultPageProvider = provide(Page, { useFactory: getDefaultPage });
export function getDefaultPage(): Page {
const frame = topmost();
if (frame) {
return frame.currentPage;
} else {
return null;
}
}
export const defaultDeviceProvider = provide(DEVICE, { useValue: device });