• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

TypeScript utils.assert函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了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;
  }
开发者ID:SmuliS,项目名称:orbit.js,代码行数:25,代码来源:connection-strategy.ts


示例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];
  }
开发者ID:SmuliS,项目名称:orbit.js,代码行数:8,代码来源:coordinator.ts


示例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];
  }
开发者ID:SmuliS,项目名称:orbit.js,代码行数:8,代码来源:coordinator.ts


示例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;
  }
开发者ID:SmuliS,项目名称:orbit.js,代码行数:8,代码来源:coordinator.ts


示例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;
  }
开发者ID:SmuliS,项目名称:orbit.js,代码行数:9,代码来源:coordinator.ts


示例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);
 }
开发者ID:SmuliS,项目名称:orbit.js,代码行数:10,代码来源:sync-strategy.ts


示例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';
  }
开发者ID:SmuliS,项目名称:orbit.js,代码行数:19,代码来源:source.ts


示例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 || '/';
  }
开发者ID:SmuliS,项目名称:orbit.js,代码行数:20,代码来源:source.ts


示例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; });
      });
  }
}
开发者ID:SmuliS,项目名称:orbit.js,代码行数:57,代码来源:queryable.ts


示例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; });
      });
  }
}
开发者ID:SmuliS,项目名称:orbit.js,代码行数:59,代码来源:pullable.ts



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
TypeScript utils.clone函数代码示例发布时间:2022-05-28
下一篇:
TypeScript memory.MemoryCache类代码示例发布时间:2022-05-28
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap