當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。