incremental-dom-string
Advanced tools
Comparing version 0.0.1 to 0.0.2
@@ -20,3 +20,3 @@ (function (global, factory) { | ||
*/ | ||
const currentElement = function () { | ||
var currentElement = function currentElement() { | ||
return exports.currentParent; | ||
@@ -28,3 +28,3 @@ }; | ||
*/ | ||
const currentPointer = function () { | ||
var currentPointer = function currentPointer() { | ||
return {}; | ||
@@ -43,3 +43,3 @@ }; | ||
*/ | ||
const patch = function (node, fn, data) { | ||
var patch = function patch(node, fn, data) { | ||
exports.currentParent = node; | ||
@@ -52,4 +52,4 @@ fn(data); | ||
const patchOuter = patch; | ||
const patchInner = patch; | ||
var patchOuter = patch; | ||
var patchInner = patch; | ||
@@ -66,6 +66,6 @@ /** | ||
*/ | ||
const text = function (value, var_args) { | ||
let formatted = value; | ||
for (let i = 1; i < arguments.length; i += 1) { | ||
const fn = arguments[i]; | ||
var text = function text(value, var_args) { | ||
var formatted = value; | ||
for (var i = 1; i < arguments.length; i += 1) { | ||
var fn = arguments[i]; | ||
formatted = fn(formatted); | ||
@@ -77,3 +77,3 @@ } | ||
/** @const */ | ||
const symbols = { | ||
var symbols = { | ||
default: '__default' | ||
@@ -83,12 +83,12 @@ }; | ||
/** @const */ | ||
const attributes = {}; | ||
var attributes = {}; | ||
/** | ||
* Calls the appropriate attribute mutator for this attribute. | ||
* @param {!Array.<string>} el Buffer representation of element attributes. | ||
* @param {!Array.<string>} el Buffer to append element attributes. | ||
* @param {string} name The attribute's name. | ||
* @param {*} value The attribute's value. | ||
*/ | ||
const updateAttribute = function (el, name, value) { | ||
const mutator = attributes[name] || attributes[symbols.default]; | ||
var updateAttribute = function updateAttribute(el, name, value) { | ||
var mutator = attributes[name] || attributes[symbols.default]; | ||
mutator(el, name, value); | ||
@@ -101,3 +101,3 @@ }; | ||
if (Array.isArray(el)) { | ||
el.push(` ${name}="${value}"`); | ||
el.push(' ' + name + '="' + value + '"'); | ||
} | ||
@@ -111,3 +111,3 @@ }; | ||
*/ | ||
const truncateArray = function (arr, length) { | ||
var truncateArray = function truncateArray(arr, length) { | ||
while (arr.length > length) { | ||
@@ -123,3 +123,3 @@ arr.pop(); | ||
*/ | ||
const ATTRIBUTES_OFFSET = 3; | ||
var ATTRIBUTES_OFFSET = 3; | ||
@@ -131,3 +131,3 @@ /** | ||
*/ | ||
const argsBuilder = []; | ||
var argsBuilder = []; | ||
@@ -142,3 +142,3 @@ /** | ||
*/ | ||
const attr = function (name, value) { | ||
var attr = function attr(name, value) { | ||
argsBuilder.push(name); | ||
@@ -154,3 +154,3 @@ argsBuilder.push(value); | ||
*/ | ||
const elementClose = function (nameOrCtor) { | ||
var elementClose = function elementClose(nameOrCtor) { | ||
if (typeof nameOrCtor === 'function') { | ||
@@ -160,3 +160,3 @@ new nameOrCtor(); | ||
} | ||
exports.buffer.push(`</${nameOrCtor}>`); | ||
exports.buffer.push('</' + nameOrCtor + '>'); | ||
}; | ||
@@ -179,3 +179,3 @@ | ||
*/ | ||
const elementVoid = function (nameOrCtor, key, statics, var_args) { | ||
var elementVoid = function elementVoid(nameOrCtor, key, statics, var_args) { | ||
elementOpen.apply(null, arguments); | ||
@@ -197,3 +197,3 @@ return elementClose(nameOrCtor); | ||
*/ | ||
const elementOpen = function (nameOrCtor, key, statics, var_args) { | ||
var elementOpen = function elementOpen(nameOrCtor, key, statics, var_args) { | ||
if (typeof nameOrCtor === 'function') { | ||
@@ -204,8 +204,8 @@ new nameOrCtor(); | ||
exports.buffer.push(`<${nameOrCtor}`); | ||
exports.buffer.push('<' + nameOrCtor); | ||
if (statics) { | ||
for (let i = 0; i < statics.length; i += 2) { | ||
const name = /** @type {string} */statics[i]; | ||
const value = statics[i + 1]; | ||
for (var _i = 0; _i < statics.length; _i += 2) { | ||
var name = /** @type {string} */statics[_i]; | ||
var value = statics[_i + 1]; | ||
updateAttribute(exports.buffer, name, value); | ||
@@ -215,9 +215,9 @@ } | ||
let i = ATTRIBUTES_OFFSET; | ||
let j = 0; | ||
var i = ATTRIBUTES_OFFSET; | ||
var j = 0; | ||
for (; i < arguments.length; i += 2, j += 2) { | ||
const name = arguments[i]; | ||
const value = arguments[i + 1]; | ||
updateAttribute(exports.buffer, name, value); | ||
var _name = arguments[i]; | ||
var _value = arguments[i + 1]; | ||
updateAttribute(exports.buffer, _name, _value); | ||
} | ||
@@ -235,3 +235,3 @@ | ||
*/ | ||
const elementOpenEnd = function () { | ||
var elementOpenEnd = function elementOpenEnd() { | ||
elementOpen.apply(null, argsBuilder); | ||
@@ -256,3 +256,3 @@ truncateArray(argsBuilder, 0); | ||
*/ | ||
const elementOpenStart = function (nameOrCtor, key, statics) { | ||
var elementOpenStart = function elementOpenStart(nameOrCtor, key, statics) { | ||
argsBuilder[0] = nameOrCtor; | ||
@@ -268,3 +268,3 @@ argsBuilder[1] = key; | ||
*/ | ||
const renderToString = function (fn) { | ||
var renderToString = function renderToString(fn) { | ||
patch({}, fn); | ||
@@ -271,0 +271,0 @@ return currentElement().innerHTML; |
{ | ||
"name": "incremental-dom-string", | ||
"version": "0.0.1", | ||
"version": "0.0.2", | ||
"description": "Ability to render Incremental DOM virtual elements into strings on the server and the client.", | ||
@@ -5,0 +5,0 @@ "scripts": { |
# Incremental DOM string | ||
The DOM to be rendered is described with the incremental node functions, `elementOpen`, `elementClose` and `text`. For example, the following function: | ||
![](https://d3vv6lp55qjaqc.cloudfront.net/items/1l3o1p3n1l3P3e38391X/ics.gif) | ||
## Setup | ||
``` | ||
npm install --save incremental-dom-string | ||
``` | ||
## Usage | ||
The string to be rendered is described with the incremental node functions, `elementOpen`, `elementClose` and `text`. For example, the following function: | ||
```js | ||
import { | ||
elementOpen, | ||
elementClose, | ||
text, | ||
renderToString | ||
} from 'incremental-dom-string'; | ||
var IncrementalDOM = require('incremental-dom-string'); | ||
const output = renderToString(() => { | ||
elementOpen('div'); | ||
text('Hello world'); | ||
elementClose('div'); | ||
const output = IncrementalDOM.renderToString(() => { | ||
IncrementalDOM.elementOpen('div'); | ||
IncrementalDOM.text('Hello world'); | ||
IncrementalDOM.elementClose('div'); | ||
}); | ||
console.log(output); | ||
``` | ||
@@ -22,5 +29,3 @@ where `output` would correspond to | ||
```html | ||
<div> | ||
Hello world | ||
</div> | ||
<div>Hello world</div> | ||
``` |
@@ -8,3 +8,3 @@ import {symbols} from './symbols.js'; | ||
* Calls the appropriate attribute mutator for this attribute. | ||
* @param {!Array.<string>} el Buffer representation of element attributes. | ||
* @param {!Array.<string>} el Buffer to append element attributes. | ||
* @param {string} name The attribute's name. | ||
@@ -11,0 +11,0 @@ * @param {*} value The attribute's value. |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
19414
31