From 694421470be9faea4410a8f020fd5753463c6948 Mon Sep 17 00:00:00 2001 From: Patrick Steele-Idem Date: Fri, 20 Jan 2017 13:40:21 -0700 Subject: [PATCH] Internal refactoring: V prefix for VDOM nodes --- runtime/vdom/AsyncVDOMBuilder.js | 22 +++++------ runtime/vdom/{Comment.js => VComment.js} | 14 +++---- ...cumentFragment.js => VDocumentFragment.js} | 18 ++++----- runtime/vdom/{HTMLElement.js => VElement.js} | 30 +++++++-------- runtime/vdom/{Node.js => VNode.js} | 10 ++--- runtime/vdom/{Text.js => VText.js} | 14 +++---- runtime/vdom/helpers.js | 10 ++--- runtime/vdom/vdom.js | 38 +++++++++---------- test/AsyncVDOMBuilder-test.js | 6 +-- .../vdom-create/assignAttributes/index.js | 4 +- test/vdom-create-test.js | 20 +++++----- widgets/Widget.js | 2 +- 12 files changed, 94 insertions(+), 94 deletions(-) rename runtime/vdom/{Comment.js => VComment.js} (50%) rename runtime/vdom/{DocumentFragment.js => VDocumentFragment.js} (63%) rename runtime/vdom/{HTMLElement.js => VElement.js} (92%) rename runtime/vdom/{Node.js => VNode.js} (96%) rename runtime/vdom/{Text.js => VText.js} (54%) diff --git a/runtime/vdom/AsyncVDOMBuilder.js b/runtime/vdom/AsyncVDOMBuilder.js index 157bb282b..0a718d6e1 100644 --- a/runtime/vdom/AsyncVDOMBuilder.js +++ b/runtime/vdom/AsyncVDOMBuilder.js @@ -1,9 +1,9 @@ var EventEmitter = require('events-light'); var vdom = require('./vdom'); -var HTMLElement = vdom.$__HTMLElement; -var DocumentFragment = vdom.$__DocumentFragment; -var Comment = vdom.$__Comment; -var Text = vdom.$__Text; +var VElement = vdom.$__VElement; +var VDocumentFragment = vdom.$__VDocumentFragment; +var VComment = vdom.$__VComment; +var VText = vdom.$__VText; var virtualizeHTML = vdom.$__virtualizeHTML; var RenderResult = require('../RenderResult'); var defaultDocument = vdom.$__defaultDocument; @@ -25,7 +25,7 @@ function State(tree) { function AsyncVDOMBuilder(globalData, parentNode, state) { if (!parentNode) { - parentNode = new DocumentFragment(); + parentNode = new VDocumentFragment(); } if (state) { @@ -47,7 +47,7 @@ var proto = AsyncVDOMBuilder.prototype = { $__document: defaultDocument, element: function(name, attrs, childCount) { - var element = new HTMLElement(name, attrs, childCount); + var element = new VElement(name, attrs, childCount); var parent = this.$__parent; @@ -93,14 +93,14 @@ var proto = AsyncVDOMBuilder.prototype = { if (lastChild && lastChild.$__Text) { lastChild.nodeValue += text; } else { - parent.$__appendChild(new Text(text)); + parent.$__appendChild(new VText(text)); } } return this; }, comment: function(comment) { - return this.node(new Comment(comment)); + return this.node(new VComment(comment)); }, html: function(html) { @@ -113,7 +113,7 @@ var proto = AsyncVDOMBuilder.prototype = { }, beginElement: function(name, attrs) { - var element = new HTMLElement(name, attrs); + var element = new VElement(name, attrs); var parent = this.$__parent; if (parent) { parent.$__appendChild(element); @@ -274,7 +274,7 @@ var proto = AsyncVDOMBuilder.prototype = { }, $__getNode: function(doc) { - var node = this.$__node; + var node = this.$__VNode; if (!node) { var vdomTree = this.$__getOutput(); @@ -282,7 +282,7 @@ var proto = AsyncVDOMBuilder.prototype = { doc = this.$__document; } - node = this.$__node = vdomTree.actualize(doc); + node = this.$__VNode = vdomTree.actualize(doc); } return node; }, diff --git a/runtime/vdom/Comment.js b/runtime/vdom/VComment.js similarity index 50% rename from runtime/vdom/Comment.js rename to runtime/vdom/VComment.js index caf506ffc..368742f7a 100644 --- a/runtime/vdom/Comment.js +++ b/runtime/vdom/VComment.js @@ -1,12 +1,12 @@ -var Node = require('./Node'); +var VNode = require('./VNode'); var inherit = require('raptor-util/inherit'); -function Comment(value) { - this.$__Node(-1 /* no children */); +function VComment(value) { + this.$__VNode(-1 /* no children */); this.nodeValue = value; } -Comment.prototype = { +VComment.prototype = { nodeType: 8, actualize: function(doc) { @@ -14,10 +14,10 @@ Comment.prototype = { }, $__cloneNode: function() { - return new Comment(this.nodeValue); + return new VComment(this.nodeValue); } }; -inherit(Comment, Node); +inherit(VComment, VNode); -module.exports = Comment; \ No newline at end of file +module.exports = VComment; diff --git a/runtime/vdom/DocumentFragment.js b/runtime/vdom/VDocumentFragment.js similarity index 63% rename from runtime/vdom/DocumentFragment.js rename to runtime/vdom/VDocumentFragment.js index a56f79161..d12a4f741 100644 --- a/runtime/vdom/DocumentFragment.js +++ b/runtime/vdom/VDocumentFragment.js @@ -1,19 +1,19 @@ -var Node = require('./Node'); +var VNode = require('./VNode'); var inherit = require('raptor-util/inherit'); var extend = require('raptor-util/extend'); -function DocumentFragmentClone(other) { +function VDocumentFragmentClone(other) { extend(this, other); this.$__parentNode = undefined; this.$__nextSibling = undefined; } -function DocumentFragment(documentFragment) { - this.$__Node(null /* childCount */); +function VDocumentFragment(documentFragment) { + this.$__VNode(null /* childCount */); this.namespaceURI = undefined; } -DocumentFragment.prototype = { +VDocumentFragment.prototype = { nodeType: 11, $__DocumentFragment: true, @@ -21,7 +21,7 @@ DocumentFragment.prototype = { $__nsAware: true, $__cloneNode: function() { - return new DocumentFragmentClone(this); + return new VDocumentFragmentClone(this); }, actualize: function(doc) { @@ -38,8 +38,8 @@ DocumentFragment.prototype = { } }; -inherit(DocumentFragment, Node); +inherit(VDocumentFragment, VNode); -DocumentFragmentClone.prototype = DocumentFragment.prototype; +VDocumentFragmentClone.prototype = VDocumentFragment.prototype; -module.exports = DocumentFragment; \ No newline at end of file +module.exports = VDocumentFragment; diff --git a/runtime/vdom/HTMLElement.js b/runtime/vdom/VElement.js similarity index 92% rename from runtime/vdom/HTMLElement.js rename to runtime/vdom/VElement.js index de109d82f..5aea7798c 100644 --- a/runtime/vdom/HTMLElement.js +++ b/runtime/vdom/VElement.js @@ -1,4 +1,4 @@ -var Node = require('./Node'); +var VNode = require('./VNode'); var inherit = require('raptor-util/inherit'); var extend = require('raptor-util/extend'); var defineProperty = Object.defineProperty; @@ -32,13 +32,13 @@ function convertAttrValue(type, value) { } } -function HTMLElementClone(other) { +function VVElementClone(other) { extend(this, other); this.$__parentNode = undefined; this.$__nextSibling = undefined; } -function HTMLElement(tagName, attrs, childCount, constId) { +function VElement(tagName, attrs, childCount, constId) { var namespaceURI; var isTextArea; @@ -55,7 +55,7 @@ function HTMLElement(tagName, attrs, childCount, constId) { break; } - this.$__Node(childCount); + this.$__VNode(childCount); if (constId) { if (!attrs) { @@ -72,15 +72,15 @@ function HTMLElement(tagName, attrs, childCount, constId) { this.$__constId = constId; } -HTMLElement.prototype = { - $__HTMLElement: true, +VElement.prototype = { + $__VElement: true, nodeType: 1, $__nsAware: true, $__cloneNode: function() { - return new HTMLElementClone(this); + return new VVElementClone(this); }, /** @@ -91,7 +91,7 @@ HTMLElement.prototype = { * @param {int|null} childCount The number of child nodes (or `null` if not known) */ e: function(tagName, attrs, childCount, constId) { - var child = this.$__appendChild(new HTMLElement(tagName, attrs, childCount, constId)); + var child = this.$__appendChild(new VElement(tagName, attrs, childCount, constId)); if (childCount === 0) { return this.$__finishChild(); @@ -180,7 +180,7 @@ HTMLElement.prototype = { if (otherNode.nodeType == 1) { var constId = this.$__constId; if (constId) { - var otherSameId = otherNode.$__Node ? otherNode.$__constId : otherNode.getAttribute(ATTR_MARKO_CONST); + var otherSameId = otherNode.$__VNode ? otherNode.$__constId : otherNode.getAttribute(ATTR_MARKO_CONST); return constId === otherSameId; } } @@ -189,9 +189,9 @@ HTMLElement.prototype = { } }; -inherit(HTMLElement, Node); +inherit(VElement, VNode); -var proto = HTMLElementClone.prototype = HTMLElement.prototype; +var proto = VVElementClone.prototype = VElement.prototype; ['checked', 'selected', 'disabled'].forEach(function(name) { defineProperty(proto, name, { @@ -218,17 +218,17 @@ defineProperty(proto, 'value', { } }); -HTMLElement.$__morphAttrs = function(fromEl, toEl) { +VElement.$__morphAttrs = function(fromEl, toEl) { var attrs = toEl.$__attributes || toEl._vattrs; var attrName; var i; // We use expando properties to associate the previous HTML // attributes provided as part of the VDOM node with the - // real HTMLElement DOM node. When diffing attributes, + // real VElement DOM node. When diffing attributes, // we only use our internal representation of the attributes. // When diffing for the first time it's possible that the - // real HTMLElement node will not have the expando property + // real VElement node will not have the expando property // so we build the attribute map from the expando property var oldAttrs = fromEl._vattrs; @@ -321,4 +321,4 @@ HTMLElement.$__morphAttrs = function(fromEl, toEl) { fromEl._vattrs = attrs; }; -module.exports = HTMLElement; \ No newline at end of file +module.exports = VElement; diff --git a/runtime/vdom/Node.js b/runtime/vdom/VNode.js similarity index 96% rename from runtime/vdom/Node.js rename to runtime/vdom/VNode.js index be40e799c..427f3fdfe 100644 --- a/runtime/vdom/Node.js +++ b/runtime/vdom/VNode.js @@ -12,10 +12,10 @@ function assignNamespace(node, namespaceURI) { } } -function Node() {} +function VNode() {} -Node.prototype = { - $__Node: function(finalChildCount) { +VNode.prototype = { + $__VNode: function(finalChildCount) { this.$__finalChildCount = finalChildCount; this.$__childCount = 0; this.$__firstChild = undefined; @@ -64,7 +64,7 @@ Node.prototype = { $__appendChild: function(child) { this.$__childCount++; - + if (this.$__isTextArea) { if (child.$__Text) { var childValue = child.nodeValue; @@ -120,4 +120,4 @@ Node.prototype = { // } }; -module.exports = Node; \ No newline at end of file +module.exports = VNode; diff --git a/runtime/vdom/Text.js b/runtime/vdom/VText.js similarity index 54% rename from runtime/vdom/Text.js rename to runtime/vdom/VText.js index 518a5dfc8..c192c8970 100644 --- a/runtime/vdom/Text.js +++ b/runtime/vdom/VText.js @@ -1,12 +1,12 @@ -var Node = require('./Node'); +var VNode = require('./VNode'); var inherit = require('raptor-util/inherit'); -function Text(value) { - this.$__Node(-1 /* no children */); +function VText(value) { + this.$__VNode(-1 /* no children */); this.nodeValue = value; } -Text.prototype = { +VText.prototype = { $__Text: true, nodeType: 3, @@ -16,10 +16,10 @@ Text.prototype = { }, $__cloneNode: function() { - return new Text(this.nodeValue); + return new VText(this.nodeValue); } }; -inherit(Text, Node); +inherit(VText, VNode); -module.exports = Text; \ No newline at end of file +module.exports = VText; diff --git a/runtime/vdom/helpers.js b/runtime/vdom/helpers.js index b994928c9..5e3e299fd 100644 --- a/runtime/vdom/helpers.js +++ b/runtime/vdom/helpers.js @@ -1,8 +1,8 @@ 'use strict'; var vdom = require('./vdom'); -var HTMLElement = vdom.$__HTMLElement; -var Text = vdom.$__Text; +var VElement = vdom.$__VElement; +var VText = vdom.$__VText; var commonHelpers = require('../helpers'); var extend = require('raptor-util/extend'); @@ -10,11 +10,11 @@ var extend = require('raptor-util/extend'); var classList = commonHelpers.cl; exports.e = function(tagName, attrs, childCount, constId) { - return new HTMLElement(tagName, attrs, childCount, constId); + return new VElement(tagName, attrs, childCount, constId); }; exports.t = function(value) { - return new Text(value); + return new VText(value); }; exports.const = function(id) { @@ -44,4 +44,4 @@ exports.ca = function(classNames) { } }; -extend(exports, commonHelpers); \ No newline at end of file +extend(exports, commonHelpers); diff --git a/runtime/vdom/vdom.js b/runtime/vdom/vdom.js index 8a8372ee0..be0876113 100644 --- a/runtime/vdom/vdom.js +++ b/runtime/vdom/vdom.js @@ -1,8 +1,8 @@ -var Node = require('./Node'); -var Comment = require('./Comment'); -var DocumentFragment = require('./DocumentFragment'); -var HTMLElement = require('./HTMLElement'); -var Text = require('./Text'); +var VNode = require('./VNode'); +var VComment = require('./VComment'); +var VDocumentFragment = require('./VDocumentFragment'); +var VElement = require('./VElement'); +var VText = require('./VText'); var defaultDocument = typeof document != 'undefined' && document; var specialHtmlRegexp = /[&<]/; @@ -41,7 +41,7 @@ function virtualize(node) { } } - var vdomEL = new HTMLElement(node.nodeName, attrs); + var vdomEL = new VElement(node.nodeName, attrs); if (vdomEL.$__isTextArea) { vdomEL.$__value = node.value; @@ -51,11 +51,11 @@ function virtualize(node) { return vdomEL; case 3: - return new Text(node.nodeValue); + return new VText(node.nodeValue); case 8: - return new Comment(node.nodeValue); + return new VComment(node.nodeValue); case 11: - var vdomDocFragment = new DocumentFragment(); + var vdomDocFragment = new VDocumentFragment(); virtualizeChildNodes(node, vdomDocFragment); return vdomDocFragment; } @@ -63,7 +63,7 @@ function virtualize(node) { function virtualizeHTML(html, doc) { if (!specialHtmlRegexp.test(html)) { - return new Text(html); + return new VText(html); } if (!range && doc.createRange) { @@ -80,7 +80,7 @@ function virtualizeHTML(html, doc) { } else { var container = doc.createElement('body'); container.innerHTML = html; - vdomFragment = new DocumentFragment(); + vdomFragment = new VDocumentFragment(); var curChild = container.firstChild; while(curChild) { @@ -92,7 +92,7 @@ function virtualizeHTML(html, doc) { return vdomFragment; } -var Node_prototype = Node.prototype; +var Node_prototype = VNode.prototype; /** * Shorthand method for creating and appending a Text node with a given value @@ -112,7 +112,7 @@ Node_prototype.t = function(value) { } } - this.$__appendChild(vdomNode || new Text(value.toString())); + this.$__appendChild(vdomNode || new VText(value.toString())); return this.$__finishChild(); }; @@ -121,18 +121,18 @@ Node_prototype.t = function(value) { * @param {String} value The value for the new Comment node */ Node_prototype.c = function(value) { - this.$__appendChild(new Comment(value)); + this.$__appendChild(new VComment(value)); return this.$__finishChild(); }; Node_prototype.$__appendDocumentFragment = function() { - return this.$__appendChild(new DocumentFragment()); + return this.$__appendChild(new VDocumentFragment()); }; -exports.$__Comment = Comment; -exports.$__DocumentFragment = DocumentFragment; -exports.$__HTMLElement = HTMLElement; -exports.$__Text = Text; +exports.$__VComment = VComment; +exports.$__VDocumentFragment = VDocumentFragment; +exports.$__VElement = VElement; +exports.$__VText = VText; exports.$__virtualize = virtualize; exports.$__virtualizeHTML = virtualizeHTML; exports.$__defaultDocument = defaultDocument; diff --git a/test/AsyncVDOMBuilder-test.js b/test/AsyncVDOMBuilder-test.js index aad642b97..2007d2d14 100644 --- a/test/AsyncVDOMBuilder-test.js +++ b/test/AsyncVDOMBuilder-test.js @@ -1,5 +1,5 @@ var AsyncVDOMBuilder = require('../runtime/vdom/AsyncVDOMBuilder'); -var HTMLElement = require('../runtime/vdom/HTMLElement'); +var VElement = require('../runtime/vdom/VElement'); var expect = require('chai').expect; function getChildNodes(parentNode) { @@ -117,7 +117,7 @@ describe('AsyncVDOMBuilder', function() { }); it('staticNode, text, comment', function(done) { - var staticNode = new HTMLElement('div', {}, 0, 'f891ea3'); + var staticNode = new VElement('div', {}, 0, 'f891ea3'); var out = new AsyncVDOMBuilder(); out.node(staticNode); @@ -144,4 +144,4 @@ describe('AsyncVDOMBuilder', function() { // it('should avoid writes after end'); // // it('globals'); -}); \ No newline at end of file +}); diff --git a/test/autotests/vdom-create/assignAttributes/index.js b/test/autotests/vdom-create/assignAttributes/index.js index 6a1befb3b..f9d410013 100644 --- a/test/autotests/vdom-create/assignAttributes/index.js +++ b/test/autotests/vdom-create/assignAttributes/index.js @@ -1,9 +1,9 @@ module.exports = function(helpers) { - var morphAttrs = helpers.vdom.HTMLElement.$__morphAttrs; + var morphAttrs = helpers.vdom.VElement.$__morphAttrs; var fromEl = helpers.document.createElement('div'); var toEl = helpers.vdom.createElement('div', { class: 'foo', 'xlink:href': 'bar.com' }); morphAttrs(fromEl, toEl); return fromEl; -}; \ No newline at end of file +}; diff --git a/test/vdom-create-test.js b/test/vdom-create-test.js index 82207f93c..0b47c9ffb 100644 --- a/test/vdom-create-test.js +++ b/test/vdom-create-test.js @@ -6,25 +6,25 @@ var toHTML = require('./util/toHTML'); var jsdom = require("jsdom").jsdom; var document = jsdom(''); -var HTMLElement = require('../runtime/vdom/HTMLElement'); -var Text = require('../runtime/vdom/Text'); -var Comment = require('../runtime/vdom/Comment'); -var DocumentFragment = require('../runtime/vdom/DocumentFragment'); +var VElement = require('../runtime/vdom/VElement'); +var VText = require('../runtime/vdom/VText'); +var VComment = require('../runtime/vdom/VComment'); +var VDocumentFragment = require('../runtime/vdom/VDocumentFragment'); var vdomHelpers = { createElement: function(tagName, attrs, childCount, constId) { - return new HTMLElement(tagName, attrs, childCount, constId); + return new VElement(tagName, attrs, childCount, constId); }, createText: function(value) { - return new Text(value); + return new VText(value); }, createComment: function(value) { - return new Comment(value); + return new VComment(value); }, createDocumentFragment: function() { - return new DocumentFragment(); + return new VDocumentFragment(); }, - HTMLElement: HTMLElement + VElement: VElement }; describe('marko-vdom', () => { @@ -45,4 +45,4 @@ describe('marko-vdom', () => { done(); } ); -}); \ No newline at end of file +}); diff --git a/widgets/Widget.js b/widgets/Widget.js index 129d175ca..34199f9bc 100644 --- a/widgets/Widget.js +++ b/widgets/Widget.js @@ -15,7 +15,7 @@ var RenderResult = require('../runtime/RenderResult'); var SubscriptionTracker = require('listener-tracker'); var inherit = require('raptor-util/inherit'); var updateManager = require('./update-manager'); -var morphAttrs = require('../runtime/vdom/HTMLElement').$__morphAttrs; +var morphAttrs = require('../runtime/vdom/VElement').$__morphAttrs; var morphdomFactory = require('morphdom/factory'); var morphdom = morphdomFactory(morphAttrs);