diff --git a/element/element.js b/element/element.js index 4523f19..33859d7 100644 --- a/element/element.js +++ b/element/element.js @@ -129,34 +129,26 @@ export default function LiteralElement(tag, lifecycle = {}, properties = {}) { }, connect: function(shadow, internals) { - const { renderer } = internals; + const { renderer, object, data } = internals; - if (!internals.initialised) { - internals.initialised = true; - - // Get data found in dataset - assignDataset(internals.object, this.dataset); - - // Set internal data to object's observer proxy - internals.data = Data.of(internals.object); - } + if (!data) internals.data = Data.of(object); // We must render synchronously here else rendered 'slotchange' // listeners miss the first slotchange... this IS synchronous, right? - internals.renderer.push(internals.data); + renderer.push(internals.data); // Connect callback called post-render if (lifecycle.connect) lifecycle.connect.call(this, shadow, internals, internals.data); }, disconnect: function(shadow, internals) { - const { renderer } = internals; + const { renderer, data } = internals; // Make literal renderer go dormant - internals.renderer.push(null); + renderer.push(null); // Disconnect callback post render - if (lifecycle.disconnect) lifecycle.disconnect.call(this, shadow, internals, internals.data); + if (lifecycle.disconnect) lifecycle.disconnect.call(this, shadow, internals, data); }, enable: lifecycle.enable && function enable(shadow, internals) { lifecycle.enable.call(this, shadow, internals, internals.data); }, diff --git a/modules/renderer.js b/modules/renderer.js deleted file mode 100644 index 4ef7395..0000000 --- a/modules/renderer.js +++ /dev/null @@ -1,42 +0,0 @@ - -import names from './renderer/property-names.js'; -import Renderer, { stats } from './renderer/renderer.js'; -import AttributeRenderer from './renderer/renderer-attribute.js'; -import BooleanRenderer from './renderer/renderer-boolean.js'; -import CheckedRenderer from './renderer/renderer-checked.js'; -import DatasetRenderer from './renderer/renderer-dataset.js'; -import TokensRenderer from './renderer/renderer-tokens.js'; -import ValueRenderer from './renderer/renderer-value.js'; -import TextRenderer from './renderer/renderer-text.js'; - -/* - Include bind() in consts somehow... - AttributeRenderer.prototype.create.call(this, element, assign({ - // Parameters - bind: (path, object, to = id, from = id) => - bindValue(element, object, path, to, from, setValue) - }, consts)); -*/ - -Renderer.create = function create(signal, literal, consts, element, n, debug) { - const name = typeof n === 'string' && (names[n] || n) ; - - return name ? - /^data-/.test(name) ? - new DatasetRenderer(signal, literal, consts, element, n, debug) : - // Return some type of attribute renderer - name === 'value' ? - new ValueRenderer(signal, literal, consts, element, n, debug) : - name === 'checked' ? - new CheckedRenderer(signal, literal, consts, element, n, debug) : - typeof element[name] === 'boolean' ? - new BooleanRenderer(signal, literal, consts, element, n, debug) : - typeof element[name] === 'object' && element[name].add && element[name].remove ? - new TokensRenderer(signal, literal, consts, element, n, debug) : - new AttributeRenderer(signal, literal, consts, element, n, debug) : - // Assume n is a text node - new TextRenderer(signal, literal, consts, element, n, debug) ; -}; - -export { stats }; -export default Renderer; diff --git a/modules/template.js b/modules/template.js index dfba524..33f99a9 100644 --- a/modules/template.js +++ b/modules/template.js @@ -31,7 +31,7 @@ import Data from '../../fn/modules/data.js'; import create from '../../dom/modules/create.js'; import identify from '../../dom/modules/identify.js'; import { pathSeparator } from './compile/constants.js'; -import Renderer, { stats } from './renderer.js'; +import Renderer, { stats } from './renderer/renderer.js'; import compileNode from './compile.js'; import { groupCollapsed, groupEnd } from './log.js'; @@ -43,7 +43,7 @@ const defaults = {}; /* -LiteralRenderer +Literal Descendant paths are stored in the form `"#id>1>12>3"`, enabling fast cloning of template instances without retraversing their DOMs looking for literal attributes and text. @@ -96,11 +96,11 @@ export default class Literal { } static isTemplate(object) { - return object instanceof LiteralRenderer; + return object instanceof Literal; } - static of(html) { - return LiteralRenderer.from(create('template', html)); + static fromHTML(html) { + return Literal.fromTemplate(create('template', html)); } static fromFragment(fragment, identifier, element, consts = {}, data, options) { @@ -246,7 +246,7 @@ export default class Literal { // Last node is not in the DOM if (this.content.lastChild === last) { - throw new Error('Illegal LiteralRenderer.before() – template is not in the DOM'); + throw new Error('Illegal Literal.before() – template is not in the DOM'); } // First node is not in the DOM