本文整理汇总了TypeScript中inferno-shared.throwError函数的典型用法代码示例。如果您正苦于以下问题:TypeScript throwError函数的具体用法?TypeScript throwError怎么用?TypeScript throwError使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了throwError函数的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: hydrate
function hydrate(
vNode: VNode,
dom: Element,
lifecycle: LifecycleClass,
context: Object,
isSVG: boolean
) {
const flags = vNode.flags;
if (flags & VNodeFlags.Component) {
hydrateComponent(
vNode,
dom,
lifecycle,
context,
isSVG,
(flags & VNodeFlags.ComponentClass) > 0
);
} else if (flags & VNodeFlags.Element) {
hydrateElement(vNode, dom, lifecycle, context, isSVG);
} else if (flags & VNodeFlags.Text) {
hydrateText(vNode, dom);
} else if (flags & VNodeFlags.Void) {
hydrateVoid(vNode, dom);
} else {
if (process.env.NODE_ENV !== "production") {
throwError(
`hydrate() expects a valid VNode, instead it received an object with the type "${typeof vNode}".`
);
}
throwError();
}
}
示例2: patchEvent
export function patchEvent(name: string, lastValue, nextValue, dom) {
if (lastValue !== nextValue) {
if (delegatedEvents.has(name)) {
handleEvent(name, lastValue, nextValue, dom);
} else {
const nameLowerCase = name.toLowerCase();
const domEvent = dom[nameLowerCase];
// if the function is wrapped, that means it's been controlled by a wrapper
if (domEvent && domEvent.wrapped) {
return;
}
if (!isFunction(nextValue) && !isNullOrUndef(nextValue)) {
const linkEvent = nextValue.event;
if (linkEvent && isFunction(linkEvent)) {
dom[nameLowerCase] = function(e) {
linkEvent(nextValue.data, e);
};
} else {
if (process.env.NODE_ENV !== "production") {
throwError(
`an event on a VNode "${name}". was not a function or a valid linkEvent.`
);
}
throwError();
}
} else {
dom[nameLowerCase] = nextValue;
}
}
}
}
示例3: createFunctionalComponentInput
export function createFunctionalComponentInput(
vNode: VNode,
component,
props: Props,
context: Object
) {
let input = component(props, context);
if (isArray(input)) {
if (process.env.NODE_ENV !== "production") {
throwError(
"a valid Inferno VNode (or null) must be returned from a component render. You may have returned an array or an invalid object."
);
}
throwError();
} else if (isInvalid(input)) {
input = createVoidVNode();
} else if (isStringOrNumber(input)) {
input = createTextVNode(input, null);
} else {
if (input.dom) {
input = directClone(input);
}
if (input.flags & VNodeFlags.Component) {
// if we have an input that is also a component, we run into a tricky situation
// where the root vNode needs to always have the correct DOM entry
// so we break monomorphism on our input and supply it our vNode as parentVNode
// we can optimise this in the future, but this gets us out of a lot of issues
input.parentVNode = vNode;
}
}
return input;
}
示例4: findDOMNode
export function findDOMNode(ref) {
if (!options.findDOMNodeEnabled) {
if (process.env.NODE_ENV !== "production") {
throwError(
"findDOMNode() has been disabled, use Inferno.options.findDOMNodeEnabled = true; enabled findDOMNode(). Warning this can significantly impact performance!"
);
}
throwError();
}
const dom = ref && ref.nodeType ? ref : null;
return componentToDOMNodeMap.get(ref) || dom;
}
示例5: mountRef
export function mountRef(dom: Element, value, lifecycle: LifecycleClass) {
if (isFunction(value)) {
lifecycle.addListener(() => value(dom));
} else {
if (isInvalid(value)) {
return;
}
if (process.env.NODE_ENV !== "production") {
throwError(
'string "refs" are not supported in Inferno 1.0. Use callback "refs" instead.'
);
}
throwError();
}
}
示例6: findAllInVNodeTree
export function findAllInVNodeTree(
vNodeTree: VNode,
predicate: (vNode: VNode) => boolean
): any {
if (isVNode(vNodeTree)) {
let result: VNode[] = predicate(vNodeTree) ? [vNodeTree] : [];
const children: any = vNodeTree.children;
if (isRenderedClassComponent(children)) {
result = result.concat(findAllInVNodeTree(
children._lastInput,
predicate
) as VNode[]);
} else if (isVNode(children)) {
result = result.concat(findAllInVNodeTree(
children,
predicate
) as VNode[]);
} else if (isArray(children)) {
children.forEach(child => {
result = result.concat(findAllInVNodeTree(child, predicate) as VNode[]);
});
}
return result;
} else {
throwError(
"findAllInVNodeTree(vNodeTree, predicate) vNodeTree must be a VNode instance"
);
}
}
示例7: connect
/**
* Wraps a component and provides stores as props
*/
function connect(arg1: any, arg2?: any): any {
if (typeof arg1 === "string") {
throwError("Store names should be provided as array");
}
if (Array.isArray(arg1)) {
// component needs stores
if (!arg2) {
// invoked as decorator
return _componentClass => connect(arg1, _componentClass);
} else {
// TODO: deprecate this invocation style
return inject.apply(null, arg1)(connect(arg2));
}
}
const componentClass = arg1;
// Stateless function component:
// If it is function but doesn't seem to be a Inferno class constructor,
// wrap it to a Inferno class automatically
if (
typeof componentClass === "function" &&
(!componentClass.prototype || !componentClass.prototype.render) &&
!componentClass.isReactClass &&
!Component.isPrototypeOf(componentClass)
) {
const newClass = createClass({
contextTypes: componentClass.contextTypes,
displayName: componentClass.displayName || componentClass.name,
getDefaultProps: () => componentClass.defaultProps,
propTypes: componentClass.propTypes,
render() {
return componentClass.call(this, this.props, this.context);
}
});
return connect(newClass);
}
if (!componentClass) {
throwError('Please pass a valid component to "connect"');
}
componentClass.isMobXReactObserver = true;
return makeReactive(componentClass);
}
示例8: mountClassComponentCallbacks
export function mountClassComponentCallbacks(
vNode: VNode,
ref,
instance,
lifecycle: LifecycleClass
) {
if (ref) {
if (isFunction(ref)) {
ref(instance);
} else {
if (process.env.NODE_ENV !== "production") {
if (isStringOrNumber(ref)) {
throwError(
'string "refs" are not supported in Inferno 1.0. Use callback "refs" instead.'
);
} else if (isObject(ref) && vNode.flags & VNodeFlags.ComponentClass) {
throwError(
"functional component lifecycle events are not supported on ES2015 class components."
);
} else {
throwError(
`a bad value for "ref" was used on component: "${JSON.stringify(
ref
)}"`
);
}
}
throwError();
}
}
const hasDidMount = !isUndefined(instance.componentDidMount);
const afterMount = options.afterMount;
if (hasDidMount || !isNull(afterMount)) {
lifecycle.addListener(() => {
instance._updating = true;
if (afterMount) {
afterMount(vNode);
}
if (hasDidMount) {
instance.componentDidMount();
}
instance._updating = false;
});
}
}
示例9: trackComponents
export function trackComponents() {
if (typeof WeakMap === "undefined") {
throwError(
"[inferno-mobx] tracking components is not supported in this browser."
);
}
if (!isDevtoolsEnabled) {
isDevtoolsEnabled = true;
}
}
示例10: mount
export function mount(
vNode: VNode,
parentDom: Element | null,
lifecycle: LifecycleClass,
context: Object,
isSVG: boolean
) {
const flags = vNode.flags;
if (flags & VNodeFlags.Element) {
return mountElement(vNode, parentDom, lifecycle, context, isSVG);
} else if (flags & VNodeFlags.Component) {
return mountComponent(
vNode,
parentDom,
lifecycle,
context,
isSVG,
(flags & VNodeFlags.ComponentClass) > 0
);
} else if (flags & VNodeFlags.Void) {
return mountVoid(vNode, parentDom);
} else if (flags & VNodeFlags.Text) {
return mountText(vNode, parentDom);
} else {
if (process.env.NODE_ENV !== "production") {
if (typeof vNode === "object") {
throwError(
`mount() received an object that's not a valid VNode, you should stringify it first. Object: "${JSON.stringify(
vNode
)}".`
);
} else {
throwError(
`mount() expects a valid VNode, instead it received an object with the type "${typeof vNode}".`
);
}
}
throwError();
}
}