本文整理汇总了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')
}
示例2: getMetricFactory
function getMetricFactory(measure: any, mdObj: any) {
const factory = rules.match(measure, mdObj);
invariant(factory, `Unknown factory for: ${measure}`);
return factory;
}
示例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;
}
示例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;
}
示例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));
};
示例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',
);
}
示例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()
}
}
示例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);
};
示例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')
}
}
}
示例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,
};
});