本文整理汇总了TypeScript中@orbit/utils.assert函数的典型用法代码示例。如果您正苦于以下问题:TypeScript assert函数的具体用法?TypeScript assert怎么用?TypeScript assert使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了assert函数的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: constructor
constructor(options: ConnectionStrategyOptions) {
assert('A `source` must be specified for a ConnectionStrategy', !!options.source);
assert('`source` should be a Source name specified as a string', typeof options.source === 'string');
assert('`on` should be specified as the name of the event a ConnectionStrategy listens for', typeof options.on === 'string');
options.sources = [options.source];
let defaultName = `${options.source}:${options.on}`;
delete options.source;
if (options.target) {
assert('`target` should be a Source name specified as a string', typeof options.target === 'string');
options.sources.push(options.target);
defaultName += ` -> ${options.target}`;
if (typeof options.action === 'string') {
defaultName += `:${options.action}`;
}
delete options.target;
}
options.name = options.name || defaultName;
super(options);
this._event = options.on;
this._action = options.action;
this._catch = options.catch;
this._filter = options.filter;
this._blocking = !!options.blocking;
}
示例2: removeSource
removeSource(name: string): void {
let source = this._sources[name];
assert(`Source '${name}' has not been added to this coordinator.`, !!source);
assert(`A coordinator's sources can not be changed while it is active.`, !this._activated);
delete this._sources[name];
}
示例3: removeStrategy
removeStrategy(name: string): void {
let strategy = this._strategies[name];
assert(`Strategy '${name}' has not been added to this coordinator.`, !!strategy);
assert(`A coordinator's strategies can not be changed while it is active.`, !this._activated);
delete this._strategies[name];
}
示例4: addStrategy
addStrategy(strategy: Strategy): void {
const name = strategy.name;
assert(`A strategy named '${name}' has already been added to this coordinator.`, !this._strategies[name]);
assert(`A coordinator's strategies can not be changed while it is active.`, !this._activated);
this._strategies[name] = strategy;
}
示例5: addSource
addSource(source: Source): void {
const name = source.name;
assert(`Sources require a 'name' to be added to a coordinator.`, !!name);
assert(`A source named '${name}' has already been added to this coordinator.`, !this._sources[name]);
assert(`A coordinator's sources can not be changed while it is active.`, !this._activated);
this._sources[name] = source;
}
示例6: constructor
constructor(options: SyncStrategyOptions) {
let opts = options as ConnectionStrategyOptions;
assert('A `source` must be specified for a SyncStrategy', !!opts.source);
assert('A `target` must be specified for a SyncStrategy', !!opts.target);
assert('`source` should be a Source name specified as a string', typeof opts.source === 'string');
assert('`target` should be a Source name specified as a string', typeof opts.target === 'string');
opts.on = opts.on || 'transform';
opts.action = opts.action || 'sync';
super(opts);
}
示例7: constructor
/**
* Create a new IndexedDBSource.
*
* @constructor
* @param {Object} [settings = {}]
* @param {Schema} [settings.schema] Orbit Schema.
* @param {String} [settings.name] Optional. Name for source. Defaults to 'indexedDB'.
* @param {String} [settings.namespace] Optional. Namespace of the application. Will be used for the IndexedDB database name. Defaults to 'orbit'.
*/
constructor(settings: IndexedDBSourceSettings = {}) {
assert('IndexedDBSource\'s `schema` must be specified in `settings.schema` constructor argument', !!settings.schema);
assert('Your browser does not support IndexedDB!', supportsIndexedDB());
settings.name = settings.name || 'indexedDB';
super(settings);
this._namespace = settings.namespace || 'orbit';
}
示例8: constructor
/**
* Create a new LocalStorageSource.
*
* @constructor
* @param {Object} [settings] Settings.
* @param {Schema} [settings.schema] Schema for source.
* @param {String} [settings.namespace] Optional. Prefix for keys used in localStorage. Defaults to 'orbit'.
* @param {String} [settings.delimiter] Optional. Delimiter used to separate key segments in localStorage. Defaults to '/'.
*/
constructor(settings: LocalStorageSourceSettings = {}) {
assert('LocalStorageSource\'s `schema` must be specified in `settings.schema` constructor argument', !!settings.schema);
assert('Your browser does not support local storage!', supportsLocalStorage());
settings.name = settings.name || 'localStorage';
super(settings);
this._namespace = settings.namespace || 'orbit';
this._delimiter = settings.delimiter || '/';
}
示例9: queryable
/**
* Marks a source as "queryable" and adds an implementation of the `Queryable`
* interface.
*
* The `query` method is part of the "request flow" in Orbit. Requests trigger
* events before and after processing of each request. Observers can delay the
* resolution of a request by returning a promise in an event listener.
*
* The `Queryable` interface introduces the following events:
*
* - `beforeQuery` - emitted prior to the processing of `query`, this event
* includes the requested `Query` as an argument.
*
* - `query` - emitted after a `query` has successfully returned, this event's
* arguments include both the requested `Query` and the results.
*
* - `queryFail` - emitted when an error has occurred processing a query, this
* event's arguments include both the requested `Query` and the error.
*
* A queryable source must implement a private method `_query`, which performs
* the processing required for `query` and returns a promise that resolves to a
* set of results.
*
* @export
* @decorator
* @param {SourceClass} Klass
* @returns {void}
*/
export default function queryable(Klass: SourceClass): void {
let proto = Klass.prototype;
if (isQueryable(proto)) {
return;
}
assert('Queryable interface can only be applied to a Source', proto instanceof Source);
proto[QUERYABLE] = true;
proto.query = function(queryOrExpression: QueryOrExpression, options?: object, id?: string): Promise<any> {
const query = buildQuery(queryOrExpression, options, id, this.queryBuilder);
return this._enqueueRequest('query', query);
}
proto.__query__ = function(query: Query): Promise<any> {
return fulfillInSeries(this, 'beforeQuery', query)
.then(() => this._query(query))
.then((result) => {
return settleInSeries(this, 'query', query, result)
.then(() => result);
})
.catch((error) => {
return settleInSeries(this, 'queryFail', query, error)
.then(() => { throw error; });
});
}
}
示例10: pullable
/**
* Marks a source as "pullable" and adds an implementation of the `Pullable`
* interface.
*
* The `pull` method is part of the "request flow" in Orbit. Requests trigger
* events before and after processing of each request. Observers can delay the
* resolution of a request by returning a promise in an event listener.
*
* A pullable source emits the following events:
*
* - `beforePull` - emitted prior to the processing of `pull`, this event
* includes the requested `Query` as an argument.
*
* - `pull` - emitted after a `pull` has successfully been requested, this
* event's arguments include both the requested `Query` and an array of the
* resulting `Transform` instances.
*
* - `pullFail` - emitted when an error has occurred processing a `pull`, this
* event's arguments include both the requested `Query` and the error.
*
* A pullable source must implement a private method `_pull`, which performs
* the processing required for `pull` and returns a promise that resolves to an
* array of `Transform` instances.
*
* @export
* @decorator
* @param {SourceClass} Klass
* @returns {void}
*/
export default function pullable(Klass: SourceClass): void {
let proto = Klass.prototype;
if (isPullable(proto)) {
return;
}
assert('Pullable interface can only be applied to a Source', proto instanceof Source);
proto[PULLABLE] = true;
proto.pull = function(queryOrExpression: QueryOrExpression, options?: object, id?: string): Promise<Transform[]> {
const query = buildQuery(queryOrExpression, options, id, this.queryBuilder);
return this._enqueueRequest('pull', query);
}
proto.__pull__ = function(query: Query): Promise<Transform[]> {
return fulfillInSeries(this, 'beforePull', query)
.then(() => this._pull(query))
.then(result => this._transformed(result))
.then(result => {
return settleInSeries(this, 'pull', query, result)
.then(() => result);
})
.catch(error => {
return settleInSeries(this, 'pullFail', query, error)
.then(() => { throw error; });
});
}
}