You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@weex.apache.org by ha...@apache.org on 2018/01/03 07:13:49 UTC
[18/22] incubator-weex git commit: * [jsfm] Adjust the file structure
of js framework
http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/51dd277e/html5/render/native/setup.js
----------------------------------------------------------------------
diff --git a/html5/render/native/setup.js b/html5/render/native/setup.js
deleted file mode 100644
index d7404cb..0000000
--- a/html5/render/native/setup.js
+++ /dev/null
@@ -1,58 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-import { subversion } from '../../../package.json'
-import runtime from '../../runtime'
-import services from '../../services/index'
-
-/**
- * Setup frameworks with runtime.
- * You can package more frameworks by
- * passing them as arguments.
- */
-export default function (frameworks) {
- const { init, config } = runtime
- config.frameworks = frameworks
- const { native, transformer } = subversion
-
- for (const serviceName in services) {
- runtime.service.register(serviceName, services[serviceName])
- }
-
- runtime.freezePrototype()
- runtime.setNativeConsole()
-
- // register framework meta info
- global.frameworkVersion = native
- global.transformerVersion = transformer
-
- // init frameworks
- const globalMethods = init(config)
-
- // set global methods
- for (const methodName in globalMethods) {
- global[methodName] = (...args) => {
- const ret = globalMethods[methodName](...args)
- if (ret instanceof Error) {
- console.error(ret.toString())
- }
- return ret
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/51dd277e/html5/render/vue/README.md
----------------------------------------------------------------------
diff --git a/html5/render/vue/README.md b/html5/render/vue/README.md
deleted file mode 100644
index a8bf32e..0000000
--- a/html5/render/vue/README.md
+++ /dev/null
@@ -1,3 +0,0 @@
-# weex-vue-render
-
-This project has been moved to [weexteam group](https://github.com/weexteam/weex-vue-render)
http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/51dd277e/html5/runtime/api/WeexInstance.js
----------------------------------------------------------------------
diff --git a/html5/runtime/api/WeexInstance.js b/html5/runtime/api/WeexInstance.js
deleted file mode 100644
index 3bc25e6..0000000
--- a/html5/runtime/api/WeexInstance.js
+++ /dev/null
@@ -1,138 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-import Document from '../vdom/Document'
-import { isRegisteredModule, getModuleDescription } from './module'
-import { isRegisteredComponent } from './component'
-import { getTaskCenter } from '../vdom/operation'
-
-const moduleProxies = {}
-
-function setId (weex, id) {
- Object.defineProperty(weex, '[[CurrentInstanceId]]', { value: id })
-}
-
-function getId (weex) {
- return weex['[[CurrentInstanceId]]']
-}
-
-function moduleGetter (id, module, method) {
- const taskCenter = getTaskCenter(id)
- if (!taskCenter || typeof taskCenter.send !== 'function') {
- console.error(`[JS Framework] Failed to find taskCenter (${id}).`)
- return null
- }
- return (...args) => taskCenter.send('module', { module, method }, args)
-}
-
-function moduleSetter (id, module, method, fn) {
- const taskCenter = getTaskCenter(id)
- if (!taskCenter || typeof taskCenter.send !== 'function') {
- console.error(`[JS Framework] Failed to find taskCenter (${id}).`)
- return null
- }
- if (typeof fn !== 'function') {
- console.error(`[JS Framework] ${module}.${method} must be assigned as a function.`)
- return null
- }
- return fn => taskCenter.send('module', { module, method }, [fn])
-}
-
-export default class WeexInstance {
- constructor (id, config) {
- setId(this, String(id))
- this.config = config || {}
- this.document = new Document(id, this.config.bundleUrl)
- this.requireModule = this.requireModule.bind(this)
- this.isRegisteredModule = isRegisteredModule
- this.isRegisteredComponent = isRegisteredComponent
- }
-
- requireModule (moduleName) {
- const id = getId(this)
- if (!(id && this.document && this.document.taskCenter)) {
- console.error(`[JS Framework] Failed to requireModule("${moduleName}"), `
- + `instance (${id}) doesn't exist anymore.`)
- return
- }
-
- // warn for unknown module
- if (!isRegisteredModule(moduleName)) {
- console.warn(`[JS Framework] using unregistered weex module "${moduleName}"`)
- return
- }
-
- // create new module proxy
- const proxyName = `${moduleName}#${id}`
- if (!moduleProxies[proxyName]) {
- // create registered module apis
- const moduleDefine = getModuleDescription(moduleName)
- const moduleApis = {}
- for (const methodName in moduleDefine) {
- Object.defineProperty(moduleApis, methodName, {
- enumerable: true,
- configurable: true,
- get: () => moduleGetter(id, moduleName, methodName),
- set: fn => moduleSetter(id, moduleName, methodName, fn)
- })
- }
-
- // create module Proxy
- if (typeof Proxy === 'function') {
- moduleProxies[proxyName] = new Proxy(moduleApis, {
- get (target, methodName) {
- if (methodName in target) {
- return target[methodName]
- }
- console.warn(`[JS Framework] using unregistered method "${moduleName}.${methodName}"`)
- return moduleGetter(id, moduleName, methodName)
- }
- })
- }
- else {
- moduleProxies[proxyName] = moduleApis
- }
- }
-
- return moduleProxies[proxyName]
- }
-
- supports (condition) {
- if (typeof condition !== 'string') return null
-
- const res = condition.match(/^@(\w+)\/(\w+)(\.(\w+))?$/i)
- if (res) {
- const type = res[1]
- const name = res[2]
- const method = res[4]
- switch (type) {
- case 'module': return isRegisteredModule(name, method)
- case 'component': return isRegisteredComponent(name)
- }
- }
-
- return null
- }
-
- // registerStyleSheet (styles) {
- // if (this.document) {
- // this.document.registerStyleSheet(styles)
- // }
- // }
-}
http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/51dd277e/html5/runtime/api/component.js
----------------------------------------------------------------------
diff --git a/html5/runtime/api/component.js b/html5/runtime/api/component.js
deleted file mode 100644
index 8a56961..0000000
--- a/html5/runtime/api/component.js
+++ /dev/null
@@ -1,51 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-import { registerElement } from '../vdom/WeexElement'
-
-const weexComponents = {}
-
-/**
- * Register native components information.
- * @param {array} newComponents
- */
-export function registerComponents (newComponents) {
- if (Array.isArray(newComponents)) {
- newComponents.forEach(component => {
- if (!component) {
- return
- }
- if (typeof component === 'string') {
- weexComponents[component] = true
- }
- else if (typeof component === 'object' && typeof component.type === 'string') {
- weexComponents[component.type] = component
- registerElement(component.type, component.methods)
- }
- })
- }
-}
-
-/**
- * Check whether the component has been registered.
- * @param {String} component name
- */
-export function isRegisteredComponent (name) {
- return !!weexComponents[name]
-}
http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/51dd277e/html5/runtime/api/config.js
----------------------------------------------------------------------
diff --git a/html5/runtime/api/config.js b/html5/runtime/api/config.js
deleted file mode 100644
index d212f3d..0000000
--- a/html5/runtime/api/config.js
+++ /dev/null
@@ -1,37 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-import { Document, Element, Comment } from '../vdom'
-import Listener from '../bridge/Listener'
-import { TaskCenter } from '../bridge/TaskCenter'
-
-const config = {
- Document, Element, Comment, Listener,
- TaskCenter,
- sendTasks (...args) {
- if (typeof callNative === 'function') {
- return callNative(...args)
- }
- return (global.callNative || (() => {}))(...args)
- }
-}
-
-Document.handler = config.sendTasks
-
-export default config
http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/51dd277e/html5/runtime/api/init.js
----------------------------------------------------------------------
diff --git a/html5/runtime/api/init.js b/html5/runtime/api/init.js
deleted file mode 100644
index 187504a..0000000
--- a/html5/runtime/api/init.js
+++ /dev/null
@@ -1,304 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-import { init as initTaskHandler } from '../bridge/TaskCenter'
-import { receiveTasks } from '../bridge/receiver'
-import { registerModules } from './module'
-import { registerComponents } from './component'
-import { services, register, unregister } from './service'
-import { track } from '../bridge/debug'
-import WeexInstance from './WeexInstance'
-import { getDoc } from '../vdom/operation'
-
-let frameworks
-let runtimeConfig
-
-const versionRegExp = /^\s*\/\/ *(\{[^}]*\}) *\r?\n/
-
-/**
- * Detect a JS Bundle code and make sure which framework it's based to. Each JS
- * Bundle should make sure that it starts with a line of JSON comment and is
- * more that one line.
- * @param {string} code
- * @return {object}
- */
-function getBundleType (code) {
- const result = versionRegExp.exec(code)
- if (result) {
- try {
- const info = JSON.parse(result[1])
- return info.framework
- }
- catch (e) {}
- }
-
- // default bundle type
- return 'Weex'
-}
-
-function createServices (id, env, config) {
- // Init JavaScript services for this instance.
- const serviceMap = Object.create(null)
- serviceMap.service = Object.create(null)
- services.forEach(({ name, options }) => {
- if (process.env.NODE_ENV === 'development') {
- console.debug(`[JS Runtime] create service ${name}.`)
- }
- const create = options.create
- if (create) {
- const result = create(id, env, config)
- Object.assign(serviceMap.service, result)
- Object.assign(serviceMap, result.instance)
- }
- })
- delete serviceMap.service.instance
- Object.freeze(serviceMap.service)
- return serviceMap
-}
-
-const instanceTypeMap = {}
-function getFrameworkType (id) {
- return instanceTypeMap[id]
-}
-
-function createInstanceContext (id, options = {}, data) {
- const weex = new WeexInstance(id, options)
- Object.freeze(weex)
-
- const bundleType = options.bundleType || 'Vue'
- instanceTypeMap[id] = bundleType
- const framework = runtimeConfig.frameworks[bundleType]
- if (!framework) {
- return new Error(`[JS Framework] Invalid bundle type "${bundleType}".`)
- }
- track(id, 'bundleType', bundleType)
-
- // prepare js service
- const services = createServices(id, { weex, bundleType }, runtimeConfig)
- Object.freeze(services)
-
- // prepare runtime context
- const runtimeContext = Object.create(null)
- Object.assign(runtimeContext, services, {
- weex,
- services // Temporary compatible with some legacy APIs in Rax
- })
- Object.freeze(runtimeContext)
-
- // prepare instance context
- const instanceContext = Object.create(runtimeContext)
- if (typeof framework.createInstanceContext === 'function') {
- Object.assign(instanceContext, framework.createInstanceContext(id, runtimeContext, data))
- }
- Object.freeze(instanceContext)
- return instanceContext
-}
-
-/**
- * Check which framework a certain JS Bundle code based to. And create instance
- * by this framework.
- * @param {string} id
- * @param {string} code
- * @param {object} config
- * @param {object} data
- */
-function createInstance (id, code, config, data) {
- if (instanceTypeMap[id]) {
- return new Error(`The instance id "${id}" has already been used!`)
- }
-
- // Init instance info.
- const bundleType = getBundleType(code)
- instanceTypeMap[id] = bundleType
-
- // Init instance config.
- config = JSON.parse(JSON.stringify(config || {}))
- config.env = JSON.parse(JSON.stringify(global.WXEnvironment || {}))
- config.bundleType = bundleType
-
- const framework = runtimeConfig.frameworks[bundleType]
- if (!framework) {
- return new Error(`[JS Framework] Invalid bundle type "${bundleType}".`)
- }
- if (bundleType === 'Weex') {
- console.error(`[JS Framework] COMPATIBILITY WARNING: `
- + `Weex DSL 1.0 (.we) framework is no longer supported! `
- + `It will be removed in the next version of WeexSDK, `
- + `your page would be crash if you still using the ".we" framework. `
- + `Please upgrade it to Vue.js or Rax.`)
- }
-
- const instanceContext = createInstanceContext(id, config, data)
- if (typeof framework.createInstance === 'function') {
- // Temporary compatible with some legacy APIs in Rax,
- // some Rax page is using the legacy ".we" framework.
- if (bundleType === 'Rax' || bundleType === 'Weex') {
- const raxInstanceContext = Object.assign({
- config,
- created: Date.now(),
- framework: bundleType
- }, instanceContext)
- return framework.createInstance(id, code, config, data, raxInstanceContext)
- }
- return framework.createInstance(id, code, config, data, instanceContext)
- }
- // console.error(`[JS Framework] Can't find available "createInstance" method in ${bundleType}!`)
- runInContext(code, instanceContext)
-}
-
-/**
- * Run js code in a specific context.
- * @param {string} code
- * @param {object} context
- */
-function runInContext (code, context) {
- const keys = []
- const args = []
- for (const key in context) {
- keys.push(key)
- args.push(context[key])
- }
-
- const bundle = `
- (function (global) {
- ${code}
- })(Object.create(this))
- `
-
- return (new Function(...keys, bundle))(...args)
-}
-
-/**
- * Get the JSON object of the root element.
- * @param {string} instanceId
- */
-function getRoot (instanceId) {
- const document = getDoc(instanceId)
- try {
- if (document && document.body) {
- return document.body.toJSON()
- }
- }
- catch (e) {
- console.error(`[JS Framework] Failed to get the virtual dom tree.`)
- return
- }
-}
-
-const methods = {
- createInstance,
- createInstanceContext,
- getRoot,
- getDocument: getDoc,
- registerService: register,
- unregisterService: unregister,
- callJS (id, tasks) {
- const framework = frameworks[getFrameworkType(id)]
- if (framework && typeof framework.receiveTasks === 'function') {
- return framework.receiveTasks(id, tasks)
- }
- return receiveTasks(id, tasks)
- }
-}
-
-/**
- * Register methods which will be called for each instance.
- * @param {string} methodName
- */
-function genInstance (methodName) {
- methods[methodName] = function (...args) {
- const id = args[0]
- const type = getFrameworkType(id)
- if (type && frameworks[type]) {
- const result = frameworks[type][methodName](...args)
- const info = { framework: type }
-
- // Lifecycle methods
- if (methodName === 'refreshInstance') {
- services.forEach(service => {
- const refresh = service.options.refresh
- if (refresh) {
- refresh(id, { info, runtime: runtimeConfig })
- }
- })
- }
- else if (methodName === 'destroyInstance') {
- services.forEach(service => {
- const destroy = service.options.destroy
- if (destroy) {
- destroy(id, { info, runtime: runtimeConfig })
- }
- })
- delete instanceTypeMap[id]
- }
-
- return result
- }
- return new Error(`[JS Framework] Using invalid instance id `
- + `"${id}" when calling ${methodName}.`)
- }
-}
-
-/**
- * Register methods which init each frameworks.
- * @param {string} methodName
- * @param {function} sharedMethod
- */
-function adaptMethod (methodName, sharedMethod) {
- methods[methodName] = function (...args) {
- if (typeof sharedMethod === 'function') {
- sharedMethod(...args)
- }
-
- // TODO: deprecated
- for (const name in runtimeConfig.frameworks) {
- const framework = runtimeConfig.frameworks[name]
- if (framework && framework[methodName]) {
- framework[methodName](...args)
- }
- }
- }
-}
-
-export default function init (config) {
- runtimeConfig = config || {}
- frameworks = runtimeConfig.frameworks || {}
- initTaskHandler()
-
- // Init each framework by `init` method and `config` which contains three
- // virtual-DOM Class: `Document`, `Element` & `Comment`, and a JS bridge method:
- // `sendTasks(...args)`.
- for (const name in frameworks) {
- const framework = frameworks[name]
- if (typeof framework.init === 'function') {
- try {
- framework.init(config)
- }
- catch (e) {}
- }
- }
-
- adaptMethod('registerComponents', registerComponents)
- adaptMethod('registerModules', registerModules)
- adaptMethod('registerMethods')
-
- ; ['destroyInstance', 'refreshInstance'].forEach(genInstance)
-
- return methods
-}
http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/51dd277e/html5/runtime/api/module.js
----------------------------------------------------------------------
diff --git a/html5/runtime/api/module.js b/html5/runtime/api/module.js
deleted file mode 100644
index df26b92..0000000
--- a/html5/runtime/api/module.js
+++ /dev/null
@@ -1,56 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-const weexModules = {}
-
-/**
- * Register native modules information.
- * @param {object} newModules
- */
-export function registerModules (newModules) {
- for (const name in newModules) {
- if (!weexModules[name]) {
- weexModules[name] = {}
- }
- newModules[name].forEach(method => {
- if (typeof method === 'string') {
- weexModules[name][method] = true
- }
- else {
- weexModules[name][method.name] = method.args
- }
- })
- }
-}
-
-/**
- * Check whether the module or the method has been registered.
- * @param {String} module name
- * @param {String} method name (optional)
- */
-export function isRegisteredModule (name, method) {
- if (typeof method === 'string') {
- return !!(weexModules[name] && weexModules[name][method])
- }
- return !!weexModules[name]
-}
-
-export function getModuleDescription (name) {
- return weexModules[name]
-}
http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/51dd277e/html5/runtime/api/service.js
----------------------------------------------------------------------
diff --git a/html5/runtime/api/service.js b/html5/runtime/api/service.js
deleted file mode 100644
index 6f2e72e..0000000
--- a/html5/runtime/api/service.js
+++ /dev/null
@@ -1,77 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-// JS Services
-
-export const services = []
-
-/**
- * Register a JavaScript service.
- * A JavaScript service options could have a set of lifecycle methods
- * for each Weex instance. For example: create, refresh, destroy.
- * For the JS framework maintainer if you want to supply some features
- * which need to work well in different Weex instances, even in different
- * frameworks separately. You can make a JavaScript service to init
- * its variables or classes for each Weex instance when it's created
- * and recycle them when it's destroyed.
- * @param {object} options Could have { create, refresh, destroy }
- * lifecycle methods. In create method it should
- * return an object of what variables or classes
- * would be injected into the Weex instance.
- */
-export function register (name, options) {
- if (has(name)) {
- console.warn(`Service "${name}" has been registered already!`)
- }
- else {
- options = Object.assign({}, options)
- services.push({ name, options })
- }
-}
-
-/**
- * Unregister a JavaScript service by name
- * @param {string} name
- */
-export function unregister (name) {
- services.some((service, index) => {
- if (service.name === name) {
- services.splice(index, 1)
- return true
- }
- })
-}
-
-/**
- * Check if a JavaScript service with a certain name existed.
- * @param {string} name
- * @return {Boolean}
- */
-export function has (name) {
- return indexOf(name) >= 0
-}
-
-/**
- * Find the index of a JavaScript service by name
- * @param {string} name
- * @return {number}
- */
-function indexOf (name) {
- return services.map(service => service.name).indexOf(name)
-}
http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/51dd277e/html5/runtime/bridge/CallbackManager.js
----------------------------------------------------------------------
diff --git a/html5/runtime/bridge/CallbackManager.js b/html5/runtime/bridge/CallbackManager.js
deleted file mode 100644
index 70bd729..0000000
--- a/html5/runtime/bridge/CallbackManager.js
+++ /dev/null
@@ -1,89 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-import { decodePrimitive } from './normalize'
-
-function getHookKey (componentId, type, hookName) {
- return `${type}@${hookName}#${componentId}`
-}
-
-/**
- * For general callback management of a certain Weex instance.
- * Because function can not passed into native, so we create callback
- * callback id for each function and pass the callback id into native
- * in fact. And when a callback called from native, we can find the real
- * callback through the callback id we have passed before.
- */
-export default class CallbackManager {
- constructor (instanceId) {
- this.instanceId = String(instanceId)
- this.lastCallbackId = 0
- this.callbacks = {}
- this.hooks = {}
- }
- add (callback) {
- this.lastCallbackId++
- this.callbacks[this.lastCallbackId] = callback
- return this.lastCallbackId
- }
- remove (callbackId) {
- const callback = this.callbacks[callbackId]
- delete this.callbacks[callbackId]
- return callback
- }
- registerHook (componentId, type, hookName, hookFunction) {
- // TODO: validate arguments
- const key = getHookKey(componentId, type, hookName)
- if (this.hooks[key]) {
- console.warn(`[JS Framework] Override an existing component hook "${key}".`)
- }
- this.hooks[key] = hookFunction
- }
- triggerHook (componentId, type, hookName, options = {}) {
- // TODO: validate arguments
- const key = getHookKey(componentId, type, hookName)
- const hookFunction = this.hooks[key]
- if (typeof hookFunction !== 'function') {
- console.error(`[JS Framework] Invalid hook function type (${typeof hookFunction}) on "${key}".`)
- return null
- }
- let result = null
- try {
- result = hookFunction.apply(null, options.args || [])
- }
- catch (e) {
- console.error(`[JS Framework] Failed to execute the hook function on "${key}".`)
- }
- return result
- }
- consume (callbackId, data, ifKeepAlive) {
- const callback = this.callbacks[callbackId]
- if (typeof ifKeepAlive === 'undefined' || ifKeepAlive === false) {
- delete this.callbacks[callbackId]
- }
- if (typeof callback === 'function') {
- return callback(decodePrimitive(data))
- }
- return new Error(`invalid callback id "${callbackId}"`)
- }
- close () {
- this.callbacks = {}
- this.hooks = {}
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/51dd277e/html5/runtime/bridge/Handler.js
----------------------------------------------------------------------
diff --git a/html5/runtime/bridge/Handler.js b/html5/runtime/bridge/Handler.js
deleted file mode 100644
index 71bf4c5..0000000
--- a/html5/runtime/bridge/Handler.js
+++ /dev/null
@@ -1,91 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-/**
- * @fileOverview
- * Task handler for communication between javascript and native.
- */
-
-const handlerMap = {
- createBody: 'callCreateBody',
- addElement: 'callAddElement',
- removeElement: 'callRemoveElement',
- moveElement: 'callMoveElement',
- updateAttrs: 'callUpdateAttrs',
- updateStyle: 'callUpdateStyle',
- addEvent: 'callAddEvent',
- removeEvent: 'callRemoveEvent'
-}
-
-/**
- * Create a task handler.
- * @param {string} id
- * @param {function} handler
- * @return {function} taskHandler
- */
-export function createHandler (id, handler) {
- const defaultHandler = handler || global.callNative
-
- /* istanbul ignore if */
- if (typeof defaultHandler !== 'function') {
- console.error('[JS Runtime] no default handler')
- }
-
- return function taskHandler (tasks) {
- /* istanbul ignore if */
- if (!Array.isArray(tasks)) {
- tasks = [tasks]
- }
- for (let i = 0; i < tasks.length; i++) {
- const returnValue = dispatchTask(id, tasks[i], defaultHandler)
- if (returnValue === -1) {
- return returnValue
- }
- }
- }
-}
-
-/**
- * Check if there is a corresponding available handler in the environment.
- * @param {string} module
- * @param {string} method
- * @return {boolean}
- */
-function hasAvailableHandler (module, method) {
- return module === 'dom'
- && handlerMap[method]
- && typeof global[handlerMap[method]] === 'function'
-}
-
-/**
- * Dispatch the task to the specified handler.
- * @param {string} id
- * @param {object} task
- * @param {function} defaultHandler
- * @return {number} signal returned from native
- */
-function dispatchTask (id, task, defaultHandler) {
- const { module, method, args } = task
-
- if (hasAvailableHandler(module, method)) {
- return global[handlerMap[method]](id, ...args, '-1')
- }
-
- return defaultHandler(id, [task], '-1')
-}
http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/51dd277e/html5/runtime/bridge/Listener.js
----------------------------------------------------------------------
diff --git a/html5/runtime/bridge/Listener.js b/html5/runtime/bridge/Listener.js
deleted file mode 100644
index 2bf3893..0000000
--- a/html5/runtime/bridge/Listener.js
+++ /dev/null
@@ -1,220 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-/**
-* Create the action object.
-* @param {string} name
-* @param {array} arguments
-* @return {object} action
-*/
-function createAction (name, args = []) {
- return { module: 'dom', method: name, args: args }
-}
-
-export default class Listener {
- constructor (id, handler) {
- this.id = id
- this.batched = false
- this.updates = []
- if (typeof handler === 'function') {
- Object.defineProperty(this, 'handler', {
- configurable: true,
- enumerable: true,
- writable: true,
- value: handler
- })
- }
- else {
- console.error('[JS Runtime] invalid parameter, handler must be a function')
- }
- }
-
- /**
- * Send the "createFinish" signal.
- * @param {function} callback
- * @return {undefined | number} the signal sent by native
- */
- createFinish (callback) {
- const handler = this.handler
- return handler([createAction('createFinish')], callback)
- }
-
- /**
- * Send the "updateFinish" signal.
- * @param {function} callback
- * @return {undefined | number} the signal sent by native
- */
- updateFinish (callback) {
- const handler = this.handler
- return handler([createAction('updateFinish')], callback)
- }
-
- /**
- * Send the "refreshFinish" signal.
- * @param {function} callback
- * @return {undefined | number} the signal sent by native
- */
- refreshFinish (callback) {
- const handler = this.handler
- return handler([createAction('refreshFinish')], callback)
- }
-
- /**
- * Send the "createBody" signal.
- * @param {object} element
- * @return {undefined | number} the signal sent by native
- */
- createBody (element) {
- const body = element.toJSON()
- const children = body.children
- delete body.children
- const actions = [createAction('createBody', [body])]
- if (children) {
- actions.push.apply(actions, children.map(child => {
- return createAction('addElement', [body.ref, child, -1])
- }))
- }
- return this.addActions(actions)
- }
-
- /**
- * Send the "addElement" signal.
- * @param {object} element
- * @param {stirng} reference id
- * @param {number} index
- * @return {undefined | number} the signal sent by native
- */
- addElement (element, ref, index) {
- if (!(index >= 0)) {
- index = -1
- }
- return this.addActions(createAction('addElement', [ref, element.toJSON(), index]))
- }
-
- /**
- * Send the "removeElement" signal.
- * @param {stirng} reference id
- * @return {undefined | number} the signal sent by native
- */
- removeElement (ref) {
- if (Array.isArray(ref)) {
- const actions = ref.map((r) => createAction('removeElement', [r]))
- return this.addActions(actions)
- }
- return this.addActions(createAction('removeElement', [ref]))
- }
-
- /**
- * Send the "moveElement" signal.
- * @param {stirng} target reference id
- * @param {stirng} parent reference id
- * @param {number} index
- * @return {undefined | number} the signal sent by native
- */
- moveElement (targetRef, parentRef, index) {
- return this.addActions(createAction('moveElement', [targetRef, parentRef, index]))
- }
-
- /**
- * Send the "updateAttrs" signal.
- * @param {stirng} reference id
- * @param {stirng} key
- * @param {stirng} value
- * @return {undefined | number} the signal sent by native
- */
- setAttr (ref, key, value) {
- const result = {}
- result[key] = value
- return this.addActions(createAction('updateAttrs', [ref, result]))
- }
-
- /**
- * Send the "updateStyle" signal, update a sole style.
- * @param {stirng} reference id
- * @param {stirng} key
- * @param {stirng} value
- * @return {undefined | number} the signal sent by native
- */
- setStyle (ref, key, value) {
- const result = {}
- result[key] = value
- return this.addActions(createAction('updateStyle', [ref, result]))
- }
-
- /**
- * Send the "updateStyle" signal.
- * @param {stirng} reference id
- * @param {object} style
- * @return {undefined | number} the signal sent by native
- */
- setStyles (ref, style) {
- return this.addActions(createAction('updateStyle', [ref, style]))
- }
-
- /**
- * Send the "addEvent" signal.
- * @param {stirng} reference id
- * @param {string} event type
- * @return {undefined | number} the signal sent by native
- */
- addEvent (ref, type) {
- return this.addActions(createAction('addEvent', [ref, type]))
- }
-
- /**
- * Send the "removeEvent" signal.
- * @param {stirng} reference id
- * @param {string} event type
- * @return {undefined | number} the signal sent by native
- */
- removeEvent (ref, type) {
- return this.addActions(createAction('removeEvent', [ref, type]))
- }
-
- /**
- * Default handler.
- * @param {object | array} actions
- * @param {function} callback
- * @return {} anything returned by callback function
- */
- handler (actions, cb) {
- return cb && cb()
- }
-
- /**
- * Add actions into updates.
- * @param {object | array} actions
- * @return {undefined | number} the signal sent by native
- */
- addActions (actions) {
- const updates = this.updates
- const handler = this.handler
-
- if (!Array.isArray(actions)) {
- actions = [actions]
- }
-
- if (this.batched) {
- updates.push.apply(updates, actions)
- }
- else {
- return handler(actions)
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/51dd277e/html5/runtime/bridge/TaskCenter.js
----------------------------------------------------------------------
diff --git a/html5/runtime/bridge/TaskCenter.js b/html5/runtime/bridge/TaskCenter.js
deleted file mode 100644
index defee6f..0000000
--- a/html5/runtime/bridge/TaskCenter.js
+++ /dev/null
@@ -1,145 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-import CallbackManager from './CallbackManager'
-import Element from '../vdom/Element'
-import { typof } from '../utils'
-import { normalizePrimitive } from './normalize'
-
-let fallback = function () {}
-
-// The API of TaskCenter would be re-design.
-export class TaskCenter {
- constructor (id, sendTasks) {
- Object.defineProperty(this, 'instanceId', {
- enumerable: true,
- value: String(id)
- })
- Object.defineProperty(this, 'callbackManager', {
- enumerable: true,
- value: new CallbackManager(id)
- })
- fallback = sendTasks || function () {}
- }
-
- callback (callbackId, data, ifKeepAlive) {
- return this.callbackManager.consume(callbackId, data, ifKeepAlive)
- }
-
- registerHook (...args) {
- return this.callbackManager.registerHook(...args)
- }
-
- triggerHook (...args) {
- return this.callbackManager.triggerHook(...args)
- }
-
- updateData (componentId, newData, callback) {
- this.send('module', {
- module: 'dom',
- method: 'updateComponentData'
- }, [componentId, newData, callback])
- }
-
- destroyCallback () {
- return this.callbackManager.close()
- }
-
- /**
- * Normalize a value. Specially, if the value is a function, then generate a function id
- * and save it to `CallbackManager`, at last return the function id.
- * @param {any} v
- * @return {primitive}
- */
- normalize (v) {
- const type = typof(v)
- if (v && v instanceof Element) {
- return v.ref
- }
- if (v && v._isVue && v.$el instanceof Element) {
- return v.$el.ref
- }
- if (type === 'Function') {
- return this.callbackManager.add(v).toString()
- }
- return normalizePrimitive(v)
- }
-
- send (type, params, args, options) {
- const { action, component, ref, module, method } = params
-
- args = args.map(arg => this.normalize(arg))
-
- switch (type) {
- case 'dom':
- return this[action](this.instanceId, args)
- case 'component':
- return this.componentHandler(this.instanceId, ref, method, args, Object.assign({ component }, options))
- default:
- return this.moduleHandler(this.instanceId, module, method, args, options)
- }
- }
-
- callDOM (action, args) {
- return this[action](this.instanceId, args)
- }
-
- callComponent (ref, method, args, options) {
- return this.componentHandler(this.instanceId, ref, method, args, options)
- }
-
- callModule (module, method, args, options) {
- return this.moduleHandler(this.instanceId, module, method, args, options)
- }
-}
-
-export function init () {
- const DOM_METHODS = {
- createFinish: global.callCreateFinish,
- updateFinish: global.callUpdateFinish,
- refreshFinish: global.callRefreshFinish,
-
- createBody: global.callCreateBody,
-
- addElement: global.callAddElement,
- removeElement: global.callRemoveElement,
- moveElement: global.callMoveElement,
- updateAttrs: global.callUpdateAttrs,
- updateStyle: global.callUpdateStyle,
-
- addEvent: global.callAddEvent,
- removeEvent: global.callRemoveEvent
- }
- const proto = TaskCenter.prototype
-
- for (const name in DOM_METHODS) {
- const method = DOM_METHODS[name]
- proto[name] = method ?
- (id, args) => method(id, ...args) :
- (id, args) => fallback(id, [{ module: 'dom', method: name, args }], '-1')
- }
-
- proto.componentHandler = global.callNativeComponent ||
- ((id, ref, method, args, options) =>
- fallback(id, [{ component: options.component, ref, method, args }]))
-
- proto.moduleHandler = global.callNativeModule ||
- ((id, module, method, args) =>
- fallback(id, [{ module, method, args }]))
-}
http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/51dd277e/html5/runtime/bridge/debug.js
----------------------------------------------------------------------
diff --git a/html5/runtime/bridge/debug.js b/html5/runtime/bridge/debug.js
deleted file mode 100644
index 6e24c6a..0000000
--- a/html5/runtime/bridge/debug.js
+++ /dev/null
@@ -1,65 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-import { getTaskCenter } from '../vdom/operation'
-import { isRegisteredModule } from '../api/module'
-
-export function track (id, type, value) {
- const taskCenter = getTaskCenter(id)
- if (!taskCenter || typeof taskCenter.send !== 'function') {
- console.error(`[JS Framework] Failed to create tracker!`)
- return
- }
- if (!type || !value) {
- console.warn(`[JS Framework] Invalid track type (${type}) or value (${value})`)
- return
- }
- const label = `jsfm.${type}.${value}`
- try {
- if (isRegisteredModule('userTrack', 'addPerfPoint')) {
- const message = Object.create(null)
- message[label] = '4'
- taskCenter.send('module', {
- module: 'userTrack',
- method: 'addPerfPoint'
- }, [message])
- }
- }
- catch (err) {
- console.error(`[JS Framework] Failed to trace "${label}"!`)
- }
-}
-
-export function error (...messages) {
- if (typeof console.error === 'function') {
- console.error(`[JS Framework] `, ...messages)
- }
-}
-
-export function handleException (err) {
- if (typeof console.error === 'function') {
- try {
- console.error(err.toString())
- }
- catch (e) {}
- }
- if (process.env.NODE_ENV !== 'production') {
- throw err
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/51dd277e/html5/runtime/bridge/normalize.js
----------------------------------------------------------------------
diff --git a/html5/runtime/bridge/normalize.js b/html5/runtime/bridge/normalize.js
deleted file mode 100644
index d7f2450..0000000
--- a/html5/runtime/bridge/normalize.js
+++ /dev/null
@@ -1,91 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-import { typof, bufferToBase64, base64ToBuffer } from '../utils'
-
-/**
- * Normalize a primitive value.
- * @param {any} v
- * @return {primitive}
- */
-export function normalizePrimitive (v) {
- const type = typof(v)
-
- switch (type) {
- case 'Undefined':
- case 'Null':
- return ''
-
- case 'RegExp':
- return v.toString()
- case 'Date':
- return v.toISOString()
-
- case 'Number':
- case 'String':
- case 'Boolean':
- case 'Array':
- case 'Object':
- return v
-
- case 'ArrayBuffer':
- return {
- '@type': 'binary',
- dataType: type,
- base64: bufferToBase64(v)
- }
-
- case 'Int8Array':
- case 'Uint8Array':
- case 'Uint8ClampedArray':
- case 'Int16Array':
- case 'Uint16Array':
- case 'Int32Array':
- case 'Uint32Array':
- case 'Float32Array':
- case 'Float64Array':
- return {
- '@type': 'binary',
- dataType: type,
- base64: bufferToBase64(v.buffer)
- }
-
- default:
- return JSON.stringify(v)
- }
-}
-
-export function decodePrimitive (data) {
- if (typof(data) === 'Object') {
- // decode base64 into binary
- if (data['@type'] && data['@type'] === 'binary') {
- return base64ToBuffer(data.base64 || '')
- }
-
- const realData = {}
- for (const key in data) {
- realData[key] = decodePrimitive(data[key])
- }
- return realData
- }
- if (typof(data) === 'Array') {
- return data.map(decodePrimitive)
- }
- return data
-}
http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/51dd277e/html5/runtime/bridge/receiver.js
----------------------------------------------------------------------
diff --git a/html5/runtime/bridge/receiver.js b/html5/runtime/bridge/receiver.js
deleted file mode 100644
index e6dea06..0000000
--- a/html5/runtime/bridge/receiver.js
+++ /dev/null
@@ -1,71 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-import { getDoc } from '../vdom/operation'
-
-function fireEvent (document, nodeId, type, event, domChanges, params) {
- const el = document.getRef(nodeId)
- if (el) {
- return document.fireEvent(el, type, event, domChanges, params)
- }
- return new Error(`invalid element reference "${nodeId}"`)
-}
-
-function callback (document, callbackId, data, ifKeepAlive) {
- return document.taskCenter.callback(callbackId, data, ifKeepAlive)
-}
-
-function componentHook (document, componentId, type, hook, options) {
- if (!document || !document.taskCenter) {
- console.error(`[JS Framework] Can't find "document" or "taskCenter".`)
- return null
- }
- let result = null
- try {
- result = document.taskCenter.triggerHook(componentId, type, hook, options)
- }
- catch (e) {
- console.error(`[JS Framework] Failed to trigger the "${type}@${hook}" hook on ${componentId}.`)
- }
- return result
-}
-
-/**
- * Accept calls from native (event or callback).
- *
- * @param {string} id
- * @param {array} tasks list with `method` and `args`
- */
-export function receiveTasks (id, tasks) {
- const document = getDoc(id)
- if (!document) {
- return new Error(`[JS Framework] Failed to receiveTasks, `
- + `instance (${id}) is not available.`)
- }
- if (Array.isArray(tasks)) {
- return tasks.map(task => {
- switch (task.method) {
- case 'callback': return callback(document, ...task.args)
- case 'fireEventSync':
- case 'fireEvent': return fireEvent(document, ...task.args)
- case 'componentHook': return componentHook(document, ...task.args)
- }
- })
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/51dd277e/html5/runtime/index.js
----------------------------------------------------------------------
diff --git a/html5/runtime/index.js b/html5/runtime/index.js
deleted file mode 100644
index 90c425e..0000000
--- a/html5/runtime/index.js
+++ /dev/null
@@ -1,55 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-/**
- * @fileOverview
- * Register framework(s) in JS runtime. Weex supply two layers for 3rd-party
- * framework(s): one is the instance management layer, another is the
- * virtual-DOM layer.
- */
-
-import * as shared from '../shared'
-
-import init from './api/init'
-import config from './api/config'
-import { register, unregister, has } from './api/service'
-
-/* istanbul ignore next */
-function freezePrototype () {
- shared.freezePrototype()
-
- // Object.freeze(config.Element)
- Object.freeze(config.Comment)
- Object.freeze(config.Listener)
- Object.freeze(config.Document.prototype)
- // Object.freeze(config.Element.prototype)
- Object.freeze(config.Comment.prototype)
- Object.freeze(config.Listener.prototype)
-}
-
-export default {
- setNativeConsole: shared.setNativeConsole,
- resetNativeConsole: shared.resetNativeConsole,
- setNativeTimer: shared.setNativeTimer,
- resetNativeTimer: shared.resetNativeTimer,
- service: { register, unregister, has },
- freezePrototype,
- init,
- config
-}
http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/51dd277e/html5/runtime/utils.js
----------------------------------------------------------------------
diff --git a/html5/runtime/utils.js b/html5/runtime/utils.js
deleted file mode 100644
index c2ab10f..0000000
--- a/html5/runtime/utils.js
+++ /dev/null
@@ -1,71 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-/**
- * Get a unique id.
- */
-let nextNodeRef = 1
-export function uniqueId () {
- return (nextNodeRef++).toString()
-}
-
-export function typof (v) {
- const s = Object.prototype.toString.call(v)
- return s.substring(8, s.length - 1)
-}
-
-export function bufferToBase64 (buffer) {
- if (typeof btoa !== 'function') {
- return ''
- }
- const string = Array.prototype.map.call(
- new Uint8Array(buffer),
- code => String.fromCharCode(code)
- ).join('')
- return btoa(string) // eslint-disable-line no-undef
-}
-
-export function base64ToBuffer (base64) {
- if (typeof atob !== 'function') {
- return new ArrayBuffer(0)
- }
- const string = atob(base64) // eslint-disable-line no-undef
- const array = new Uint8Array(string.length)
- Array.prototype.forEach.call(string, (ch, i) => {
- array[i] = ch.charCodeAt(0)
- })
- return array.buffer
-}
-
-/**
- * Detect if the param is falsy or empty
- * @param {any} any
- */
-export function isEmpty (any) {
- if (!any || typeof any !== 'object') {
- return true
- }
-
- for (const key in any) {
- if (Object.prototype.hasOwnProperty.call(any, key)) {
- return false
- }
- }
- return true
-}
http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/51dd277e/html5/runtime/vdom/Comment.js
----------------------------------------------------------------------
diff --git a/html5/runtime/vdom/Comment.js b/html5/runtime/vdom/Comment.js
deleted file mode 100644
index d7ab115..0000000
--- a/html5/runtime/vdom/Comment.js
+++ /dev/null
@@ -1,43 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-import Node from './Node'
-import { uniqueId } from '../utils'
-
-export default class Comment extends Node {
- constructor (value) {
- super()
-
- this.nodeType = 8
- this.nodeId = uniqueId()
- this.ref = this.nodeId
- this.type = 'comment'
- this.value = value
- this.children = []
- this.pureChildren = []
- }
-
- /**
- * Convert to HTML comment string.
- * @return {stirng} html
- */
- toString () {
- return '<!-- ' + this.value + ' -->'
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/51dd277e/html5/runtime/vdom/Document.js
----------------------------------------------------------------------
diff --git a/html5/runtime/vdom/Document.js b/html5/runtime/vdom/Document.js
deleted file mode 100644
index c64fba5..0000000
--- a/html5/runtime/vdom/Document.js
+++ /dev/null
@@ -1,189 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-import Comment from './Comment'
-import Element from './Element'
-import Listener from '../bridge/Listener'
-import { TaskCenter } from '../bridge/TaskCenter'
-import { createHandler } from '../bridge/Handler'
-import { addDoc, removeDoc, appendBody, setBody } from './operation'
-
-/**
- * Update all changes for an element.
- * @param {object} element
- * @param {object} changes
- */
-function updateElement (el, changes) {
- const attrs = changes.attrs || {}
- for (const name in attrs) {
- el.setAttr(name, attrs[name], true)
- }
- const style = changes.style || {}
- for (const name in style) {
- el.setStyle(name, style[name], true)
- }
-}
-
-export default class Document {
- constructor (id, url, handler) {
- id = id ? id.toString() : ''
- this.id = id
- this.URL = url
-
- addDoc(id, this)
- this.nodeMap = {}
- const L = Document.Listener || Listener
- this.listener = new L(id, handler || createHandler(id, Document.handler)) // deprecated
- this.taskCenter = new TaskCenter(id, handler ? (id, ...args) => handler(...args) : Document.handler)
- this.createDocumentElement()
- }
-
- /**
- * Get the node from nodeMap.
- * @param {string} reference id
- * @return {object} node
- */
- getRef (ref) {
- return this.nodeMap[ref]
- }
-
- /**
- * Turn on batched updates.
- */
- open () {
- this.listener.batched = false
- }
-
- /**
- * Turn off batched updates.
- */
- close () {
- this.listener.batched = true
- }
-
- /**
- * Create the document element.
- * @return {object} documentElement
- */
- createDocumentElement () {
- if (!this.documentElement) {
- const el = new Element('document')
- el.docId = this.id
- el.ownerDocument = this
- el.role = 'documentElement'
- el.depth = 0
- el.ref = '_documentElement'
- this.nodeMap._documentElement = el
- this.documentElement = el
-
- Object.defineProperty(el, 'appendChild', {
- configurable: true,
- enumerable: true,
- writable: true,
- value: (node) => {
- appendBody(this, node)
- }
- })
-
- Object.defineProperty(el, 'insertBefore', {
- configurable: true,
- enumerable: true,
- writable: true,
- value: (node, before) => {
- appendBody(this, node, before)
- }
- })
- }
-
- return this.documentElement
- }
-
- /**
- * Create the body element.
- * @param {string} type
- * @param {objct} props
- * @return {object} body element
- */
- createBody (type, props) {
- if (!this.body) {
- const el = new Element(type, props)
- setBody(this, el)
- }
-
- return this.body
- }
-
- /**
- * Create an element.
- * @param {string} tagName
- * @param {objct} props
- * @return {object} element
- */
- createElement (tagName, props) {
- return new Element(tagName, props)
- }
-
- /**
- * Create an comment.
- * @param {string} text
- * @return {object} comment
- */
- createComment (text) {
- return new Comment(text)
- }
-
- /**
- * Fire an event on specified element manually.
- * @param {object} element
- * @param {string} event type
- * @param {object} event object
- * @param {object} dom changes
- * @param {object} options
- * @return {} anything returned by handler function
- */
- fireEvent (el, type, event, domChanges, options) {
- if (!el) {
- return
- }
- event = event || {}
- event.type = event.type || type
- event.target = el
- event.currentTarget = el
- event.timestamp = Date.now()
- if (domChanges) {
- updateElement(el, domChanges)
- }
- const isBubble = this.getRef('_root').attr['bubble'] === 'true'
- return el.fireEvent(type, event, isBubble, options)
- }
-
- /**
- * Destroy current document, and remove itself form docMap.
- */
- destroy () {
- this.taskCenter.destroyCallback()
- delete this.listener
- delete this.nodeMap
- delete this.taskCenter
- removeDoc(this.id)
- }
-}
-
-// default task handler
-Document.handler = null
http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/51dd277e/html5/runtime/vdom/Element.js
----------------------------------------------------------------------
diff --git a/html5/runtime/vdom/Element.js b/html5/runtime/vdom/Element.js
deleted file mode 100644
index 5ba05ba..0000000
--- a/html5/runtime/vdom/Element.js
+++ /dev/null
@@ -1,524 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-import Node from './Node'
-import {
- getDoc,
- getTaskCenter,
- linkParent,
- nextElement,
- previousElement,
- insertIndex,
- moveIndex,
- removeIndex
-} from './operation'
-import { uniqueId, isEmpty } from '../utils'
-import { getWeexElement, setElement } from './WeexElement'
-
-const DEFAULT_TAG_NAME = 'div'
-const BUBBLE_EVENTS = [
- 'click', 'longpress', 'touchstart', 'touchmove', 'touchend',
- 'panstart', 'panmove', 'panend', 'horizontalpan', 'verticalpan', 'swipe'
-]
-
-function registerNode (docId, node) {
- const doc = getDoc(docId)
- doc.nodeMap[node.nodeId] = node
-}
-
-export default class Element extends Node {
- constructor (type = DEFAULT_TAG_NAME, props, isExtended) {
- super()
-
- const WeexElement = getWeexElement(type)
- if (WeexElement && !isExtended) {
- return new WeexElement(type, props, true)
- }
-
- props = props || {}
- this.nodeType = 1
- this.nodeId = uniqueId()
- this.ref = this.nodeId
- this.type = type
- this.attr = props.attr || {}
- this.style = props.style || {}
- this.classStyle = props.classStyle || {}
- this.event = {}
- this.children = []
- this.pureChildren = []
- }
-
- /**
- * Append a child node.
- * @param {object} node
- * @return {undefined | number} the signal sent by native
- */
- appendChild (node) {
- if (node.parentNode && node.parentNode !== this) {
- return
- }
- /* istanbul ignore else */
- if (!node.parentNode) {
- linkParent(node, this)
- insertIndex(node, this.children, this.children.length, true)
- if (this.docId) {
- registerNode(this.docId, node)
- }
- if (node.nodeType === 1) {
- insertIndex(node, this.pureChildren, this.pureChildren.length)
- const taskCenter = getTaskCenter(this.docId)
- if (taskCenter) {
- return taskCenter.send(
- 'dom',
- { action: 'addElement' },
- [this.ref, node.toJSON(), -1]
- )
- }
- }
- }
- else {
- moveIndex(node, this.children, this.children.length, true)
- if (node.nodeType === 1) {
- const index = moveIndex(node, this.pureChildren, this.pureChildren.length)
- const taskCenter = getTaskCenter(this.docId)
- if (taskCenter && index >= 0) {
- return taskCenter.send(
- 'dom',
- { action: 'moveElement' },
- [node.ref, this.ref, index]
- )
- }
- }
- }
- }
-
- /**
- * Insert a node before specified node.
- * @param {object} node
- * @param {object} before
- * @return {undefined | number} the signal sent by native
- */
- insertBefore (node, before) {
- if (node.parentNode && node.parentNode !== this) {
- return
- }
- if (node === before || (node.nextSibling && node.nextSibling === before)) {
- return
- }
- if (!node.parentNode) {
- linkParent(node, this)
- insertIndex(node, this.children, this.children.indexOf(before), true)
- if (this.docId) {
- registerNode(this.docId, node)
- }
- if (node.nodeType === 1) {
- const pureBefore = nextElement(before)
- const index = insertIndex(
- node,
- this.pureChildren,
- pureBefore
- ? this.pureChildren.indexOf(pureBefore)
- : this.pureChildren.length
- )
- const taskCenter = getTaskCenter(this.docId)
- if (taskCenter) {
- return taskCenter.send(
- 'dom',
- { action: 'addElement' },
- [this.ref, node.toJSON(), index]
- )
- }
- }
- }
- else {
- moveIndex(node, this.children, this.children.indexOf(before), true)
- if (node.nodeType === 1) {
- const pureBefore = nextElement(before)
- /* istanbul ignore next */
- const index = moveIndex(
- node,
- this.pureChildren,
- pureBefore
- ? this.pureChildren.indexOf(pureBefore)
- : this.pureChildren.length
- )
- const taskCenter = getTaskCenter(this.docId)
- if (taskCenter && index >= 0) {
- return taskCenter.send(
- 'dom',
- { action: 'moveElement' },
- [node.ref, this.ref, index]
- )
- }
- }
- }
- }
-
- /**
- * Insert a node after specified node.
- * @param {object} node
- * @param {object} after
- * @return {undefined | number} the signal sent by native
- */
- insertAfter (node, after) {
- if (node.parentNode && node.parentNode !== this) {
- return
- }
- if (node === after || (node.previousSibling && node.previousSibling === after)) {
- return
- }
- if (!node.parentNode) {
- linkParent(node, this)
- insertIndex(node, this.children, this.children.indexOf(after) + 1, true)
- /* istanbul ignore else */
- if (this.docId) {
- registerNode(this.docId, node)
- }
- if (node.nodeType === 1) {
- const index = insertIndex(
- node,
- this.pureChildren,
- this.pureChildren.indexOf(previousElement(after)) + 1
- )
- const taskCenter = getTaskCenter(this.docId)
- /* istanbul ignore else */
- if (taskCenter) {
- return taskCenter.send(
- 'dom',
- { action: 'addElement' },
- [this.ref, node.toJSON(), index]
- )
- }
- }
- }
- else {
- moveIndex(node, this.children, this.children.indexOf(after) + 1, true)
- if (node.nodeType === 1) {
- const index = moveIndex(
- node,
- this.pureChildren,
- this.pureChildren.indexOf(previousElement(after)) + 1
- )
- const taskCenter = getTaskCenter(this.docId)
- if (taskCenter && index >= 0) {
- return taskCenter.send(
- 'dom',
- { action: 'moveElement' },
- [node.ref, this.ref, index]
- )
- }
- }
- }
- }
-
- /**
- * Remove a child node, and decide whether it should be destroyed.
- * @param {object} node
- * @param {boolean} preserved
- */
- removeChild (node, preserved) {
- if (node.parentNode) {
- removeIndex(node, this.children, true)
- if (node.nodeType === 1) {
- removeIndex(node, this.pureChildren)
- const taskCenter = getTaskCenter(this.docId)
- if (taskCenter) {
- taskCenter.send(
- 'dom',
- { action: 'removeElement' },
- [node.ref]
- )
- }
- }
- }
- if (!preserved) {
- node.destroy()
- }
- }
-
- /**
- * Clear all child nodes.
- */
- clear () {
- const taskCenter = getTaskCenter(this.docId)
- /* istanbul ignore else */
- if (taskCenter) {
- this.pureChildren.forEach(node => {
- taskCenter.send(
- 'dom',
- { action: 'removeElement' },
- [node.ref]
- )
- })
- }
- this.children.forEach(node => {
- node.destroy()
- })
- this.children.length = 0
- this.pureChildren.length = 0
- }
-
- /**
- * Set an attribute, and decide whether the task should be send to native.
- * @param {string} key
- * @param {string | number} value
- * @param {boolean} silent
- */
- setAttr (key, value, silent) {
- if (this.attr[key] === value && silent !== false) {
- return
- }
- this.attr[key] = value
- const taskCenter = getTaskCenter(this.docId)
- if (!silent && taskCenter) {
- const result = {}
- result[key] = value
- taskCenter.send(
- 'dom',
- { action: 'updateAttrs' },
- [this.ref, result]
- )
- }
- }
-
- /**
- * Set batched attributes.
- * @param {object} batchedAttrs
- * @param {boolean} silent
- */
- setAttrs (batchedAttrs, silent) {
- if (isEmpty(batchedAttrs)) return
- const mutations = {}
- for (const key in batchedAttrs) {
- if (this.attr[key] !== batchedAttrs[key]) {
- this.attr[key] = batchedAttrs[key]
- mutations[key] = batchedAttrs[key]
- }
- }
- if (!isEmpty(mutations)) {
- const taskCenter = getTaskCenter(this.docId)
- if (!silent && taskCenter) {
- taskCenter.send(
- 'dom',
- { action: 'updateAttrs' },
- [this.ref, mutations]
- )
- }
- }
- }
-
- /**
- * Set a style property, and decide whether the task should be send to native.
- * @param {string} key
- * @param {string | number} value
- * @param {boolean} silent
- */
- setStyle (key, value, silent) {
- if (this.style[key] === value && silent !== false) {
- return
- }
- this.style[key] = value
- const taskCenter = getTaskCenter(this.docId)
- if (!silent && taskCenter) {
- const result = {}
- result[key] = value
- taskCenter.send(
- 'dom',
- { action: 'updateStyle' },
- [this.ref, result]
- )
- }
- }
-
- /**
- * Set batched style properties.
- * @param {object} batchedStyles
- * @param {boolean} silent
- */
- setStyles (batchedStyles, silent) {
- if (isEmpty(batchedStyles)) return
- const mutations = {}
- for (const key in batchedStyles) {
- if (this.style[key] !== batchedStyles[key]) {
- this.style[key] = batchedStyles[key]
- mutations[key] = batchedStyles[key]
- }
- }
- if (!isEmpty(mutations)) {
- const taskCenter = getTaskCenter(this.docId)
- if (!silent && taskCenter) {
- taskCenter.send(
- 'dom',
- { action: 'updateStyle' },
- [this.ref, mutations]
- )
- }
- }
- }
-
- /**
- * Set style properties from class.
- * @param {object} classStyle
- */
- setClassStyle (classStyle) {
- // reset previous class style to empty string
- for (const key in this.classStyle) {
- this.classStyle[key] = ''
- }
-
- Object.assign(this.classStyle, classStyle)
- const taskCenter = getTaskCenter(this.docId)
- if (taskCenter) {
- taskCenter.send(
- 'dom',
- { action: 'updateStyle' },
- [this.ref, this.toStyle()]
- )
- }
- }
-
- /**
- * Add an event handler.
- * @param {string} event type
- * @param {function} event handler
- */
- addEvent (type, handler, params) {
- if (!this.event) {
- this.event = {}
- }
- if (!this.event[type]) {
- this.event[type] = { handler, params }
- const taskCenter = getTaskCenter(this.docId)
- if (taskCenter) {
- taskCenter.send(
- 'dom',
- { action: 'addEvent' },
- [this.ref, type]
- )
- }
- }
- }
-
- /**
- * Remove an event handler.
- * @param {string} event type
- */
- removeEvent (type) {
- if (this.event && this.event[type]) {
- delete this.event[type]
- const taskCenter = getTaskCenter(this.docId)
- if (taskCenter) {
- taskCenter.send(
- 'dom',
- { action: 'removeEvent' },
- [this.ref, type]
- )
- }
- }
- }
-
- /**
- * Fire an event manually.
- * @param {string} type type
- * @param {function} event handler
- * @param {boolean} isBubble whether or not event bubble
- * @param {boolean} options
- * @return {} anything returned by handler function
- */
- fireEvent (type, event, isBubble, options) {
- let result = null
- let isStopPropagation = false
- const eventDesc = this.event[type]
- if (eventDesc && event) {
- const handler = eventDesc.handler
- event.stopPropagation = () => {
- isStopPropagation = true
- }
- if (options && options.params) {
- result = handler.call(this, ...options.params, event)
- }
- else {
- result = handler.call(this, event)
- }
- }
-
- if (!isStopPropagation
- && isBubble
- && (BUBBLE_EVENTS.indexOf(type) !== -1)
- && this.parentNode
- && this.parentNode.fireEvent) {
- event.currentTarget = this.parentNode
- this.parentNode.fireEvent(type, event, isBubble) // no options
- }
-
- return result
- }
-
- /**
- * Get all styles of current element.
- * @return {object} style
- */
- toStyle () {
- return Object.assign({}, this.classStyle, this.style)
- }
-
- /**
- * Convert current element to JSON like object.
- * @return {object} element
- */
- toJSON () {
- const result = {
- ref: this.ref.toString(),
- type: this.type,
- attr: this.attr,
- style: this.toStyle()
- }
- const event = []
- for (const type in this.event) {
- const { params } = this.event[type]
- if (!params) {
- event.push(type)
- }
- else {
- event.push({ type, params })
- }
- }
- if (event.length) {
- result.event = event
- }
- if (this.pureChildren.length) {
- result.children = this.pureChildren.map((child) => child.toJSON())
- }
- return result
- }
-
- /**
- * Convert to HTML element tag string.
- * @return {stirng} html
- */
- toString () {
- return '<' + this.type +
- ' attr=' + JSON.stringify(this.attr) +
- ' style=' + JSON.stringify(this.toStyle()) + '>' +
- this.pureChildren.map((child) => child.toString()).join('') +
- '</' + this.type + '>'
- }
-}
-
-setElement(Element)
http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/51dd277e/html5/runtime/vdom/Node.js
----------------------------------------------------------------------
diff --git a/html5/runtime/vdom/Node.js b/html5/runtime/vdom/Node.js
deleted file mode 100644
index 645f7df..0000000
--- a/html5/runtime/vdom/Node.js
+++ /dev/null
@@ -1,47 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-import { uniqueId } from '../utils'
-import { getDoc } from './operation'
-
-export default class Node {
- constructor () {
- this.nodeId = uniqueId()
- this.ref = this.nodeId
- this.children = []
- this.pureChildren = []
- this.parentNode = null
- this.nextSibling = null
- this.previousSibling = null
- }
-
- /**
- * Destroy current node, and remove itself form nodeMap.
- */
- destroy () {
- const doc = getDoc(this.docId)
- if (doc) {
- delete this.docId
- delete doc.nodeMap[this.nodeId]
- }
- this.children.forEach(child => {
- child.destroy()
- })
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/51dd277e/html5/runtime/vdom/WeexElement.js
----------------------------------------------------------------------
diff --git a/html5/runtime/vdom/WeexElement.js b/html5/runtime/vdom/WeexElement.js
deleted file mode 100644
index 455e69e..0000000
--- a/html5/runtime/vdom/WeexElement.js
+++ /dev/null
@@ -1,84 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-import { getTaskCenter } from './operation'
-
-let Element
-
-export function setElement (El) {
- Element = El
-}
-
-/**
- * A map which stores all type of elements.
- * @type {Object}
- */
-const registeredElements = {}
-
-/**
- * Register an extended element type with component methods.
- * @param {string} type component type
- * @param {array} methods a list of method names
- */
-export function registerElement (type, methods) {
- // Skip when no special component methods.
- if (!methods || !methods.length) {
- return
- }
-
- // Init constructor.
- class WeexElement extends Element {}
-
- // Add methods to prototype.
- methods.forEach(methodName => {
- WeexElement.prototype[methodName] = function (...args) {
- const taskCenter = getTaskCenter(this.docId)
- if (taskCenter) {
- return taskCenter.send('component', {
- ref: this.ref,
- component: type,
- method: methodName
- }, args)
- }
- }
- })
-
- // Add to element type map.
- registeredElements[type] = WeexElement
-}
-
-export function unregisterElement (type) {
- delete registeredElements[type]
-}
-
-export function getWeexElement (type) {
- return registeredElements[type]
-}
-
-export function isWeexElement (type) {
- return !!registeredElements[type]
-}
-
-/**
- * Clear all element types. Only for testing.
- */
-export function clearWeexElements () {
- for (const type in registeredElements) {
- unregisterElement(type)
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/51dd277e/html5/runtime/vdom/index.js
----------------------------------------------------------------------
diff --git a/html5/runtime/vdom/index.js b/html5/runtime/vdom/index.js
deleted file mode 100644
index 2947f5e..0000000
--- a/html5/runtime/vdom/index.js
+++ /dev/null
@@ -1,37 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-import Node from './Node'
-import Element from './Element'
-import Comment from './Comment'
-import Document from './Document'
-
-export {
- registerElement,
- unregisterElement,
- isWeexElement,
- clearWeexElements
-} from './WeexElement'
-
-export {
- Document,
- Node,
- Element,
- Comment
-}