本文整理汇总了TypeScript中inferno-shared.isFunction函数的典型用法代码示例。如果您正苦于以下问题:TypeScript isFunction函数的具体用法?TypeScript isFunction怎么用?TypeScript isFunction使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了isFunction函数的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的TypeScript代码示例。
示例1: 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;
}
}
}
}
开发者ID:russelgal,项目名称:inferno,代码行数:32,代码来源:patching.ts
示例2: isRenderedClassComponent
export function isRenderedClassComponent(instance: any): boolean {
return (
Boolean(instance) &&
isObject(instance) &&
isVNode((instance as any)._vNode) &&
isFunction((instance as any).render) &&
isFunction((instance as any).setState)
);
}
开发者ID:russelgal,项目名称:inferno,代码行数:9,代码来源:index.ts
示例3: isRenderedClassComponentOfType
export function isRenderedClassComponentOfType(
instance: any,
type: Function
): boolean {
return (
isRenderedClassComponent(instance) &&
isFunction(type) &&
instance._vNode.type === type
);
}
开发者ID:russelgal,项目名称:inferno,代码行数:10,代码来源:index.ts
示例4: 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();
}
}
开发者ID:russelgal,项目名称:inferno,代码行数:15,代码来源:mounting.ts
示例5: 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;
});
}
}
开发者ID:russelgal,项目名称:inferno,代码行数:46,代码来源:mounting.ts
示例6: findAllInRenderedTree
return findAllInRenderedTree(renderedTree, instance => {
if (isDOMVNode(instance)) {
let domClassName = (instance.dom as Element).className;
if (
!isString(domClassName) &&
!isNullOrUndef(instance.dom) &&
isFunction(instance.dom.getAttribute)
) {
// SVG || null, probably
domClassName = (instance.dom as Element).getAttribute("class") || "";
}
const domClassList = parseSelector(domClassName);
return parseSelector(classNames).every(className => {
return domClassList.indexOf(className) !== -1;
});
}
return false;
}).map(instance => instance.dom);
开发者ID:russelgal,项目名称:inferno,代码行数:18,代码来源:index.ts
示例7: function
return function(name, _props, ...children) {
const props = _props || {};
const ref = props.ref;
if (typeof ref === "string" && !isNull(currentComponent)) {
currentComponent.refs = currentComponent.refs || {};
props.ref = function(val) {
this.refs[ref] = val;
}.bind(currentComponent);
}
if (typeof name === "string") {
normalizeProps(name, props);
}
// React supports iterable children, in addition to Array-like
if (hasSymbolSupport) {
for (let i = 0, len = children.length; i < len; i++) {
const child = children[i];
if (
child &&
!isArray(child) &&
!isString(child) &&
isFunction(child[Symbol.iterator])
) {
children[i] = iterableToArray(child[Symbol.iterator]());
}
}
}
const vnode = originalFunction(name, props, ...children);
if (vnode.className) {
vnode.props = vnode.props || {};
vnode.props.className = vnode.className;
}
return vnode;
};
开发者ID:russelgal,项目名称:inferno,代码行数:37,代码来源:index.ts
示例8: renderVNodeToString
function renderVNodeToString(
vNode,
parent,
context,
firstChild
): string | undefined {
const flags = vNode.flags;
const type = vNode.type;
const props = vNode.props || EMPTY_OBJ;
const children = vNode.children;
if ((flags & VNodeFlags.Component) > 0) {
const isClass = flags & VNodeFlags.ComponentClass;
if (isClass) {
const instance = new type(props, context);
instance._blockSetState = false;
let childContext;
if (isFunction(instance.getChildContext)) {
childContext = instance.getChildContext();
}
if (isNullOrUndef(childContext)) {
childContext = context;
} else {
childContext = combineFrom(context, childContext);
}
if (instance.props === EMPTY_OBJ) {
instance.props = props;
}
instance.context = context;
instance._unmounted = false;
if (isFunction(instance.componentWillMount)) {
instance._blockRender = true;
instance.componentWillMount();
if (instance._pendingSetState) {
const state = instance.state;
const pending = instance._pendingState;
if (state === null) {
instance.state = pending;
} else {
for (const key in pending) {
state[key] = pending[key];
}
}
instance._pendingSetState = false;
instance._pendingState = null;
}
instance._blockRender = false;
}
const nextVNode = instance.render(props, instance.state, instance.context);
// In case render returns invalid stuff
if (isInvalid(nextVNode)) {
return "<!--!-->";
}
return renderVNodeToString(nextVNode, vNode, childContext, true);
} else {
const nextVNode = type(props, context);
if (isInvalid(nextVNode)) {
return "<!--!-->";
}
return renderVNodeToString(nextVNode, vNode, context, true);
}
} else if ((flags & VNodeFlags.Element) > 0) {
let renderedString = `<${type}`;
let html;
const isVoidElement = voidElements.has(type);
const className = vNode.className;
if (isString(className)) {
renderedString += ` class="${escapeText(className)}"`;
} else if (isNumber(className)) {
renderedString += ` class="${className}"`;
}
if (!isNull(props)) {
for (const prop in props) {
const value = props[prop];
if (prop === "dangerouslySetInnerHTML") {
html = value.__html;
} else if (prop === "style") {
renderedString += ` style="${renderStylesToString(props.style)}"`;
} else if (prop === "children") {
// Ignore children as prop.
} else if (prop === "defaultValue") {
// Use default values if normal values are not present
if (!props.value) {
renderedString += ` value="${isString(value)
? escapeText(value)
: value}"`;
}
} else if (prop === "defaultChecked") {
// Use default values if normal values are not present
if (!props.checked) {
renderedString += ` checked="${value}"`;
}
} else {
//.........这里部分代码省略.........
开发者ID:russelgal,项目名称:inferno,代码行数:101,代码来源:renderToString.ts
示例9: linkEvent
export function linkEvent(data, event) {
if (isFunction(event)) {
return { data, event };
}
return null; // Return null when event is invalid, to avoid creating unnecessary event handlers
}
开发者ID:russelgal,项目名称:inferno,代码行数:6,代码来源:linkEvent.ts
示例10: unmount
export function unmount(
vNode: VNode,
parentDom: Element | null,
lifecycle: LifecycleClass,
canRecycle: boolean,
isRecycling: boolean
) {
const flags = vNode.flags;
const dom = vNode.dom as Element;
if (flags & VNodeFlags.Component) {
const instance = vNode.children as any;
const isStatefulComponent: boolean =
(flags & VNodeFlags.ComponentClass) > 0;
const props = vNode.props || EMPTY_OBJ;
const ref = vNode.ref as any;
if (!isRecycling) {
if (isStatefulComponent) {
if (!instance._unmounted) {
if (!isNull(options.beforeUnmount)) {
options.beforeUnmount(vNode);
}
if (!isUndefined(instance.componentWillUnmount)) {
instance.componentWillUnmount();
}
if (ref && !isRecycling) {
ref(null);
}
instance._unmounted = true;
if (options.findDOMNodeEnabled) {
componentToDOMNodeMap.delete(instance);
}
unmount(
instance._lastInput,
null,
instance._lifecycle,
false,
isRecycling
);
}
} else {
if (!isNullOrUndef(ref)) {
if (!isNullOrUndef(ref.onComponentWillUnmount)) {
ref.onComponentWillUnmount(dom, props);
}
}
unmount(instance, null, lifecycle, false, isRecycling);
}
}
if (
options.recyclingEnabled &&
!isStatefulComponent &&
(parentDom || canRecycle)
) {
poolComponent(vNode);
}
} else if (flags & VNodeFlags.Element) {
const ref = vNode.ref as any;
const props = vNode.props;
if (!isRecycling && isFunction(ref)) {
ref(null);
}
const children = vNode.children;
if (!isNullOrUndef(children)) {
if (isArray(children)) {
for (
let i = 0, len = (children as Array<string | number | VNode>).length;
i < len;
i++
) {
const child = children[i];
if (!isInvalid(child) && isObject(child)) {
unmount(child as VNode, null, lifecycle, false, isRecycling);
}
}
} else if (isObject(children)) {
unmount(children as VNode, null, lifecycle, false, isRecycling);
}
}
if (!isNull(props)) {
for (const name in props) {
// do not add a hasOwnProperty check here, it affects performance
if (props[name] !== null && isAttrAnEvent(name)) {
patchEvent(name, props[name], null, dom);
// We need to set this null, because same props otherwise come back if SCU returns false and we are recyling
props[name] = null;
}
}
}
if (options.recyclingEnabled && (parentDom || canRecycle)) {
poolElement(vNode);
}
//.........这里部分代码省略.........
开发者ID:russelgal,项目名称:inferno,代码行数:101,代码来源:unmounting.ts
注:本文中的inferno-shared.isFunction函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论