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

TypeScript invariant.default函数代码示例

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

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



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

示例1: cloneWithRef

export default function cloneWithRef(
	element: any,
	newRef: any,
): React.ReactElement<any> {
	const previousRef = element.ref
	invariant(
		typeof previousRef !== 'string',
		'Cannot connect React DnD to an element with an existing string ref. ' +
			'Please convert it to use a callback ref instead, or wrap it into a <span> or <div>. ' +
			'Read more: https://facebook.github.io/react/docs/more-about-refs.html#the-ref-callback-attribute',
	)

	if (!previousRef) {
		// When there is no ref on the element, use the new ref directly
		return cloneElement(element, {
			ref: newRef,
		})
	}

	return cloneElement(element, {
		ref: (node: any) => {
			newRef(node)
			if (previousRef) {
				previousRef(node)
			}
		},
	})
}
开发者ID:chenermeng,项目名称:react-dnd,代码行数:28,代码来源:cloneWithRef.ts


示例2: subscribeToStateChange

	public subscribeToStateChange(
		listener: Listener,
		options: { handlerIds: string[] | undefined } = { handlerIds: undefined },
	): Unsubscribe {
		const { handlerIds } = options
		invariant(typeof listener === 'function', 'listener must be a function.')
		invariant(
			typeof handlerIds === 'undefined' || Array.isArray(handlerIds),
			'handlerIds, when specified, must be an array of strings.',
		)

		let prevStateId = this.store.getState().stateId
		const handleChange = () => {
			const state = this.store.getState()
			const currentStateId = state.stateId
			try {
				const canSkipListener =
					currentStateId === prevStateId ||
					(currentStateId === prevStateId + 1 &&
						!areDirty(state.dirtyHandlerIds, handlerIds))

				if (!canSkipListener) {
					listener()
				}
			} finally {
				prevStateId = currentStateId
			}
		}

		return this.store.subscribe(handleChange)
	}
开发者ID:chenermeng,项目名称:react-dnd,代码行数:31,代码来源:DragDropMonitorImpl.ts


示例3: delay

function * aiJudgeScore () {
  const { board, player, ai, version } = yield select()
  const scores = []
  const judge = judgeScores[version]
  invariant(judge, 'version error')
  const chess = getCandidate(player)
  for (let r = 0; r < 8; r += 1) {
    for (let c = 0; c < 8; c += 1) {
      if (board[r][c] === chess) {
        let score = judge(board, ai, r, c)
        scores.push({
          row: r,
          col: c,
          score: score
        })
      }
    }
  }
  invariant(scores.length, 'Invalid State: Candidates not place')
  const { score } = head(orderBy(scores, 'score', 'desc'))
  const { row, col } = sample(filter(scores, ['score', score])) // A little random
  yield delay(300) // A little delay
  yield put(
    pushLog({
      player,
      pos: `(${row}, ${col})`
    })
  )
  yield call(flipAllChess, { row, col, player })
  yield put(placeChess(row, col, player))
}
开发者ID:DanSnow,项目名称:react-reversi,代码行数:31,代码来源:saga.ts


示例4: verifyInvariants

function verifyInvariants(monitor: DragDropMonitor) {
	invariant(monitor.isDragging(), 'Cannot call drop while not dragging.')
	invariant(
		!monitor.didDrop(),
		'Cannot call drop twice during one drag operation.',
	)
}
开发者ID:gaearon,项目名称:react-dnd,代码行数:7,代码来源:drop.ts


示例5: verifyInvariants

function verifyInvariants(
	sourceIds: string[],
	monitor: DragDropMonitor,
	registry: HandlerRegistry,
) {
	invariant(!monitor.isDragging(), 'Cannot call beginDrag while dragging.')
	for (const s of sourceIds) {
		invariant(registry.getSource(s), 'Expected sourceIds to be registered.')
	}
}
开发者ID:gaearon,项目名称:react-dnd,代码行数:10,代码来源:beginDrag.ts


示例6: getCurrentPosition

function getCurrentPosition(
  success: GeoSuccessCallback,
  error: GeoErrorCallback = () => {},
  options: LocationOptions = {}
): void {
  invariant(typeof success === 'function', 'Must provide a valid success callback.');

  invariant(typeof options === 'object', 'options must be an object.');

  _getCurrentPositionAsyncWrapper(success, error, options);
}
开发者ID:schneizel1,项目名称:usuario-interfas,代码行数:11,代码来源:Location.ts


示例7: validateSourceContract

export function validateSourceContract(source: DragSource) {
	invariant(
		typeof source.canDrag === 'function',
		'Expected canDrag to be a function.',
	)
	invariant(
		typeof source.beginDrag === 'function',
		'Expected beginDrag to be a function.',
	)
	invariant(
		typeof source.endDrag === 'function',
		'Expected endDrag to be a function.',
	)
}
开发者ID:chenermeng,项目名称:react-dnd,代码行数:14,代码来源:contracts.ts


示例8: validateTargetContract

export function validateTargetContract(target: DropTarget) {
	invariant(
		typeof target.canDrop === 'function',
		'Expected canDrop to be a function.',
	)
	invariant(
		typeof target.hover === 'function',
		'Expected hover to be a function.',
	)
	invariant(
		typeof target.drop === 'function',
		'Expected beginDrag to be a function.',
	)
}
开发者ID:chenermeng,项目名称:react-dnd,代码行数:14,代码来源:contracts.ts


示例9: useRef

export function useDrop<
	DragObject extends DragObjectWithType,
	DropResult,
	CollectedProps
>(
	spec: DropTargetHookSpec<DragObject, DropResult, CollectedProps>,
): [CollectedProps, ConnectDropTarget] {
	const specRef = useRef(spec)
	invariant(spec.accept != null, 'accept must be defined')

	const [monitor, connector] = useDropTargetMonitor()
	useDropHandler(specRef, monitor, connector)

	const result: CollectedProps = useMonitorOutput(
		monitor,
		specRef.current.collect || (() => ({} as CollectedProps)),
		() => connector.reconnect(),
	)

	const connectDropTarget = useMemo(() => connector.hooks.dropTarget(), [
		connector,
	])

	useEffect(() => {
		connector.dropTargetOptions = spec.options || null
		connector.reconnect()
	}, [spec.options])
	return [result, connectDropTarget]
}
开发者ID:gaearon,项目名称:react-dnd,代码行数:29,代码来源:useDrop.ts


示例10: timeoutForField

export function timeoutForField(field: GraphQLField<any, any>) {
  const fieldDirectives = field.astNode && field.astNode.directives
  const directive = fieldDirectives && fieldDirectives.find(directive => directive.name.value === "timeout")
  if (directive) {
    const args = directive && directive.arguments
    const arg = args && args[0]
    invariant(arg && arg.name.value === "ms", "graphqlTimeoutMiddleware: The `@timeout(ms: …)` argument is required.")
    const value = arg!.value
    if (value.kind === "IntValue") {
      return parseInt(value.value)
    } else {
      invariant(false, `graphqlTimeoutMiddleware: Expected \`@timeout(ms: …)\` to be a \`IntValue\`, got \`${value.kind}\` instead.`)
      return null
    }
  }
  return null
}
开发者ID:xtina-starr,项目名称:metaphysics,代码行数:17,代码来源:graphqlTimeoutMiddleware.ts



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
TypeScript inversify.decorate函数代码示例发布时间:2022-05-25
下一篇:
TypeScript testUtils.TOKEN_LOCATIONS类代码示例发布时间:2022-05-25
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

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

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

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