You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@weex.apache.org by da...@apache.org on 2017/08/17 03:59:41 UTC

[24/43] incubator-weex git commit: * [jsfm] change the file name case in vdom

* [jsfm] change the file name case in vdom


Project: http://git-wip-us.apache.org/repos/asf/incubator-weex/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-weex/commit/8294acfc
Tree: http://git-wip-us.apache.org/repos/asf/incubator-weex/tree/8294acfc
Diff: http://git-wip-us.apache.org/repos/asf/incubator-weex/diff/8294acfc

Branch: refs/heads/0.16-dev
Commit: 8294acfc2c5a5268edf1bd048981a578e5a9c253
Parents: 229740a
Author: Hanks <zh...@gmail.com>
Authored: Tue Aug 8 17:11:20 2017 +0800
Committer: Hanks <zh...@gmail.com>
Committed: Tue Aug 8 17:11:20 2017 +0800

----------------------------------------------------------------------
 html5/runtime/vdom/Comment.js  |  43 ++++
 html5/runtime/vdom/Document.js | 188 +++++++++++++++
 html5/runtime/vdom/Element.js  | 454 ++++++++++++++++++++++++++++++++++++
 html5/runtime/vdom/Node.js     |  47 ++++
 html5/runtime/vdom/comment.js  |  43 ----
 html5/runtime/vdom/document.js | 188 ---------------
 html5/runtime/vdom/element.js  | 454 ------------------------------------
 html5/runtime/vdom/node.js     |  47 ----
 8 files changed, 732 insertions(+), 732 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/8294acfc/html5/runtime/vdom/Comment.js
----------------------------------------------------------------------
diff --git a/html5/runtime/vdom/Comment.js b/html5/runtime/vdom/Comment.js
new file mode 100644
index 0000000..d7ab115
--- /dev/null
+++ b/html5/runtime/vdom/Comment.js
@@ -0,0 +1,43 @@
+/*
+ * 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/8294acfc/html5/runtime/vdom/Document.js
----------------------------------------------------------------------
diff --git a/html5/runtime/vdom/Document.js b/html5/runtime/vdom/Document.js
new file mode 100644
index 0000000..58efa5d
--- /dev/null
+++ b/html5/runtime/vdom/Document.js
@@ -0,0 +1,188 @@
+/*
+ * 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
+  * @return {} anything returned by handler function
+  */
+  fireEvent (el, type, e, domChanges) {
+    if (!el) {
+      return
+    }
+    e = e || {}
+    e.type = type
+    e.target = el
+    e.currentTarget = el
+    e.timestamp = Date.now()
+    if (domChanges) {
+      updateElement(el, domChanges)
+    }
+    const isBubble = this.getRef('_root').attr['bubble'] === 'true'
+    return el.fireEvent(type, e, isBubble)
+  }
+
+  /**
+  * 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/8294acfc/html5/runtime/vdom/Element.js
----------------------------------------------------------------------
diff --git a/html5/runtime/vdom/Element.js b/html5/runtime/vdom/Element.js
new file mode 100644
index 0000000..dcb487b
--- /dev/null
+++ b/html5/runtime/vdom/Element.js
@@ -0,0 +1,454 @@
+/*
+ * 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 } from '../utils'
+import { getWeexElement, setElement } from './WeexElement'
+import { filterDirective } from './directive'
+
+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(props)
+    }
+
+    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] = filterDirective(value)
+      taskCenter.send(
+        'dom',
+        { action: 'updateAttrs' },
+        [this.ref, result]
+      )
+    }
+  }
+
+  /**
+   * 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 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) {
+    if (!this.event[type]) {
+      this.event[type] = handler
+      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[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} e handler
+   * @param {boolean} isBubble whether or not event bubble
+   * @return {} anything returned by handler function
+   */
+  fireEvent (type, e, isBubble) {
+    let result = null
+    let isStopPropagation = false
+    const handler = this.event[type]
+    if (handler && e) {
+      e.stopPropagation = () => {
+        isStopPropagation = true
+      }
+      result = handler.call(this, e)
+    }
+
+    if (!isStopPropagation
+      && isBubble
+      && BUBBLE_EVENTS.includes(type)
+      && this.parentNode
+      && this.parentNode.fireEvent) {
+      e.currentTarget = this.parentNode
+      this.parentNode.fireEvent(type, e, isBubble)
+    }
+
+    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: filterDirective(this.attr),
+      style: this.toStyle()
+    }
+    const event = Object.keys(this.event)
+    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/8294acfc/html5/runtime/vdom/Node.js
----------------------------------------------------------------------
diff --git a/html5/runtime/vdom/Node.js b/html5/runtime/vdom/Node.js
new file mode 100644
index 0000000..645f7df
--- /dev/null
+++ b/html5/runtime/vdom/Node.js
@@ -0,0 +1,47 @@
+/*
+ * 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/8294acfc/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/8294acfc/html5/runtime/vdom/document.js
----------------------------------------------------------------------
diff --git a/html5/runtime/vdom/document.js b/html5/runtime/vdom/document.js
deleted file mode 100644
index 58efa5d..0000000
--- a/html5/runtime/vdom/document.js
+++ /dev/null
@@ -1,188 +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
-  * @return {} anything returned by handler function
-  */
-  fireEvent (el, type, e, domChanges) {
-    if (!el) {
-      return
-    }
-    e = e || {}
-    e.type = type
-    e.target = el
-    e.currentTarget = el
-    e.timestamp = Date.now()
-    if (domChanges) {
-      updateElement(el, domChanges)
-    }
-    const isBubble = this.getRef('_root').attr['bubble'] === 'true'
-    return el.fireEvent(type, e, isBubble)
-  }
-
-  /**
-  * 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/8294acfc/html5/runtime/vdom/element.js
----------------------------------------------------------------------
diff --git a/html5/runtime/vdom/element.js b/html5/runtime/vdom/element.js
deleted file mode 100644
index dcb487b..0000000
--- a/html5/runtime/vdom/element.js
+++ /dev/null
@@ -1,454 +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 } from '../utils'
-import { getWeexElement, setElement } from './WeexElement'
-import { filterDirective } from './directive'
-
-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(props)
-    }
-
-    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] = filterDirective(value)
-      taskCenter.send(
-        'dom',
-        { action: 'updateAttrs' },
-        [this.ref, result]
-      )
-    }
-  }
-
-  /**
-   * 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 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) {
-    if (!this.event[type]) {
-      this.event[type] = handler
-      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[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} e handler
-   * @param {boolean} isBubble whether or not event bubble
-   * @return {} anything returned by handler function
-   */
-  fireEvent (type, e, isBubble) {
-    let result = null
-    let isStopPropagation = false
-    const handler = this.event[type]
-    if (handler && e) {
-      e.stopPropagation = () => {
-        isStopPropagation = true
-      }
-      result = handler.call(this, e)
-    }
-
-    if (!isStopPropagation
-      && isBubble
-      && BUBBLE_EVENTS.includes(type)
-      && this.parentNode
-      && this.parentNode.fireEvent) {
-      e.currentTarget = this.parentNode
-      this.parentNode.fireEvent(type, e, isBubble)
-    }
-
-    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: filterDirective(this.attr),
-      style: this.toStyle()
-    }
-    const event = Object.keys(this.event)
-    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/8294acfc/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()
-    })
-  }
-}