code
stringlengths
24
2.07M
docstring
stringlengths
25
85.3k
func_name
stringlengths
1
92
language
stringclasses
1 value
repo
stringlengths
5
64
path
stringlengths
4
172
url
stringlengths
44
218
license
stringclasses
7 values
function resolveScopedSlots( fns: Array<[string, Function]>, ): { [key: string]: Function }
Runtime helper for resolving raw children VNodes into a slot object.
resolveScopedSlots
javascript
GeekyAnts/vue-native-core
src/core/instance/render-helpers/resolve-slots.js
https://github.com/GeekyAnts/vue-native-core/blob/master/src/core/instance/render-helpers/resolve-slots.js
MIT
constructor() { this.id = uid++ this.subs = [] }
A dep is an observable that can have multiple directives subscribing to it.
constructor
javascript
GeekyAnts/vue-native-core
src/core/observer/dep.js
https://github.com/GeekyAnts/vue-native-core/blob/master/src/core/observer/dep.js
MIT
removeSub(sub: Watcher) { remove(this.subs, sub) }
A dep is an observable that can have multiple directives subscribing to it.
removeSub
javascript
GeekyAnts/vue-native-core
src/core/observer/dep.js
https://github.com/GeekyAnts/vue-native-core/blob/master/src/core/observer/dep.js
MIT
depend() { if (Dep.target) { Dep.target.addDep(this) } }
A dep is an observable that can have multiple directives subscribing to it.
depend
javascript
GeekyAnts/vue-native-core
src/core/observer/dep.js
https://github.com/GeekyAnts/vue-native-core/blob/master/src/core/observer/dep.js
MIT
notify() { // stabilize the subscriber list first const subs = this.subs.slice() for (let i = 0, l = subs.length; i < l; i++) { subs[i].update() } }
A dep is an observable that can have multiple directives subscribing to it.
notify
javascript
GeekyAnts/vue-native-core
src/core/observer/dep.js
https://github.com/GeekyAnts/vue-native-core/blob/master/src/core/observer/dep.js
MIT
function pushTarget(_target: Watcher) { if (Dep.target) targetStack.push(Dep.target) Dep.target = _target }
A dep is an observable that can have multiple directives subscribing to it.
pushTarget
javascript
GeekyAnts/vue-native-core
src/core/observer/dep.js
https://github.com/GeekyAnts/vue-native-core/blob/master/src/core/observer/dep.js
MIT
function popTarget() { Dep.target = targetStack.pop() }
A dep is an observable that can have multiple directives subscribing to it.
popTarget
javascript
GeekyAnts/vue-native-core
src/core/observer/dep.js
https://github.com/GeekyAnts/vue-native-core/blob/master/src/core/observer/dep.js
MIT
for (let i = 0, l = keys.length; i < l; i++) { const key = keys[i] def(target, key, src[key]) }
Augment an target Object or Array by defining hidden properties.
for
javascript
GeekyAnts/vue-native-core
src/core/observer/index.js
https://github.com/GeekyAnts/vue-native-core/blob/master/src/core/observer/index.js
MIT
function dependArray(value: Array<any>) { for (let e, i = 0, l = value.length; i < l; i++) { e = value[i] e && e.__ob__ && e.__ob__.dep.depend() if (Array.isArray(e)) { dependArray(e) } } }
Collect dependencies on array elements when the array is touched, since we cannot intercept array element access like property getters.
dependArray
javascript
GeekyAnts/vue-native-core
src/core/observer/index.js
https://github.com/GeekyAnts/vue-native-core/blob/master/src/core/observer/index.js
MIT
function nextTickHandler() { pending = false const copies = callbacks.slice(0) callbacks.length = 0 for (let i = 0; i < copies.length; i++) { copies[i]() } }
Defer a task to execute it asynchronously.
nextTickHandler
javascript
GeekyAnts/vue-native-core
src/core/util/env.js
https://github.com/GeekyAnts/vue-native-core/blob/master/src/core/util/env.js
MIT
constructor() { this.set = Object.create(null) }
Defer a task to execute it asynchronously.
constructor
javascript
GeekyAnts/vue-native-core
src/core/util/env.js
https://github.com/GeekyAnts/vue-native-core/blob/master/src/core/util/env.js
MIT
has(key: string | number) { return this.set[key] === true }
Defer a task to execute it asynchronously.
has
javascript
GeekyAnts/vue-native-core
src/core/util/env.js
https://github.com/GeekyAnts/vue-native-core/blob/master/src/core/util/env.js
MIT
add(key: string | number) { this.set[key] = true }
Defer a task to execute it asynchronously.
add
javascript
GeekyAnts/vue-native-core
src/core/util/env.js
https://github.com/GeekyAnts/vue-native-core/blob/master/src/core/util/env.js
MIT
clear() { this.set = Object.create(null) }
Defer a task to execute it asynchronously.
clear
javascript
GeekyAnts/vue-native-core
src/core/util/env.js
https://github.com/GeekyAnts/vue-native-core/blob/master/src/core/util/env.js
MIT
function isReserved(str: string): boolean { const c = (str + '').charCodeAt(0) return c === 0x24 || c === 0x5f }
Check if a string starts with $ or _
isReserved
javascript
GeekyAnts/vue-native-core
src/core/util/lang.js
https://github.com/GeekyAnts/vue-native-core/blob/master/src/core/util/lang.js
MIT
function mergeData(to: Object, from: ?Object): Object { if (!from) return to let key, toVal, fromVal const keys = Object.keys(from) for (let i = 0; i < keys.length; i++) { key = keys[i] toVal = to[key] fromVal = from[key] if (!hasOwn(to, key)) { set(to, key, fromVal) } else if (isPlainObject(toVal) && isPlainObject(fromVal)) { mergeData(toVal, fromVal) } } return to }
Helper that recursively merges two data objects together.
mergeData
javascript
GeekyAnts/vue-native-core
src/core/util/options.js
https://github.com/GeekyAnts/vue-native-core/blob/master/src/core/util/options.js
MIT
function mergeHook( parentVal: ?Array<Function>, childVal: ?Function | ?Array<Function>, ): ?Array<Function> { return childVal ? parentVal ? parentVal.concat(childVal) : Array.isArray(childVal) ? childVal : [childVal] : parentVal } LIFECYCLE_HOOKS.forEach(hook => { strats[hook] = mergeHook }) /** * Assets * * When a vm is present (instance creation), we need to do * a three-way merge between constructor options, instance * options and parent options. */ function mergeAssets(parentVal: ?Object, childVal: ?Object): Object { const res = Object.create(parentVal || null) return childVal ? extend(res, childVal) : res } ASSET_TYPES.forEach(function(type) { strats[type + 's'] = mergeAssets }) /** * Watchers. * * Watchers hashes should not overwrite one * another, so we merge them as arrays. */ strats.watch = function(parentVal: ?Object, childVal: ?Object): ?Object { /* istanbul ignore if */ if (!childVal) return Object.create(parentVal || null) if (!parentVal) return childVal const ret = {} extend(ret, parentVal) for (const key in childVal) { let parent = ret[key] const child = childVal[key] if (parent && !Array.isArray(parent)) { parent = [parent] } ret[key] = parent ? parent.concat(child) : [child] } return ret } /** * Other object hashes. */ strats.props = strats.methods = strats.computed = function( parentVal: ?Object, childVal: ?Object, ): ?Object { if (!childVal) return Object.create(parentVal || null) if (!parentVal) return childVal const ret = Object.create(null) extend(ret, parentVal) extend(ret, childVal) return ret } /** * Default strategy. */ const defaultStrat = function(parentVal: any, childVal: any): any { return childVal === undefined ? parentVal : childVal } /** * Validate component names */ function checkComponents(options: Object) { for (const key in options.components) { const lower = key.toLowerCase() if (isBuiltInTag(lower) || config.isReservedTag(lower)) { warn( 'Do not use built-in or reserved HTML elements as component ' + 'id: ' + key, ) } } } /** * Ensure all props option syntax are normalized into the * Object-based format. */ function normalizeProps(options: Object) { const props = options.props if (!props) return const res = {} let i, val, name if (Array.isArray(props)) { i = props.length while (i--) { val = props[i] if (typeof val === 'string') { name = camelize(val) res[name] = { type: null } } else if (process.env.NODE_ENV !== 'production') { warn('props must be strings when using array syntax.') } } } else if (isPlainObject(props)) { for (const key in props) { val = props[key] name = camelize(key) res[name] = isPlainObject(val) ? val : { type: val } } } options.props = res } /** * Normalize raw function directives into object format. */ function normalizeDirectives(options: Object) { const dirs = options.directives if (dirs) { for (const key in dirs) { const def = dirs[key] if (typeof def === 'function') { dirs[key] = { bind: def, update: def } } } } } /** * Merge two option objects into a new one. * Core utility used in both instantiation and inheritance. */ export function mergeOptions( parent: Object, child: Object, vm?: Component, ): Object { if (process.env.NODE_ENV !== 'production') { checkComponents(child) } if (typeof child === 'function') { child = child.options } normalizeProps(child) normalizeDirectives(child) const extendsFrom = child.extends if (extendsFrom) { parent = mergeOptions(parent, extendsFrom, vm) }
Hooks and props are merged as arrays.
mergeHook
javascript
GeekyAnts/vue-native-core
src/core/util/options.js
https://github.com/GeekyAnts/vue-native-core/blob/master/src/core/util/options.js
MIT
function mergeField(key) { const strat = strats[key] || defaultStrat options[key] = strat(parent[key], child[key], vm, key) }
Merge two option objects into a new one. Core utility used in both instantiation and inheritance.
mergeField
javascript
GeekyAnts/vue-native-core
src/core/util/options.js
https://github.com/GeekyAnts/vue-native-core/blob/master/src/core/util/options.js
MIT
function getPropDefaultValue( vm: ?Component, prop: PropOptions, key: string, ): any { // no default, return undefined if (!hasOwn(prop, 'default')) { return undefined } const def = prop.default // warn against non-factory defaults for Object & Array if (process.env.NODE_ENV !== 'production' && isObject(def)) { warn( 'Invalid default value for prop "' + key + '": ' + 'Props with type Object/Array must use a factory function ' + 'to return the default value.', vm, ) } // the raw prop value was also undefined from previous render, // return previous default value to avoid unnecessary watcher trigger if ( vm && vm.$options.propsData && vm.$options.propsData[key] === undefined && vm._props[key] !== undefined ) { return vm._props[key] } // call factory function for non-Function types // a value is Function if its prototype is function even across different execution context return typeof def === 'function' && getType(prop.type) !== 'Function' ? def.call(vm) : def }
Get the default value of a prop.
getPropDefaultValue
javascript
GeekyAnts/vue-native-core
src/core/util/props.js
https://github.com/GeekyAnts/vue-native-core/blob/master/src/core/util/props.js
MIT
function isType(type, fn) { if (!Array.isArray(fn)) { return getType(fn) === getType(type) } for (let i = 0, len = fn.length; i < len; i++) { if (getType(fn[i]) === getType(type)) { return true } } /* istanbul ignore next */ return false }
Use function string name to check built-in types, because a simple equality check will fail when running across different vms / iframes.
isType
javascript
GeekyAnts/vue-native-core
src/core/util/props.js
https://github.com/GeekyAnts/vue-native-core/blob/master/src/core/util/props.js
MIT
function observer(componentClass) { if ( typeof componentClass === 'function' && (!componentClass.prototype || !componentClass.prototype.render) && !componentClass.isReactClass && // eslint-disable-next-line no-prototype-builtins !React.Component.isPrototypeOf(componentClass) ) { class ObserverComponent extends React.Component { render() { return componentClass.call(this, this.props, this.context) } } ObserverComponent.displayName = componentClass.displayName || componentClass.name ObserverComponent.contextTypes = componentClass.contextTypes ObserverComponent.propTypes = componentClass.propTypes ObserverComponent.defaultProps = componentClass.defaultProps return observer(ObserverComponent) } if (!componentClass) { throw new Error("Please pass a valid component to 'observer'") } const target = componentClass.prototype || componentClass mixinLifecycleEvents(target) return componentClass }
Reference to mobx https://github.com/mobxjs/mobx-react-vue/blob/master/src/observer.js
observer
javascript
GeekyAnts/vue-native-core
src/platforms/vue-native/observer.js
https://github.com/GeekyAnts/vue-native-core/blob/master/src/platforms/vue-native/observer.js
MIT
render() { return componentClass.call(this, this.props, this.context) }
Reference to mobx https://github.com/mobxjs/mobx-react-vue/blob/master/src/observer.js
render
javascript
GeekyAnts/vue-native-core
src/platforms/vue-native/observer.js
https://github.com/GeekyAnts/vue-native-core/blob/master/src/platforms/vue-native/observer.js
MIT
function mixinLifecycleEvents(target) { for (const key in lifecycleMixin) { if ( key === 'shouldComponentUpdate' && typeof target.shouldComponentUpdate === 'function' ) { continue } patch(target, key) } }
Reference to mobx https://github.com/mobxjs/mobx-react-vue/blob/master/src/observer.js
mixinLifecycleEvents
javascript
GeekyAnts/vue-native-core
src/platforms/vue-native/observer.js
https://github.com/GeekyAnts/vue-native-core/blob/master/src/platforms/vue-native/observer.js
MIT
UNSAFE_componentWillMount() { const cb = this.forceUpdate.bind(this) const render = this.render.bind(this) const watcher = new Watcher({ _watchers: [] }, render, cb, { lazy: true }) this.render = watcher.get.bind(watcher) watcher.lazy = false watcher.run = cb this.$vuewatcher = watcher }
Reference to mobx https://github.com/mobxjs/mobx-react-vue/blob/master/src/observer.js
UNSAFE_componentWillMount
javascript
GeekyAnts/vue-native-core
src/platforms/vue-native/observer.js
https://github.com/GeekyAnts/vue-native-core/blob/master/src/platforms/vue-native/observer.js
MIT
shouldComponentUpdate(nextProps, nextState) { if (this.state !== nextState) { return true } return isObjectShallowModified(this.props, nextProps) }
Reference to mobx https://github.com/mobxjs/mobx-react-vue/blob/master/src/observer.js
shouldComponentUpdate
javascript
GeekyAnts/vue-native-core
src/platforms/vue-native/observer.js
https://github.com/GeekyAnts/vue-native-core/blob/master/src/platforms/vue-native/observer.js
MIT
function patch(target, funcName) { const base = target[funcName] const mixinFunc = lifecycleMixin[funcName] target[funcName] = !base ? function() { return mixinFunc.apply(this, arguments) } : function() { mixinFunc.apply(this, arguments) return base.apply(this, arguments) } }
Reference to mobx https://github.com/mobxjs/mobx-react-vue/blob/master/src/observer.js
patch
javascript
GeekyAnts/vue-native-core
src/platforms/vue-native/observer.js
https://github.com/GeekyAnts/vue-native-core/blob/master/src/platforms/vue-native/observer.js
MIT
function isObjectShallowModified(prev, next) { if ( prev == null || next == null || typeof prev !== 'object' || typeof next !== 'object' ) { return prev !== next } const keys = Object.keys(prev) if (keys.length !== Object.keys(next).length) { return true } let key for (let i = keys.length - 1; i >= 0; i--) { key = keys[i] if (next[key] !== prev[key]) { return true } } return false }
Reference to mobx https://github.com/mobxjs/mobx-react-vue/blob/master/src/observer.js
isObjectShallowModified
javascript
GeekyAnts/vue-native-core
src/platforms/vue-native/observer.js
https://github.com/GeekyAnts/vue-native-core/blob/master/src/platforms/vue-native/observer.js
MIT
genTextExpression(ast) { let code = super.genTextExpression(ast) code = code.replace(/^"\\n\s*/, '"').replace(/\\n\s*"$/, '"') return code }
override gen text expression @param {Object} ast
genTextExpression
javascript
GeekyAnts/vue-native-core
src/platforms/vue-native/compiler/codegen/NativeRenderGenerator.js
https://github.com/GeekyAnts/vue-native-core/blob/master/src/platforms/vue-native/compiler/codegen/NativeRenderGenerator.js
MIT
genText(ast) { let code = super.genText(ast) code = code.replace(/^"\\n\s*/, '"').replace(/\\n\s*"$/, '"') return code }
override gen text @param {Object} ast
genText
javascript
GeekyAnts/vue-native-core
src/platforms/vue-native/compiler/codegen/NativeRenderGenerator.js
https://github.com/GeekyAnts/vue-native-core/blob/master/src/platforms/vue-native/compiler/codegen/NativeRenderGenerator.js
MIT
genStyleProps(ast) { const styleAttrsValue = ast.attrs .filter(v => v.name === 'style') .map(v => v.value) const show = ast.directives && ast.directives.filter(v => v.name === 'show')[0] const topParent = this.isAstTopParent(ast) if (styleAttrsValue.length === 0 && !show && !topParent) { return } let staticStyle, dynamicStyle, showStyle styleAttrsValue.forEach(v => { if (/^".*"$/.test(v)) { staticStyle = v.trim().replace(/;*"$/, ';"') } else { dynamicStyle = v } }) if (staticStyle) { try { staticStyle = JSON.stringify(parseStyleText(staticStyle)) } catch (e) {} } if (show) { showStyle = `{display: ${show.value} ? '' : 'none'}` } return `${NATIVE.bindStyle.name}(${dynamicStyle}, ${staticStyle}, ${showStyle})` }
gen style props @param {Object} ast
genStyleProps
javascript
GeekyAnts/vue-native-core
src/platforms/vue-native/compiler/codegen/NativeRenderGenerator.js
https://github.com/GeekyAnts/vue-native-core/blob/master/src/platforms/vue-native/compiler/codegen/NativeRenderGenerator.js
MIT
genClassProps(ast) { const topParent = this.isAstTopParent(ast) const classAttrsValue = ast.attrs .filter(v => v.name === 'class') .map(v => v.value) if (classAttrsValue.length === 0 && !topParent) { return } let staticClass, dynamicClass classAttrsValue.forEach(v => { if (/^".*"$/.test(v) || /^'.*'$/.test(v)) { staticClass = v.trim() // .replace(/^"(.*)"$/, '$1') } else { dynamicClass = v } }) let objCode = '{' if (staticClass) { objCode += `staticClass: ${staticClass},` } if (dynamicClass) { objCode += `dynamicClass: ${dynamicClass},` } if (topParent) { objCode += `parentClass: this.props.style,` } objCode = `${objCode.replace(/,$/, '')}}` return `${NATIVE.bindClass.name}.call(this, ${objCode})` }
gen class props @param {Object} ast
genClassProps
javascript
GeekyAnts/vue-native-core
src/platforms/vue-native/compiler/codegen/NativeRenderGenerator.js
https://github.com/GeekyAnts/vue-native-core/blob/master/src/platforms/vue-native/compiler/codegen/NativeRenderGenerator.js
MIT
isAstTopParent(ast) { if (ast.parent === undefined) { return true } if ( ast.parent.tag === 'template' || ast.parent.tag === 'transition' || ast.parent.originTag === 'transition' ) { if (ast.parent.parent === undefined) { return true } } return false }
gen class props @param {Object} ast
isAstTopParent
javascript
GeekyAnts/vue-native-core
src/platforms/vue-native/compiler/codegen/NativeRenderGenerator.js
https://github.com/GeekyAnts/vue-native-core/blob/master/src/platforms/vue-native/compiler/codegen/NativeRenderGenerator.js
MIT
genChildren(ast) { let children = [] if (ast.children && ast.children.length) { children = children.concat( ast.children.map(v => { return this.genElement(v) }), ) } if (ast.scopedSlots) { children = children.concat( Object.keys(ast.scopedSlots) .map(v => ast.scopedSlots[v]) .map(v => { const slotCode = this.genElement(v) || '' const slotScope = v.slotScope const render = `render: (${slotScope}) => ${slotCode.trim()}` const type = `type: '${COMMON.template.type}'` const slot = `'dataSlot': ${v.slotTarget}` const code = `{${type},${render},${slot}}` return code }), ) } return children }
gen children, include slot template generate @param {Object} ast
genChildren
javascript
GeekyAnts/vue-native-core
src/platforms/vue-native/compiler/codegen/RenderGenerator.js
https://github.com/GeekyAnts/vue-native-core/blob/master/src/platforms/vue-native/compiler/codegen/RenderGenerator.js
MIT
genTextExpression(ast) { return parseText(ast.text) }
gen text expression @param {Object} ast
genTextExpression
javascript
GeekyAnts/vue-native-core
src/platforms/vue-native/compiler/codegen/RenderGenerator.js
https://github.com/GeekyAnts/vue-native-core/blob/master/src/platforms/vue-native/compiler/codegen/RenderGenerator.js
MIT
genIf(ast) { ast.ifProcessed = true return this.genIfConditions(ast.ifConditions.slice()) }
gen if condition @param {Object} ast
genIf
javascript
GeekyAnts/vue-native-core
src/platforms/vue-native/compiler/codegen/RenderGenerator.js
https://github.com/GeekyAnts/vue-native-core/blob/master/src/platforms/vue-native/compiler/codegen/RenderGenerator.js
MIT
genIfConditions(conditions) { if (!conditions.length) { return 'null' } const condition = conditions.shift() let code if (condition.exp) { code = `(${condition.exp}) ?${this.genElement( condition.block, )} : ${this.genIfConditions(conditions)}` } else { code = `${this.genElement(condition.block)}` } return code }
gen if condition @param {Object} ast
genIfConditions
javascript
GeekyAnts/vue-native-core
src/platforms/vue-native/compiler/codegen/RenderGenerator.js
https://github.com/GeekyAnts/vue-native-core/blob/master/src/platforms/vue-native/compiler/codegen/RenderGenerator.js
MIT
genTemplate(ast) { return this.genElement(ast.children[0]) }
gen a empty component @param {Object} ast
genTemplate
javascript
GeekyAnts/vue-native-core
src/platforms/vue-native/compiler/codegen/RenderGenerator.js
https://github.com/GeekyAnts/vue-native-core/blob/master/src/platforms/vue-native/compiler/codegen/RenderGenerator.js
MIT
genChildrenKey(ast) { ast.children.forEach((v, i) => { v.attrs = v.attrs || [] v.attrs.push({ name: 'key', value: String(i), }) }) }
gen children key @param {Object} ast
genChildrenKey
javascript
GeekyAnts/vue-native-core
src/platforms/vue-native/compiler/codegen/RenderGenerator.js
https://github.com/GeekyAnts/vue-native-core/blob/master/src/platforms/vue-native/compiler/codegen/RenderGenerator.js
MIT
genTransition(ast) { return this.genChildren(ast) }
gen transition helper, this function would be override by sub class @param {Object} ast
genTransition
javascript
GeekyAnts/vue-native-core
src/platforms/vue-native/compiler/codegen/RenderGenerator.js
https://github.com/GeekyAnts/vue-native-core/blob/master/src/platforms/vue-native/compiler/codegen/RenderGenerator.js
MIT
genTransitionGroup(ast) { return this.genChildren(ast) }
gen transition group helper, this function would be override by sub class @param {Object} ast
genTransitionGroup
javascript
GeekyAnts/vue-native-core
src/platforms/vue-native/compiler/codegen/RenderGenerator.js
https://github.com/GeekyAnts/vue-native-core/blob/master/src/platforms/vue-native/compiler/codegen/RenderGenerator.js
MIT
genProps(ast) { let code = [] if (filterDirective(ast).length) { const directives = this.genDirectives(ast) if (directives) { code.push(directives) } const directiveTag = this.genDirectiveTag(ast) if (directiveTag) { code.push(directiveTag) } const directiveContext = this.genDirectiveContext(ast) if (directiveContext) { code.push(directiveContext) } } if (ast.slotTarget !== undefined) { this.genSlotTarget(ast) } if (ast.ref || ast.parent === undefined) { const ref = this.genRef(ast) if (ref) { code.push(ref) } } if (ast.key !== undefined) { const key = this.genKey(ast) if (key) { code.push(key) } } if (Array.isArray(ast.attrsList)) { ast.attrsList.forEach(v => { if (v.name === 'v-bind' && /^\{.*\}$/.test(v.value)) { try { const matchVArr = v.value.match(/^\{(.*)\}$/) if (matchVArr && matchVArr[1]) { matchVArr[1].split(',').forEach(_v => { const _vArr = _v.split(':') if (_vArr.length === 2) { ast.attrs.push({ name: _vArr[0].trim().replace(/'|"/g, ''), value: _vArr[1].trim(), }) } }) } } catch (e) { console.log('parse error for v-bind obj') } } }) } if (Array.isArray(ast.attrs)) { const props = ast.attrs .filter(v => { return v.name !== 'class' && v.name !== 'style' && v.name !== 'v-pre' }) .map(v => { let value = v.value let name = v.name if ( name.indexOf('data-') === 0 || name.indexOf(HELPER_HEADER) === 0 ) { return `'${name}': ${value}` } if (name === 'for') { name = 'htmlFor' } if (isBooleanAttr(name)) { if (value === '""') { value = 'true' } } if (!isReservedTag(ast.tag)) { name = camelize(name) } else if (propertyMap[name]) { name = propertyMap[name] } return `'${name}': ${value}` }) code = code.concat(props) } return code }
gen props, this funciton would be override by sub class @param {Object} ast
genProps
javascript
GeekyAnts/vue-native-core
src/platforms/vue-native/compiler/codegen/RenderGenerator.js
https://github.com/GeekyAnts/vue-native-core/blob/master/src/platforms/vue-native/compiler/codegen/RenderGenerator.js
MIT
genDirectives(ast) { let code = [] ast.directives.forEach(v => { code.push( `{name:"${v.name}",directiveName:"${changeCase.lowerCase( changeCase.camelCase(v.name), )}",rawName:"${v.rawName}"${ v.value ? `,value:(${v.value}),expression:${JSON.stringify(v.value)}` : '' }${v.arg ? `,arg:"${v.arg}"` : ''}${ v.modifiers ? `,modifiers:${JSON.stringify(v.modifiers)}` : '' }}`, ) }) code = `${COMMON.directive.name}: [${code.join(',')}]` return code }
gen common directive, this function would be override by SubClass
genDirectives
javascript
GeekyAnts/vue-native-core
src/platforms/vue-native/compiler/codegen/RenderGenerator.js
https://github.com/GeekyAnts/vue-native-core/blob/master/src/platforms/vue-native/compiler/codegen/RenderGenerator.js
MIT
genDirectiveTag(ast) { let code = '' code += `${COMMON.directive.tag}: ${this.genTag(ast)}` return code }
gen common directive, this function would be override by SubClass
genDirectiveTag
javascript
GeekyAnts/vue-native-core
src/platforms/vue-native/compiler/codegen/RenderGenerator.js
https://github.com/GeekyAnts/vue-native-core/blob/master/src/platforms/vue-native/compiler/codegen/RenderGenerator.js
MIT
genDirectiveContext(ast) { let code = '' code += `${COMMON.directive.context}: this` return code }
gen common directive, this function would be override by SubClass
genDirectiveContext
javascript
GeekyAnts/vue-native-core
src/platforms/vue-native/compiler/codegen/RenderGenerator.js
https://github.com/GeekyAnts/vue-native-core/blob/master/src/platforms/vue-native/compiler/codegen/RenderGenerator.js
MIT
genSlotTarget(ast) { ast.attrs = ast.attrs || [] ast.attrs.push({ name: 'dataSlot', value: ast.slotTarget, }) }
gen slot props @param {Object} ast
genSlotTarget
javascript
GeekyAnts/vue-native-core
src/platforms/vue-native/compiler/codegen/RenderGenerator.js
https://github.com/GeekyAnts/vue-native-core/blob/master/src/platforms/vue-native/compiler/codegen/RenderGenerator.js
MIT
genKey(ast) { return `key: ${ast.key}` }
gen slot props @param {Object} ast
genKey
javascript
GeekyAnts/vue-native-core
src/platforms/vue-native/compiler/codegen/RenderGenerator.js
https://github.com/GeekyAnts/vue-native-core/blob/master/src/platforms/vue-native/compiler/codegen/RenderGenerator.js
MIT
genKeyFor(ast) { if (!ast.key) { const obj = {} obj.name = 'key' obj.value = 'arguments[1]' ast.attrs = ast.attrs || [] ast.attrs.push(obj) } return ast }
gen key in for iterator @param {Object} ast
genKeyFor
javascript
GeekyAnts/vue-native-core
src/platforms/vue-native/compiler/codegen/RenderGenerator.js
https://github.com/GeekyAnts/vue-native-core/blob/master/src/platforms/vue-native/compiler/codegen/RenderGenerator.js
MIT
genIMEResolve(ast) { ast.inputProcessed = true return this.genElement(ast) }
wrapped node in a buildin component to prevent IME problem @param {Object} ast
genIMEResolve
javascript
GeekyAnts/vue-native-core
src/platforms/vue-native/compiler/codegen/RenderGenerator.js
https://github.com/GeekyAnts/vue-native-core/blob/master/src/platforms/vue-native/compiler/codegen/RenderGenerator.js
MIT
genTag(ast) { return ast.tag }
generate react tag, this funciton would be override by sub class @param {String} tag
genTag
javascript
GeekyAnts/vue-native-core
src/platforms/vue-native/compiler/codegen/RenderGenerator.js
https://github.com/GeekyAnts/vue-native-core/blob/master/src/platforms/vue-native/compiler/codegen/RenderGenerator.js
MIT
isWebInput(ast) { if (!ast.inputProcessed) { if (ast.tag === 'textarea') { return true } else if (ast.tag === 'input') { const type = ast.attrs.filter(v => v.name === 'type')[0] if (type === undefined) { return true } else if (type.value === 'text' || type.value === 'password') { return true } } } return false }
for web platform, we wrapped node in a buildin component to prevent IME problem @param {Object} ast
isWebInput
javascript
GeekyAnts/vue-native-core
src/platforms/vue-native/compiler/codegen/RenderGenerator.js
https://github.com/GeekyAnts/vue-native-core/blob/master/src/platforms/vue-native/compiler/codegen/RenderGenerator.js
MIT
genClassProps(ast) { let code = '' const topParent = this.isAstTopParent(ast) const classAttrsValue = ast.attrs .filter(v => v.name === 'class') .map(v => v.value) if (classAttrsValue.length === 0 && !topParent) { return code } let staticClass, dynamicClass classAttrsValue.forEach(v => { if (/^".*"$/.test(v) || /^'.*'$/.test(v)) { staticClass = v.trim() // .replace(/^"(.*)"$/, '$1') } else { dynamicClass = v } }) if (staticClass) { code += ` ${staticClass}` } if (dynamicClass) { code = code.replace(/"$/, ' "') code += ` + ${WEB.bindClass.name}(${dynamicClass})` } if (topParent) { code += `+ ' ' + (this.props.className || '')` } code = `className: (${code.trim().replace(/^[\s]*\+[\s]*/, '')}).trim()` return code }
gen class props @param {Object} ast
genClassProps
javascript
GeekyAnts/vue-native-core
src/platforms/vue-native/compiler/codegen/WebRenderGenerator.js
https://github.com/GeekyAnts/vue-native-core/blob/master/src/platforms/vue-native/compiler/codegen/WebRenderGenerator.js
MIT
genStyleProps(ast) { const styleAttrsValue = ast.attrs .filter(v => v.name === 'style') .map(v => v.value) const show = ast.directives && ast.directives.filter(v => v.name === 'show')[0] const topParent = this.isAstTopParent(ast) if (styleAttrsValue.length === 0 && !show && !topParent) { return } let staticStyle, dynamicStyle, showStyle styleAttrsValue.forEach(v => { if (/^".*"$/.test(v)) { staticStyle = v.trim().replace(/;*"$/, ';"') } else { dynamicStyle = v } }) let code = '' if (staticStyle) { try { staticStyle = JSON.stringify(parseStyleText(staticStyle)) } catch (e) {} } if (show) { showStyle = `{display: ${show.value} ? '' : 'none'}` } if (topParent) { showStyle = `Object.assign({}, ${showStyle}, this.props.style)` } code = `${WEB.bindStyle.name}(${dynamicStyle}, ${staticStyle}, ${showStyle})` code = `style: ${code.trim().replace(/^[\s]*\+[\s]*/, '')}` return code }
gen style props @param {Object} ast
genStyleProps
javascript
GeekyAnts/vue-native-core
src/platforms/vue-native/compiler/codegen/WebRenderGenerator.js
https://github.com/GeekyAnts/vue-native-core/blob/master/src/platforms/vue-native/compiler/codegen/WebRenderGenerator.js
MIT
getChildContext() { return { owner: this, } }
children can access parent instance by 'this.context.owner'
getChildContext
javascript
GeekyAnts/vue-native-core
src/platforms/vue-native/runtime/components/buildComponent.js
https://github.com/GeekyAnts/vue-native-core/blob/master/src/platforms/vue-native/runtime/components/buildComponent.js
MIT
setEventOnce(fn) { const name = fn.name return event => { if (this.eventOnceUid.indexOf(name) === -1) { this.eventOnceUid.push(name) fn(event) } } }
for event modifiers v-on:xxx.once
setEventOnce
javascript
GeekyAnts/vue-native-core
src/platforms/vue-native/runtime/components/buildComponent.js
https://github.com/GeekyAnts/vue-native-core/blob/master/src/platforms/vue-native/runtime/components/buildComponent.js
MIT
setRootRef(ref) { if (ref) { ref = ref._ref || ref this._ref = ref this.vm.$el = this._ref } }
for event modifiers v-on:xxx.once
setRootRef
javascript
GeekyAnts/vue-native-core
src/platforms/vue-native/runtime/components/buildComponent.js
https://github.com/GeekyAnts/vue-native-core/blob/master/src/platforms/vue-native/runtime/components/buildComponent.js
MIT
setRef(ref, text, inFor) { if (ref) { // for buildin component, we set ref to his hold node directly // it means the buildin componet would be the end of $refs chain ref = ref.vm || ref._ref || ref if (inFor === true) { if (!this.vm.$refs[text]) { this.vm.$refs[text] = [] } this.vm.$refs[text].push(ref) } else { this.vm.$refs[text] = ref } this.$refs = this.vm.$refs } }
for event modifiers v-on:xxx.once
setRef
javascript
GeekyAnts/vue-native-core
src/platforms/vue-native/runtime/components/buildComponent.js
https://github.com/GeekyAnts/vue-native-core/blob/master/src/platforms/vue-native/runtime/components/buildComponent.js
MIT
buildVM(options) { // set this property to prevent runtime error in vue render._withStripped = true const vueOptions = { render: render, propsData: this.props, parent: this.context.owner ? this.context.owner.vm : undefined, } const reactVueOptions = { reactVueSlots: getSlots(this.props.children), reactVueForceUpdate: this.forceUpdate.bind(this), reactVueCustomEvent: filterCustomEvent(this.props), } Object.assign(options, vueOptions, reactVueOptions) const vm = new Vue(options) vm.$options.directives = handleDirectives(vm.$options.directives) vm.$options.components = handleComponents(vm.$options.components) /** * for ignoredElements */ Vue.config.ignoredElements.forEach(name => { const _name = pascalCaseTag(name) if (vm.$options.components[_name] === undefined) { vm.$options.components[_name] = name } }) return vm }
for event modifiers v-on:xxx.once
buildVM
javascript
GeekyAnts/vue-native-core
src/platforms/vue-native/runtime/components/buildComponent.js
https://github.com/GeekyAnts/vue-native-core/blob/master/src/platforms/vue-native/runtime/components/buildComponent.js
MIT
setRef(ref) { if (ref) { if (ref._reactInternalInstance && ref.vm === undefined) { this._ref = ref._ref || ref } else { this._ref = ref.vm || ref } } }
for vue, every component should have a ref to represent node element
setRef
javascript
GeekyAnts/vue-native-core
src/platforms/vue-native/runtime/components/buildMixin.js
https://github.com/GeekyAnts/vue-native-core/blob/master/src/platforms/vue-native/runtime/components/buildMixin.js
MIT
buildStateProps(props) { const stateProps = Object.assign({}, props) const originRef = stateProps.ref stateProps.ref = ref => { this.setRef(ref) if (typeof originRef === 'function') { return originRef(ref) } else { return ref } } return stateProps }
for vue, every component should have a ref to represent node element
buildStateProps
javascript
GeekyAnts/vue-native-core
src/platforms/vue-native/runtime/components/buildMixin.js
https://github.com/GeekyAnts/vue-native-core/blob/master/src/platforms/vue-native/runtime/components/buildMixin.js
MIT
getChildContext() { return { owner: this, } }
children can access parent instance by 'this.context.owner'
getChildContext
javascript
GeekyAnts/vue-native-core
src/platforms/vue-native/runtime/components/buildNativeComponent.js
https://github.com/GeekyAnts/vue-native-core/blob/master/src/platforms/vue-native/runtime/components/buildNativeComponent.js
MIT
setEventOnce(fn) { const name = fn.name return event => { if (this.eventOnceUid.indexOf(name) === -1) { this.eventOnceUid.push(name) fn(event) } } }
for event modifiers v-on:xxx.once
setEventOnce
javascript
GeekyAnts/vue-native-core
src/platforms/vue-native/runtime/components/buildNativeComponent.js
https://github.com/GeekyAnts/vue-native-core/blob/master/src/platforms/vue-native/runtime/components/buildNativeComponent.js
MIT
setRootRef(ref) { if (ref) { ref = ref._ref || ref this._ref = ref this.vm.$el = this._ref } }
for event modifiers v-on:xxx.once
setRootRef
javascript
GeekyAnts/vue-native-core
src/platforms/vue-native/runtime/components/buildNativeComponent.js
https://github.com/GeekyAnts/vue-native-core/blob/master/src/platforms/vue-native/runtime/components/buildNativeComponent.js
MIT
setRef(ref, text, inFor) { if (ref) { // for buildin component, we set ref to his hold node directly // it means the buildin componet would be the end of $refs chain ref = ref.vm || ref._ref || ref if (inFor === true) { if (!this.vm.$refs[text]) { this.vm.$refs[text] = [] } this.vm.$refs[text].push(ref) } else { this.vm.$refs[text] = ref } this.$refs = this.vm.$refs } }
for event modifiers v-on:xxx.once
setRef
javascript
GeekyAnts/vue-native-core
src/platforms/vue-native/runtime/components/buildNativeComponent.js
https://github.com/GeekyAnts/vue-native-core/blob/master/src/platforms/vue-native/runtime/components/buildNativeComponent.js
MIT
buildVM(options) { // set this property to prevent runtime error in vue render._withStripped = true const vueOptions = { render: render, propsData: this.props, parent: this.context.owner ? this.context.owner.vm : undefined, } const reactVueOptions = { reactVueSlots: getSlots(this.props.children), reactVueForceUpdate: this.forceUpdate.bind(this), reactVueCustomEvent: filterCustomEvent(this.props), } Object.assign(options, vueOptions, reactVueOptions) const vm = new Vue(options) vm.$options.directives = handleDirectives(vm.$options.directives) vm.$options.components = handleComponents(vm.$options.components) /** * for ignoredElements */ Vue.config.ignoredElements.forEach(name => { const _name = pascalCaseTag(name) if (vm.$options.components[_name] === undefined) { vm.$options.components[_name] = name } }) return vm }
for event modifiers v-on:xxx.once
buildVM
javascript
GeekyAnts/vue-native-core
src/platforms/vue-native/runtime/components/buildNativeComponent.js
https://github.com/GeekyAnts/vue-native-core/blob/master/src/platforms/vue-native/runtime/components/buildNativeComponent.js
MIT
function getHookArgumentsLength(fn) { if (isUndef(fn)) { return false } const invokerFns = fn.fns if (isDef(invokerFns)) { // invoker return getHookArgumentsLength( Array.isArray(invokerFns) ? invokerFns[0] : invokerFns, ) } else { return (fn._length || fn.length) > 1 } }
Normalize a transition hook's argument length. The hook may be: - a merged hook (invoker) with the original in .fns - a wrapped component method (check ._length) - a plain function (.length)
getHookArgumentsLength
javascript
GeekyAnts/vue-native-core
src/platforms/vue-native/runtime/components/buildWebTransition.js
https://github.com/GeekyAnts/vue-native-core/blob/master/src/platforms/vue-native/runtime/components/buildWebTransition.js
MIT
function checkDuration(val, name) { if (typeof val !== 'number') { warn( `<transition> explicit ${name} duration is not a valid number - ` + `got ${JSON.stringify(val)}.`, ) } else if (isNaN(val)) { warn( `<transition> explicit ${name} duration is NaN - ` + 'the duration expression might be incorrect.', ) } }
Normalize a transition hook's argument length. The hook may be: - a merged hook (invoker) with the original in .fns - a wrapped component method (check ._length) - a plain function (.length)
checkDuration
javascript
GeekyAnts/vue-native-core
src/platforms/vue-native/runtime/components/buildWebTransition.js
https://github.com/GeekyAnts/vue-native-core/blob/master/src/platforms/vue-native/runtime/components/buildWebTransition.js
MIT
function isValidDuration(val) { return typeof val === 'number' && !isNaN(val) }
Normalize a transition hook's argument length. The hook may be: - a merged hook (invoker) with the original in .fns - a wrapped component method (check ._length) - a plain function (.length)
isValidDuration
javascript
GeekyAnts/vue-native-core
src/platforms/vue-native/runtime/components/buildWebTransition.js
https://github.com/GeekyAnts/vue-native-core/blob/master/src/platforms/vue-native/runtime/components/buildWebTransition.js
MIT
function addTransitionClass(ref, className) { addClass(ref, className) }
Normalize a transition hook's argument length. The hook may be: - a merged hook (invoker) with the original in .fns - a wrapped component method (check ._length) - a plain function (.length)
addTransitionClass
javascript
GeekyAnts/vue-native-core
src/platforms/vue-native/runtime/components/buildWebTransition.js
https://github.com/GeekyAnts/vue-native-core/blob/master/src/platforms/vue-native/runtime/components/buildWebTransition.js
MIT
function removeTransitionClass(ref, className) { removeClass(ref, className) }
Normalize a transition hook's argument length. The hook may be: - a merged hook (invoker) with the original in .fns - a wrapped component method (check ._length) - a plain function (.length)
removeTransitionClass
javascript
GeekyAnts/vue-native-core
src/platforms/vue-native/runtime/components/buildWebTransition.js
https://github.com/GeekyAnts/vue-native-core/blob/master/src/platforms/vue-native/runtime/components/buildWebTransition.js
MIT
function enter({ el, cb }) { const { css, type, enterClass, enterToClass, enterActiveClass, appearClass, appearToClass, appearActiveClass, onBeforeEnter, onEnter, onAfterEnter, onEnterCancelled, onBeforeAppear, appear, onAppear, onAfterAppear, onAppearCancelled, duration, } = this.transitionResolved const isAppear = this.isAppear if (isUndef(el)) { return } if (isAppear && !appear && appear !== '') { return } if (isDef(el._enterCb) || el.nodeType !== 1) { return } const startClass = isAppear && appearClass ? appearClass : enterClass const activeClass = isAppear && appearActiveClass ? appearActiveClass : enterActiveClass const toClass = isAppear && appearToClass ? appearToClass : enterToClass const beforeEnterHook = isAppear ? onBeforeAppear || onBeforeEnter : onBeforeEnter const enterHook = isAppear ? onAppear || onEnter : onEnter const afterEnterHook = isAppear ? onAfterAppear || onAfterEnter : onAfterEnter const enterCancelledHook = isAppear ? onAppearCancelled || onEnterCancelled : onEnterCancelled const explicitEnterDuration = toNumber( isObject(duration) ? duration.enter : duration, ) if (process.env.NODE_ENV !== 'production' && explicitEnterDuration != null) { checkDuration(explicitEnterDuration, 'enter') } const expectsCSS = css !== false && !isIE9 const userWantsControl = getHookArgumentsLength(enterHook) const _cb = (el._enterCb = once(() => { if (expectsCSS) { removeTransitionClass(el, activeClass) removeTransitionClass(el, toClass) } cb && cb() if (_cb.cancelled) { if (expectsCSS) { removeTransitionClass(el, startClass) } enterCancelledHook && enterCancelledHook(el) } else { afterEnterHook && afterEnterHook(el) } el._enterCb = null })) beforeEnterHook && beforeEnterHook(el) if (expectsCSS) { addTransitionClass(el, startClass) addTransitionClass(el, activeClass) nextFrame(() => { removeTransitionClass(el, startClass) addTransitionClass(el, toClass) if (!_cb.cancelled && !userWantsControl) { if (isValidDuration(explicitEnterDuration)) { setTimeout(_cb, explicitEnterDuration) } else { whenTransitionEnds(el, type || getTransitionInfo(el).type, _cb) } } }) } nextFrame(() => enterHook && enterHook(el, _cb)) if (!expectsCSS && !userWantsControl) { _cb() } }
check whether animation should be updated for performance it does not used for under component but in the future we would be used @param {Object} prev props @param {Object} next props
enter
javascript
GeekyAnts/vue-native-core
src/platforms/vue-native/runtime/components/buildWebTransition.js
https://github.com/GeekyAnts/vue-native-core/blob/master/src/platforms/vue-native/runtime/components/buildWebTransition.js
MIT
function leave({ el, cb }) { const { css, type, leaveClass, leaveToClass, leaveActiveClass, onBeforeLeave, onLeave, onAfterLeave, onLeaveCancelled, duration, } = this.transitionResolved if (isUndef(el)) { return } if (isDef(el._leaveCb) || el.nodeType !== 1) { return } const expectsCSS = css !== false && !isIE9 const userWantsControl = getHookArgumentsLength(onLeave) const explicitLeaveDuration = toNumber( isObject(duration) ? duration.leave : duration, ) if (process.env.NODE_ENV !== 'production' && explicitLeaveDuration != null) { checkDuration(explicitLeaveDuration, 'leave') } const _cb = (el._leaveCb = once(() => { if (expectsCSS) { removeTransitionClass(el, leaveActiveClass) removeTransitionClass(el, leaveToClass) } cb && cb() if (_cb.cancelled) { if (expectsCSS) { removeTransitionClass(el, leaveClass) } onLeaveCancelled && onLeaveCancelled(el) } else { onAfterLeave && onAfterLeave(el) } el._leaveCb = null })) onBeforeLeave && onBeforeLeave(el) if (expectsCSS) { addTransitionClass(el, leaveClass) addTransitionClass(el, leaveActiveClass) nextFrame(() => { removeTransitionClass(el, leaveClass) addTransitionClass(el, leaveToClass) if (!_cb.cancelled && !userWantsControl) { if (isValidDuration(explicitLeaveDuration)) { setTimeout(_cb, explicitLeaveDuration) } else { whenTransitionEnds(el, type || getTransitionInfo(el).type, _cb) } } }) } onLeave && onLeave(el, _cb) if (!expectsCSS && !userWantsControl && !onLeave) { _cb() } }
check whether animation should be updated for performance it does not used for under component but in the future we would be used @param {Object} prev props @param {Object} next props
leave
javascript
GeekyAnts/vue-native-core
src/platforms/vue-native/runtime/components/buildWebTransition.js
https://github.com/GeekyAnts/vue-native-core/blob/master/src/platforms/vue-native/runtime/components/buildWebTransition.js
MIT
function buildWebTransition(Component, createElement) { const EmptyComponent = buildWebEmptyComponent(Component, createElement) class Transition extends Component { constructor(props) { super(props) this._ref = null this._refs = {} this.transitionResolved = {} this._shouldComponentUpdateTransitionResult = false this.isAppear = false this.state = { transObj: {}, animated: true, tagKey: null, } } setRef(ref, key) { if (!ref) { return } this._ref = ref._ref || ref this._refs[key] = this._ref } resolveData(props, type) { const target = filterCollection(props[WEB.transition.collection])[0] if (target) { const element = target.element const _props = {} for (const key in element.props) { _props[key] = element.props[key] } let key = target.index if (element.key != null) { key = element.key + key } if (target.type === 'component') { const targetExp = target.exp const thisTarget = this.state.transObj[this.state.tagKey] const thisExp = thisTarget && thisTarget.exp if (targetExp !== thisExp) { key = this.state.tagKey === 0 ? 1 : 0 } } _props.key = _props.key || key const setRef = ref => { this.setRef(ref, _props.key) element.ref && element.ref(ref) } if (target.type === 'component') { _props[COMMON.setRef.name] = setRef } else { _props.ref = setRef } const transObj = Object.assign({}, this.state.transObj) transObj[_props.key] = Object.assign({}, target, { props: _props, }) return { transObj: transObj, animated: true, tagKey: _props.key, } } else if (type === 'update') { const tagKey = this.state.tagKey const transition = this.state.transObj[tagKey] // someone want to hide and his prev state is show if (transition) { const transObj = {} transObj[tagKey] = Object.assign({}, transition, { exp: transition.exp ? !transition.exp : transition.exp, }) return { animated: true, transObj: transObj, tagKey: tagKey, } } } } UNSAFE_componentWillMount() { this.transitionResolved = resolveTransition(this.props) this.isAppear = true const state = this.resolveData(this.props) state && this.setState(state) } componentDidMount() { this.resolveEnterTransition({ el: this._refs[this.state.tagKey], }) } UNSAFE_componentWillReceiveProps(nextProps) { this.transitionResolved = resolveTransition(nextProps) this.isAppear = false const nextState = this.resolveData(nextProps, 'update') if (nextState) { this._shouldComponentUpdateTransitionResult = this._shouldComponentUpdateTransition( nextProps, nextState, ) this.setState(nextState) } if (this._shouldComponentUpdateTransitionResult) { Object.keys(this._refs).forEach(k => { const el = this._refs[k] if (isDef(el._leaveCb)) { el._leaveCb.cancelled = true el._leaveCb() } if (isDef(el._enterCb)) { el._enterCb.cancelled = true el._enterCb() } }) } } _shouldComponentUpdateTransition(nextProps, nextState) { if ( Object.keys(nextState.transObj).length !== Object.keys(this.state.transObj).length ) { return true } if (nextState.tagKey === this.state.tagKey) { const nextTransition = nextState.transObj[nextState.tagKey] const transition = this.state.transObj[this.state.tagKey] if (nextTransition && transition) { return transition.exp !== nextTransition.exp } } return true } resolveEnterTransition(option) { enter.call(this, option) } resolveLeaveTransition(option) { leave.call(this, option) } componentDidUpdate(prevProps, prevState) { if ( this.state.animated === false || this._shouldComponentUpdateTransitionResult === false ) { return } if (this.state.tagKey === prevState.tagKey) { // same element const ref = this._refs[this.state.tagKey] const transition = this.state.transObj[this.state.tagKey] if (ref && transition) { if (transition.type === 'show') { ref.style.display = '' if (transition.exp === false) { this.resolveLeaveTransition({ el: ref, cb: () => { ref.style.display = 'none' }, }) } else if (transition.exp === true) { this.resolveEnterTransition({ el: ref, }) } } else if (transition.type === 'if') { if (transition.exp === false) { const transObj = Object.assign({}, this.state.transObj) delete transObj[prevState.tagKey] this.resolveLeaveTransition({ el: ref, cb: () => { this.setState({ transObj: transObj, animated: false, }) }, }) } else if (transition.exp === true) { this.resolveEnterTransition({ el: ref, }) } } } } else { const enterRef = this._refs[this.state.tagKey] const leaveRef = this._refs[prevState.tagKey] const transObj = Object.assign({}, this.state.transObj) delete transObj[prevState.tagKey] this.resolveEnterTransition({ el: enterRef, }) this.resolveLeaveTransition({ el: leaveRef, cb: () => { this.setState({ transObj: transObj, animated: false, }) }, }) } } render() { const transObj = this.state.transObj const tag = this.props.tag || EmptyComponent return createElement( tag, null, Object.keys(transObj).map(k => { const type = transObj[k].element.type const props = transObj[k].props const children = props.children return createElement(type, props, children) }), ) } } return Transition }
check whether animation should be updated for performance it does not used for under component but in the future we would be used @param {Object} prev props @param {Object} next props
buildWebTransition
javascript
GeekyAnts/vue-native-core
src/platforms/vue-native/runtime/components/buildWebTransition.js
https://github.com/GeekyAnts/vue-native-core/blob/master/src/platforms/vue-native/runtime/components/buildWebTransition.js
MIT
constructor(props) { super(props) this._ref = null this._refs = {} this.transitionResolved = {} this._shouldComponentUpdateTransitionResult = false this.isAppear = false this.state = { transObj: {}, animated: true, tagKey: null, } }
check whether animation should be updated for performance it does not used for under component but in the future we would be used @param {Object} prev props @param {Object} next props
constructor
javascript
GeekyAnts/vue-native-core
src/platforms/vue-native/runtime/components/buildWebTransition.js
https://github.com/GeekyAnts/vue-native-core/blob/master/src/platforms/vue-native/runtime/components/buildWebTransition.js
MIT
setRef(ref, key) { if (!ref) { return } this._ref = ref._ref || ref this._refs[key] = this._ref }
check whether animation should be updated for performance it does not used for under component but in the future we would be used @param {Object} prev props @param {Object} next props
setRef
javascript
GeekyAnts/vue-native-core
src/platforms/vue-native/runtime/components/buildWebTransition.js
https://github.com/GeekyAnts/vue-native-core/blob/master/src/platforms/vue-native/runtime/components/buildWebTransition.js
MIT
resolveData(props, type) { const target = filterCollection(props[WEB.transition.collection])[0] if (target) { const element = target.element const _props = {} for (const key in element.props) { _props[key] = element.props[key] } let key = target.index if (element.key != null) { key = element.key + key } if (target.type === 'component') { const targetExp = target.exp const thisTarget = this.state.transObj[this.state.tagKey] const thisExp = thisTarget && thisTarget.exp if (targetExp !== thisExp) { key = this.state.tagKey === 0 ? 1 : 0 } } _props.key = _props.key || key const setRef = ref => { this.setRef(ref, _props.key) element.ref && element.ref(ref) } if (target.type === 'component') { _props[COMMON.setRef.name] = setRef } else { _props.ref = setRef } const transObj = Object.assign({}, this.state.transObj) transObj[_props.key] = Object.assign({}, target, { props: _props, }) return { transObj: transObj, animated: true, tagKey: _props.key, } } else if (type === 'update') { const tagKey = this.state.tagKey const transition = this.state.transObj[tagKey] // someone want to hide and his prev state is show if (transition) { const transObj = {} transObj[tagKey] = Object.assign({}, transition, { exp: transition.exp ? !transition.exp : transition.exp, }) return { animated: true, transObj: transObj, tagKey: tagKey, } } } }
check whether animation should be updated for performance it does not used for under component but in the future we would be used @param {Object} prev props @param {Object} next props
resolveData
javascript
GeekyAnts/vue-native-core
src/platforms/vue-native/runtime/components/buildWebTransition.js
https://github.com/GeekyAnts/vue-native-core/blob/master/src/platforms/vue-native/runtime/components/buildWebTransition.js
MIT
setRef = ref => { this.setRef(ref, _props.key) element.ref && element.ref(ref) }
check whether animation should be updated for performance it does not used for under component but in the future we would be used @param {Object} prev props @param {Object} next props
setRef
javascript
GeekyAnts/vue-native-core
src/platforms/vue-native/runtime/components/buildWebTransition.js
https://github.com/GeekyAnts/vue-native-core/blob/master/src/platforms/vue-native/runtime/components/buildWebTransition.js
MIT
setRef = ref => { this.setRef(ref, _props.key) element.ref && element.ref(ref) }
check whether animation should be updated for performance it does not used for under component but in the future we would be used @param {Object} prev props @param {Object} next props
setRef
javascript
GeekyAnts/vue-native-core
src/platforms/vue-native/runtime/components/buildWebTransition.js
https://github.com/GeekyAnts/vue-native-core/blob/master/src/platforms/vue-native/runtime/components/buildWebTransition.js
MIT
UNSAFE_componentWillMount() { this.transitionResolved = resolveTransition(this.props) this.isAppear = true const state = this.resolveData(this.props) state && this.setState(state) }
check whether animation should be updated for performance it does not used for under component but in the future we would be used @param {Object} prev props @param {Object} next props
UNSAFE_componentWillMount
javascript
GeekyAnts/vue-native-core
src/platforms/vue-native/runtime/components/buildWebTransition.js
https://github.com/GeekyAnts/vue-native-core/blob/master/src/platforms/vue-native/runtime/components/buildWebTransition.js
MIT
componentDidMount() { this.resolveEnterTransition({ el: this._refs[this.state.tagKey], }) }
check whether animation should be updated for performance it does not used for under component but in the future we would be used @param {Object} prev props @param {Object} next props
componentDidMount
javascript
GeekyAnts/vue-native-core
src/platforms/vue-native/runtime/components/buildWebTransition.js
https://github.com/GeekyAnts/vue-native-core/blob/master/src/platforms/vue-native/runtime/components/buildWebTransition.js
MIT
UNSAFE_componentWillReceiveProps(nextProps) { this.transitionResolved = resolveTransition(nextProps) this.isAppear = false const nextState = this.resolveData(nextProps, 'update') if (nextState) { this._shouldComponentUpdateTransitionResult = this._shouldComponentUpdateTransition( nextProps, nextState, ) this.setState(nextState) } if (this._shouldComponentUpdateTransitionResult) { Object.keys(this._refs).forEach(k => { const el = this._refs[k] if (isDef(el._leaveCb)) { el._leaveCb.cancelled = true el._leaveCb() } if (isDef(el._enterCb)) { el._enterCb.cancelled = true el._enterCb() } }) } }
check whether animation should be updated for performance it does not used for under component but in the future we would be used @param {Object} prev props @param {Object} next props
UNSAFE_componentWillReceiveProps
javascript
GeekyAnts/vue-native-core
src/platforms/vue-native/runtime/components/buildWebTransition.js
https://github.com/GeekyAnts/vue-native-core/blob/master/src/platforms/vue-native/runtime/components/buildWebTransition.js
MIT
_shouldComponentUpdateTransition(nextProps, nextState) { if ( Object.keys(nextState.transObj).length !== Object.keys(this.state.transObj).length ) { return true } if (nextState.tagKey === this.state.tagKey) { const nextTransition = nextState.transObj[nextState.tagKey] const transition = this.state.transObj[this.state.tagKey] if (nextTransition && transition) { return transition.exp !== nextTransition.exp } } return true }
check whether animation should be updated for performance it does not used for under component but in the future we would be used @param {Object} prev props @param {Object} next props
_shouldComponentUpdateTransition
javascript
GeekyAnts/vue-native-core
src/platforms/vue-native/runtime/components/buildWebTransition.js
https://github.com/GeekyAnts/vue-native-core/blob/master/src/platforms/vue-native/runtime/components/buildWebTransition.js
MIT
resolveEnterTransition(option) { enter.call(this, option) }
check whether animation should be updated for performance it does not used for under component but in the future we would be used @param {Object} prev props @param {Object} next props
resolveEnterTransition
javascript
GeekyAnts/vue-native-core
src/platforms/vue-native/runtime/components/buildWebTransition.js
https://github.com/GeekyAnts/vue-native-core/blob/master/src/platforms/vue-native/runtime/components/buildWebTransition.js
MIT
resolveLeaveTransition(option) { leave.call(this, option) }
check whether animation should be updated for performance it does not used for under component but in the future we would be used @param {Object} prev props @param {Object} next props
resolveLeaveTransition
javascript
GeekyAnts/vue-native-core
src/platforms/vue-native/runtime/components/buildWebTransition.js
https://github.com/GeekyAnts/vue-native-core/blob/master/src/platforms/vue-native/runtime/components/buildWebTransition.js
MIT
componentDidUpdate(prevProps, prevState) { if ( this.state.animated === false || this._shouldComponentUpdateTransitionResult === false ) { return } if (this.state.tagKey === prevState.tagKey) { // same element const ref = this._refs[this.state.tagKey] const transition = this.state.transObj[this.state.tagKey] if (ref && transition) { if (transition.type === 'show') { ref.style.display = '' if (transition.exp === false) { this.resolveLeaveTransition({ el: ref, cb: () => { ref.style.display = 'none' }, }) } else if (transition.exp === true) { this.resolveEnterTransition({ el: ref, }) } } else if (transition.type === 'if') { if (transition.exp === false) { const transObj = Object.assign({}, this.state.transObj) delete transObj[prevState.tagKey] this.resolveLeaveTransition({ el: ref, cb: () => { this.setState({ transObj: transObj, animated: false, }) }, }) } else if (transition.exp === true) { this.resolveEnterTransition({ el: ref, }) } } } } else { const enterRef = this._refs[this.state.tagKey] const leaveRef = this._refs[prevState.tagKey] const transObj = Object.assign({}, this.state.transObj) delete transObj[prevState.tagKey] this.resolveEnterTransition({ el: enterRef, }) this.resolveLeaveTransition({ el: leaveRef, cb: () => { this.setState({ transObj: transObj, animated: false, }) }, }) } }
check whether animation should be updated for performance it does not used for under component but in the future we would be used @param {Object} prev props @param {Object} next props
componentDidUpdate
javascript
GeekyAnts/vue-native-core
src/platforms/vue-native/runtime/components/buildWebTransition.js
https://github.com/GeekyAnts/vue-native-core/blob/master/src/platforms/vue-native/runtime/components/buildWebTransition.js
MIT
render() { const transObj = this.state.transObj const tag = this.props.tag || EmptyComponent return createElement( tag, null, Object.keys(transObj).map(k => { const type = transObj[k].element.type const props = transObj[k].props const children = props.children return createElement(type, props, children) }), ) }
check whether animation should be updated for performance it does not used for under component but in the future we would be used @param {Object} prev props @param {Object} next props
render
javascript
GeekyAnts/vue-native-core
src/platforms/vue-native/runtime/components/buildWebTransition.js
https://github.com/GeekyAnts/vue-native-core/blob/master/src/platforms/vue-native/runtime/components/buildWebTransition.js
MIT
function handleComponents(components) { for (const k in components) { if (hasOwn(components, k)) { components[pascalCaseTag(k)] = components[k] const c = components[k] if (c.name) { components[pascalCaseTag(c.name)] = components[k] } } } return components }
for options {components} @param {Object} components
handleComponents
javascript
GeekyAnts/vue-native-core
src/platforms/vue-native/runtime/components/util.js
https://github.com/GeekyAnts/vue-native-core/blob/master/src/platforms/vue-native/runtime/components/util.js
MIT
function handleDirectives(directives) { const obj = {} for (const k in directives) { obj[k.toLowerCase().replace(/[^a-z]/g, '')] = directives[k] } return obj }
for options {components} @param {Object} components
handleDirectives
javascript
GeekyAnts/vue-native-core
src/platforms/vue-native/runtime/components/util.js
https://github.com/GeekyAnts/vue-native-core/blob/master/src/platforms/vue-native/runtime/components/util.js
MIT
function getSlots(children) { const slots = {} if (children == null) { return slots } if (!Array.isArray(children)) { children = [children] } children = children.filter(v => v != null) children.forEach(v => { if (typeof v === 'string' || typeof v === 'number' || v === null) { slots.default = slots.default || [] slots.default.push(v) } else if (v.type === COMMON.template.type) { // data-slot renamed to dataSlot to fix named slot issue slots[v['dataSlot']] = slots[v['dataSlot']] || [] slots[v['dataSlot']].push(v.render) } else if (v.props) { const dataSlot = v.props['dataSlot'] if (dataSlot == null) { slots.default = slots.default || [] slots.default.push(v) } else { slots[dataSlot] = slots[dataSlot] || [] slots[dataSlot].push(v) } } }) return slots }
for 'this.$solts' @param {this.props.children} children
getSlots
javascript
GeekyAnts/vue-native-core
src/platforms/vue-native/runtime/components/util.js
https://github.com/GeekyAnts/vue-native-core/blob/master/src/platforms/vue-native/runtime/components/util.js
MIT
function filterCustomEvent(props) { return Object.keys(props) .filter(v => { return v.indexOf(COMMON.customEvent.name) === 0 }) .map(v => { return { name: v.replace(COMMON.customEvent.name, ''), handle: props[v], } }) }
for 'this.$solts' @param {this.props.children} children
filterCustomEvent
javascript
GeekyAnts/vue-native-core
src/platforms/vue-native/runtime/components/util.js
https://github.com/GeekyAnts/vue-native-core/blob/master/src/platforms/vue-native/runtime/components/util.js
MIT
function getHookArgumentsLength(fn) { if (isUndef(fn)) { return false } const invokerFns = fn.fns if (isDef(invokerFns)) { // invoker return getHookArgumentsLength( Array.isArray(invokerFns) ? invokerFns[0] : invokerFns, ) } else { return (fn._length || fn.length) > 1 } }
Normalize a transition hook's argument length. The hook may be: - a merged hook (invoker) with the original in .fns - a wrapped component method (check ._length) - a plain function (.length)
getHookArgumentsLength
javascript
GeekyAnts/vue-native-core
src/platforms/vue-native/runtime/render-helpers/transitionWeb.js
https://github.com/GeekyAnts/vue-native-core/blob/master/src/platforms/vue-native/runtime/render-helpers/transitionWeb.js
MIT
function checkDuration(val, name) { if (typeof val !== 'number') { warn( `<transition> explicit ${name} duration is not a valid number - ` + `got ${JSON.stringify(val)}.`, ) } else if (isNaN(val)) { warn( `<transition> explicit ${name} duration is NaN - ` + 'the duration expression might be incorrect.', ) } }
Normalize a transition hook's argument length. The hook may be: - a merged hook (invoker) with the original in .fns - a wrapped component method (check ._length) - a plain function (.length)
checkDuration
javascript
GeekyAnts/vue-native-core
src/platforms/vue-native/runtime/render-helpers/transitionWeb.js
https://github.com/GeekyAnts/vue-native-core/blob/master/src/platforms/vue-native/runtime/render-helpers/transitionWeb.js
MIT
function isValidDuration(val) { return typeof val === 'number' && !isNaN(val) }
Normalize a transition hook's argument length. The hook may be: - a merged hook (invoker) with the original in .fns - a wrapped component method (check ._length) - a plain function (.length)
isValidDuration
javascript
GeekyAnts/vue-native-core
src/platforms/vue-native/runtime/render-helpers/transitionWeb.js
https://github.com/GeekyAnts/vue-native-core/blob/master/src/platforms/vue-native/runtime/render-helpers/transitionWeb.js
MIT
function addTransitionClass(ref, className) { addClass(ref, className) }
Normalize a transition hook's argument length. The hook may be: - a merged hook (invoker) with the original in .fns - a wrapped component method (check ._length) - a plain function (.length)
addTransitionClass
javascript
GeekyAnts/vue-native-core
src/platforms/vue-native/runtime/render-helpers/transitionWeb.js
https://github.com/GeekyAnts/vue-native-core/blob/master/src/platforms/vue-native/runtime/render-helpers/transitionWeb.js
MIT
function removeTransitionClass(ref, className) { removeClass(ref, className) }
Normalize a transition hook's argument length. The hook may be: - a merged hook (invoker) with the original in .fns - a wrapped component method (check ._length) - a plain function (.length)
removeTransitionClass
javascript
GeekyAnts/vue-native-core
src/platforms/vue-native/runtime/render-helpers/transitionWeb.js
https://github.com/GeekyAnts/vue-native-core/blob/master/src/platforms/vue-native/runtime/render-helpers/transitionWeb.js
MIT
function enter({ el, cb }) { const { css, type, enterClass, enterToClass, enterActiveClass, appearClass, appearToClass, appearActiveClass, onBeforeEnter, onEnter, onAfterEnter, onEnterCancelled, onBeforeAppear, appear, onAppear, onAfterAppear, onAppearCancelled, duration, } = this.transitionResolved const isAppear = this.isAppear if (isUndef(el)) { return } if (isAppear && !appear && appear !== '') { return } if (isDef(el._enterCb) || el.nodeType !== 1) { return } const startClass = isAppear && appearClass ? appearClass : enterClass const activeClass = isAppear && appearActiveClass ? appearActiveClass : enterActiveClass const toClass = isAppear && appearToClass ? appearToClass : enterToClass const beforeEnterHook = isAppear ? onBeforeAppear || onBeforeEnter : onBeforeEnter const enterHook = isAppear ? onAppear || onEnter : onEnter const afterEnterHook = isAppear ? onAfterAppear || onAfterEnter : onAfterEnter const enterCancelledHook = isAppear ? onAppearCancelled || onEnterCancelled : onEnterCancelled const explicitEnterDuration = toNumber( isObject(duration) ? duration.enter : duration, ) if (process.env.NODE_ENV !== 'production' && explicitEnterDuration != null) { checkDuration(explicitEnterDuration, 'enter') } const expectsCSS = css !== false && !isIE9 const userWantsControl = getHookArgumentsLength(enterHook) const _cb = (el._enterCb = once(() => { if (expectsCSS) { removeTransitionClass(el, activeClass) removeTransitionClass(el, toClass) } cb && cb() if (_cb.cancelled) { if (expectsCSS) { removeTransitionClass(el, startClass) } enterCancelledHook && enterCancelledHook(el) } else { afterEnterHook && afterEnterHook(el) } el._enterCb = null })) beforeEnterHook && beforeEnterHook(el) if (expectsCSS) { addTransitionClass(el, startClass) addTransitionClass(el, activeClass) nextFrame(() => { removeTransitionClass(el, startClass) addTransitionClass(el, toClass) if (!_cb.cancelled && !userWantsControl) { if (isValidDuration(explicitEnterDuration)) { setTimeout(_cb, explicitEnterDuration) } else { whenTransitionEnds(el, type || getTransitionInfo(el).type, _cb) } } }) } nextFrame(() => enterHook && enterHook(el, _cb)) if (!expectsCSS && !userWantsControl) { _cb() } }
Normalize a transition hook's argument length. The hook may be: - a merged hook (invoker) with the original in .fns - a wrapped component method (check ._length) - a plain function (.length)
enter
javascript
GeekyAnts/vue-native-core
src/platforms/vue-native/runtime/render-helpers/transitionWeb.js
https://github.com/GeekyAnts/vue-native-core/blob/master/src/platforms/vue-native/runtime/render-helpers/transitionWeb.js
MIT
function leave({ el, cb }) { const { css, type, leaveClass, leaveToClass, leaveActiveClass, onBeforeLeave, onLeave, onAfterLeave, onLeaveCancelled, duration, } = this.transitionResolved if (isUndef(el)) { return } if (isDef(el._leaveCb) || el.nodeType !== 1) { return } const expectsCSS = css !== false && !isIE9 const userWantsControl = getHookArgumentsLength(onLeave) const explicitLeaveDuration = toNumber( isObject(duration) ? duration.leave : duration, ) if (process.env.NODE_ENV !== 'production' && explicitLeaveDuration != null) { checkDuration(explicitLeaveDuration, 'leave') } const _cb = (el._leaveCb = once(() => { if (expectsCSS) { removeTransitionClass(el, leaveActiveClass) removeTransitionClass(el, leaveToClass) } cb && cb() if (_cb.cancelled) { if (expectsCSS) { removeTransitionClass(el, leaveClass) } onLeaveCancelled && onLeaveCancelled(el) } else { onAfterLeave && onAfterLeave(el) } el._leaveCb = null })) onBeforeLeave && onBeforeLeave(el) if (expectsCSS) { addTransitionClass(el, leaveClass) addTransitionClass(el, leaveActiveClass) nextFrame(() => { removeTransitionClass(el, leaveClass) addTransitionClass(el, leaveToClass) if (!_cb.cancelled && !userWantsControl) { if (isValidDuration(explicitLeaveDuration)) { setTimeout(_cb, explicitLeaveDuration) } else { whenTransitionEnds(el, type || getTransitionInfo(el).type, _cb) } } }) } onLeave && onLeave(el, _cb) if (!expectsCSS && !userWantsControl) { _cb() } }
Normalize a transition hook's argument length. The hook may be: - a merged hook (invoker) with the original in .fns - a wrapped component method (check ._length) - a plain function (.length)
leave
javascript
GeekyAnts/vue-native-core
src/platforms/vue-native/runtime/render-helpers/transitionWeb.js
https://github.com/GeekyAnts/vue-native-core/blob/master/src/platforms/vue-native/runtime/render-helpers/transitionWeb.js
MIT
function transitionWeb(Component, createElement) { class Transition extends Component { constructor(props) { super(props) this._refs = {} this.transitionResolved = {} this._shouldComponentUpdateTransitionResult = false this.isAppear = false this.state = { transObj: {}, animated: true, tagKey: null, } } setRef(ref, key) { if (!ref) { return } this._refs[key] = ref.ref || ref } resolveData(props, type) { const target = filterCollection(props[WEB.transition.collection])[0] if (target) { const element = target.element const _props = {} for (const key in element.props) { _props[key] = element.props[key] } let key = target.index if (element.key != null) { key = element.key + key } if (target.type === 'component') { const targetExp = target.exp const thisTarget = this.state.transObj[this.state.tagKey] const thisExp = thisTarget && thisTarget.exp if (targetExp !== thisExp) { key = this.state.tagKey === 0 ? 1 : 0 } } _props.key = _props.key || key const setRef = ref => { this.setRef(ref, _props.key) element.ref && element.ref(ref) } if (target.type === 'component') { _props[COMMON.setRef.name] = setRef } else { _props.ref = setRef } const transObj = Object.assign({}, this.state.transObj) transObj[_props.key] = Object.assign({}, target, { props: _props, }) return { transObj: transObj, animated: true, tagKey: _props.key, } } else if (type === 'update') { return this.triggerTransitionExp() } } triggerTransitionExp() { const tagKey = this.state.tagKey const transition = this.state.transObj[tagKey] // someone want to hide and his prev state is show if (transition) { const transObj = {} transObj[tagKey] = Object.assign({}, transition, { exp: !transition.exp, }) return { animated: true, transObj: transObj, tagKey: tagKey, } } } UNSAFE_componentWillMount() { this.transitionResolved = resolveTransition(this.props) this.isAppear = true const state = this.resolveData(this.props) state && this.setState(state) } componentDidMount() { this.resolveEnterTransition({ el: this._refs[this.state.tagKey], }) } UNSAFE_componentWillReceiveProps(nextProps) { this.transitionResolved = resolveTransition(nextProps) this.isAppear = false const nextState = this.resolveData(nextProps, 'update') this._shouldComponentUpdateTransitionResult = nextState ? this._shouldComponentUpdateTransition(nextProps, nextState) : true Object.keys(this._refs).forEach(k => { const el = this._refs[k] if (isDef(el._leaveCb)) { el._leaveCb.cancelled = true el._leaveCb() } if (isDef(el._enterCb)) { el._enterCb.cancelled = true el._enterCb() } }) nextState && this.setState(nextState) } _shouldComponentUpdateTransition(nextProps, nextState) { if ( Object.keys(nextState.transObj).length !== Object.keys(this.state.transObj).length ) { return true } if (nextState.tagKey === this.state.tagKey) { const nextTransition = nextState.transObj[nextState.tagKey] const transition = this.state.transObj[this.state.tagKey] if (nextTransition && transition) { return transition.exp !== nextTransition.exp } } return true } // shouldComponentUpdate () { // return this._shouldComponentUpdateTransitionResult // } resolveEnterTransition(option) { enter.call(this, option) } resolveLeaveTransition(option) { leave.call(this, option) } componentDidUpdate(prevProps, prevState) { if ( this.state.animated === false || this._shouldComponentUpdateTransition === false ) { return } if (this.state.tagKey === prevState.tagKey) { // same element const ref = this._refs[this.state.tagKey] const transition = this.state.transObj[this.state.tagKey] if (ref && transition) { if (transition.type === 'show') { if (transition.exp === false) { this.resolveLeaveTransition({ el: ref, cb: () => { ref.style.display = 'none' }, }) } else if (transition.exp === true) { ref.style.display = '' this.resolveEnterTransition({ el: ref, }) } } else if (transition.type === 'if') { if (transition.exp === false) { const transObj = Object.assign({}, this.state.transObj) delete transObj[prevState.tagKey] this.resolveLeaveTransition({ el: ref, cb: () => { this.setState({ transObj: transObj, animated: false, }) }, }) } else if (transition.exp === true) { this.resolveEnterTransition({ el: ref, }) } } } } else { const enterRef = this._refs[this.state.tagKey] const leaveRef = this._refs[prevState.tagKey] const transObj = Object.assign({}, this.state.transObj) delete transObj[prevState.tagKey] this.resolveEnterTransition({ el: enterRef, }) this.resolveLeaveTransition({ el: leaveRef, cb: () => { this.setState({ transObj: transObj, animated: false, }) }, }) } } render() { const transObj = this.state.transObj const tag = this.props.tag || 'null' return createElement( tag, null, Object.keys(transObj).map(k => { const type = transObj[k].element.type const props = transObj[k].props const children = props.children return createElement(type, props, children) }), ) } } return Transition }
Normalize a transition hook's argument length. The hook may be: - a merged hook (invoker) with the original in .fns - a wrapped component method (check ._length) - a plain function (.length)
transitionWeb
javascript
GeekyAnts/vue-native-core
src/platforms/vue-native/runtime/render-helpers/transitionWeb.js
https://github.com/GeekyAnts/vue-native-core/blob/master/src/platforms/vue-native/runtime/render-helpers/transitionWeb.js
MIT
constructor(props) { super(props) this._refs = {} this.transitionResolved = {} this._shouldComponentUpdateTransitionResult = false this.isAppear = false this.state = { transObj: {}, animated: true, tagKey: null, } }
Normalize a transition hook's argument length. The hook may be: - a merged hook (invoker) with the original in .fns - a wrapped component method (check ._length) - a plain function (.length)
constructor
javascript
GeekyAnts/vue-native-core
src/platforms/vue-native/runtime/render-helpers/transitionWeb.js
https://github.com/GeekyAnts/vue-native-core/blob/master/src/platforms/vue-native/runtime/render-helpers/transitionWeb.js
MIT
setRef(ref, key) { if (!ref) { return } this._refs[key] = ref.ref || ref }
Normalize a transition hook's argument length. The hook may be: - a merged hook (invoker) with the original in .fns - a wrapped component method (check ._length) - a plain function (.length)
setRef
javascript
GeekyAnts/vue-native-core
src/platforms/vue-native/runtime/render-helpers/transitionWeb.js
https://github.com/GeekyAnts/vue-native-core/blob/master/src/platforms/vue-native/runtime/render-helpers/transitionWeb.js
MIT
resolveData(props, type) { const target = filterCollection(props[WEB.transition.collection])[0] if (target) { const element = target.element const _props = {} for (const key in element.props) { _props[key] = element.props[key] } let key = target.index if (element.key != null) { key = element.key + key } if (target.type === 'component') { const targetExp = target.exp const thisTarget = this.state.transObj[this.state.tagKey] const thisExp = thisTarget && thisTarget.exp if (targetExp !== thisExp) { key = this.state.tagKey === 0 ? 1 : 0 } } _props.key = _props.key || key const setRef = ref => { this.setRef(ref, _props.key) element.ref && element.ref(ref) } if (target.type === 'component') { _props[COMMON.setRef.name] = setRef } else { _props.ref = setRef } const transObj = Object.assign({}, this.state.transObj) transObj[_props.key] = Object.assign({}, target, { props: _props, }) return { transObj: transObj, animated: true, tagKey: _props.key, } } else if (type === 'update') { return this.triggerTransitionExp() } }
Normalize a transition hook's argument length. The hook may be: - a merged hook (invoker) with the original in .fns - a wrapped component method (check ._length) - a plain function (.length)
resolveData
javascript
GeekyAnts/vue-native-core
src/platforms/vue-native/runtime/render-helpers/transitionWeb.js
https://github.com/GeekyAnts/vue-native-core/blob/master/src/platforms/vue-native/runtime/render-helpers/transitionWeb.js
MIT