当前位置: 首页>>代码示例>>TypeScript>>正文


TypeScript invariant类代码示例

本文整理汇总了TypeScript中invariant的典型用法代码示例。如果您正苦于以下问题:TypeScript invariant类的具体用法?TypeScript invariant怎么用?TypeScript invariant使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了invariant类的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。

示例1: addCode

  /**
   * Evaluate another code.
   *
   * @param code The code to be evaluated.
   */
  addCode(code: string) {
    invariant(this.interpreter, 'Must call start() before addCode()')
    invariant(
      !this.interpreter.isRunning,
      'Cannot add more code when previous evaluation is in progress'
    )

    this.evalCode(code)
    this.emit('start')
  }
开发者ID:evansb,项目名称:source-toolchain,代码行数:15,代码来源:session.ts

示例2: getMetricFactory

function getMetricFactory(measure: any, mdObj: any) {
    const factory = rules.match(measure, mdObj);

    invariant(factory, `Unknown factory for: ${measure}`);

    return factory;
}
开发者ID:gooddata,项目名称:gooddata-js,代码行数:7,代码来源:experimental-executions.ts

示例3: match

    public match(subject: any, params: any) {
        const [, callback] = find(this.rules, ([tests]) => every(tests, test => test(subject, params)));

        invariant(callback, 'Callback not found :-(');

        return callback;
    }
开发者ID:gooddata,项目名称:gooddata-js,代码行数:7,代码来源:rules.ts

示例4: getDownloadUrlByVideoId

export async function getDownloadUrlByVideoId(videoId: number): Promise<string> {
    /**
     * 以下请求返回下载列表
     * https://api.live.bilibili.com/room/v1/Room/playUrl?cid=381652&quality=0&platform=web
     */
    const response = JSON.parse(await httpGet('https://api.live.bilibili.com/room/v1/Room/playUrl', {cid: videoId}) as string);
    const {code, msg, data} = response as any;
    invariant(code === 0 /** 成功 */, `getDownloadUrlByVideoId: 请求失败,状态码: ${code}, 信息:${msg}`);
    const {durl} = data;
    const {url} = durl[0];
    return url;
}
开发者ID:jf3096,项目名称:bilibili-live-video-noty,代码行数:12,代码来源:link.ts

示例5: injectReducer

  return function injectReducer(name, asyncReducer) { // tslint:disable-line:only-arrow-functions
    if (!isValid) { checkStore(store); }

    invariant(
      isString(name) && !isEmpty(name) && isFunction(asyncReducer),
      '(app/utils...) injectAsyncReducer: Expected `asyncReducer` to be a reducer function',
    );

    if (Reflect.has(store.asyncReducers, name)) { return; }

    store.asyncReducers[name] = asyncReducer; // eslint-disable-line no-param-reassign
    store.replaceReducer(createReducer(store.asyncReducers));
  };
开发者ID:StrikeForceZero,项目名称:react-boilerplate,代码行数:13,代码来源:asyncInjectors.ts

示例6: checkStore

export function checkStore(store) {
  const shape = {
    dispatch: isFunction,
    subscribe: isFunction,
    getState: isFunction,
    replaceReducer: isFunction,
    runSaga: isFunction,
    asyncReducers: isObject,
  };
  invariant(
    conformsTo(store, shape),
    '(app/utils...) asyncInjectors: Expected a valid redux store',
  );
}
开发者ID:StrikeForceZero,项目名称:react-boilerplate,代码行数:14,代码来源:asyncInjectors.ts

示例7: invariant

export const generateCFG = (state: StaticState) => {
  invariant(
    state.cfg.scopes.length === 1,
    `state.cfg.scopes must contain
  exactly the global scope before generating CFG`
  )
  invariant(
    state.cfg.scopes[0].node,
    `state.cfg.scopes[0] node 
  must be a program from the parser`
  )
  // Reset states
  nodeStack = []
  scopeQueue = [state.cfg.scopes[0]]
  edgeLabel = 'next'

  // Process Node BFS style
  while (scopeQueue.length > 0) {
    const current = scopeQueue[0].node!
    recursive(current, state, walkers)
    scopeQueue.shift()
  }
}
开发者ID:evansb,项目名称:source-toolchain,代码行数:23,代码来源:cfg.ts

示例8: injectSagas

  return function injectSagas(sagas) { // tslint:disable-line:only-arrow-functions
    if (!isValid) { checkStore(store); }

    invariant(
      Array.isArray(sagas),
      '(app/utils...) injectAsyncSagas: Expected `sagas` to be an array of generator functions',
    );

    warning(
      !isEmpty(sagas),
      '(app/utils...) injectAsyncSagas: Received an empty `sagas` array',
    );

    sagas.map(store.runSaga);
  };
开发者ID:StrikeForceZero,项目名称:react-boilerplate,代码行数:15,代码来源:asyncInjectors.ts

示例9: next

  /**
   * Evaluate single step of the program.
   */
  next() {
    invariant(this.genInterpreter, 'start() must be called before calling next')

    if (this.interpreter.isRunning) {
      const { value: nextInterpreter } = this.genInterpreter.next()

      // Stop interpreter on error
      if (!nextInterpreter.errors.isEmpty) {
        this.emit('errors', nextInterpreter.errors.toJS())
      }

      // Update states
      this.interpreter = nextInterpreter
      this.visualizer = nextVisualizer(this.visualizer, this.interpreter)

      // Emit appropriate events
      if (!this.interpreter.isRunning) {
        this.emit('done')
      } else {
        this.emit('next')
      }
    }
  }
开发者ID:evansb,项目名称:source-toolchain,代码行数:26,代码来源:session.ts

示例10: invariant

  devices.forEach(data => {
    const key = `sl_${data.api_name}_${data.short_version}`;

    // make sure there aren't any key collisions
    invariant(
      !customLaunchers[key],
      'Key `%s` already exists in customLaunchers',
      key
    );

    let browserName;
    if (data.api_name === 'iphone') {
      browserName = 'Safari';
    } else if (data.api_name === 'android') {
      const androidVersion = parseInt(data.short_version, 10);
      if (androidVersion < 6) {
        browserName = 'Browser';
      } else {
        browserName = 'Chrome';
      }
    } else {
      return;
    }

    customLaunchers[key] = {
      // recommended_backend_version can be an empty string
      appiumVersion:
        data.recommended_backend_version ||
        data.supported_backend_versions.slice(-1)[0],
      base: 'SauceLabs',
      browserName,
      deviceName: data.long_name,
      name: `${data.long_name} ${data.short_version}`,
      platformName: mobilePlatforms[data.api_name] || data.long_name,
      platformVersion: data.short_version,
    };
  });
开发者ID:petehunt,项目名称:jsxstyle,代码行数:37,代码来源:getCustomLaunchers.ts


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