當前位置: 首頁>>代碼示例>>TypeScript>>正文


TypeScript invariant.default函數代碼示例

本文整理匯總了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;未經允許,請勿轉載。