typed-dom
Advanced tools
Comparing version 0.0.22 to 0.0.23
@@ -1,2 +0,2 @@ | ||
/*! typed-dom v0.0.22 https://github.com/falsandtru/typed-dom | (c) 2016, falsandtru | MIT License */ | ||
/*! typed-dom v0.0.23 https://github.com/falsandtru/typed-dom | (c) 2016, falsandtru | MIT License */ | ||
require = function e(t, n, r) { | ||
@@ -41,4 +41,14 @@ function s(o, u) { | ||
'use strict'; | ||
var __assign = this && this.__assign || Object.assign || function (t) { | ||
for (var s, i = 1, n = arguments.length; i < n; i++) { | ||
s = arguments[i]; | ||
for (var p in s) | ||
if (Object.prototype.hasOwnProperty.call(s, p)) | ||
t[p] = s[p]; | ||
} | ||
return t; | ||
}; | ||
var TypedHTMLElement = function () { | ||
function TypedHTMLElement(element_, children_) { | ||
var _this = this; | ||
this.element_ = element_; | ||
@@ -57,9 +67,10 @@ this.children_ = children_; | ||
case 'collection': | ||
void Object.freeze(children_); | ||
this.children_ = []; | ||
this.children_ = Object.freeze([]); | ||
this.children = children_; | ||
break; | ||
case 'struct': | ||
this.children_ = Object.create(null); | ||
this.children = children_; | ||
this.children_ = this.observe(__assign({}, children_)); | ||
void this.structkeys.forEach(function (k) { | ||
return void _this.element_.appendChild(children_[k].element); | ||
}); | ||
break; | ||
@@ -95,3 +106,4 @@ } | ||
break; | ||
void Object.freeze(children); | ||
if (!Object.isFrozen(this.children_)) | ||
throw new Error('TypedHTMLElement collections cannot be updated recursively.'); | ||
void children.reduce(function (ccs, ic) { | ||
@@ -106,6 +118,7 @@ var i = ccs.indexOf(ic); | ||
}); | ||
void children.forEach(function (child) { | ||
return void _this.element_.appendChild(child.element); | ||
this.children_ = []; | ||
void children.forEach(function (child, i) { | ||
return _this.children_[i] = child, void _this.element_.appendChild(child.element); | ||
}); | ||
this.children_ = children; | ||
void Object.freeze(this.children_); | ||
break; | ||
@@ -116,6 +129,4 @@ case 'struct': | ||
void this.structkeys.forEach(function (k) { | ||
return _this.children_[k] && _this.children_[k].element.parentElement === _this.element_ ? void _this.element_.replaceChild(children[k].element, _this.children_[k].element) : void _this.element_.appendChild(children[k].element); | ||
return _this.children_[k] = children[k]; | ||
}); | ||
void this.observe(children); | ||
this.children_ = children; | ||
break; | ||
@@ -129,4 +140,4 @@ } | ||
var _this = this; | ||
void Object.defineProperties(children, this.structkeys.reduce(function (descs, key) { | ||
var oldChild = children[key]; | ||
return Object.defineProperties(children, this.structkeys.reduce(function (descs, key) { | ||
var current = children[key]; | ||
descs[key] = { | ||
@@ -136,9 +147,10 @@ configurable: true, | ||
get: function () { | ||
return oldChild; | ||
return current; | ||
}, | ||
set: function (newChild) { | ||
var oldChild = current; | ||
if (newChild === oldChild) | ||
return; | ||
current = newChild; | ||
void _this.element_.replaceChild(newChild.element, oldChild.element); | ||
oldChild = newChild; | ||
} | ||
@@ -145,0 +157,0 @@ }; |
@@ -1,2 +0,2 @@ | ||
/*! typed-dom v0.0.22 https://github.com/falsandtru/typed-dom | (c) 2016, falsandtru | MIT License */ | ||
require=function e(t,r,n){function i(c,d){if(!r[c]){if(!t[c]){var s="function"==typeof require&&require;if(!d&&s)return s(c,!0);if(o)return o(c,!0);var l=new Error("Cannot find module '"+c+"'");throw l.code="MODULE_NOT_FOUND",l}var u=r[c]={exports:{}};t[c][0].call(u.exports,function(e){var r=t[c][1][e];return i(r?r:e)},u,u.exports,e,t,r,n)}return r[c].exports}for(var o="function"==typeof require&&require,c=0;c<n.length;c++)i(n[c]);return i}({1:[function(e,t,r){},{}],2:[function(e,t,r){arguments[4][1][0].apply(r,arguments)},{dup:1}],3:[function(e,t,r){"use strict";var n=function(){function e(e,t){if(this.element_=e,this.children_=t,this.mode=void 0===this.children_?"empty":"string"==typeof this.children_?"text":Array.isArray(this.children_)?"collection":"struct",this.structkeys="struct"===this.mode?Object.keys(this.children_):[],void 0!==t)switch(this.mode){case"text":this.children_=document.createTextNode(""),void this.element_.appendChild(this.children_),this.children=t;break;case"collection":void Object.freeze(t),this.children_=[],this.children=t;break;case"struct":this.children_=Object.create(null),this.children=t}}return Object.defineProperty(e.prototype,"element",{get:function(){return this.element_},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"children",{get:function(){switch(this.mode){case"text":return this.children_.data;default:return this.children_}},set:function(e){var t=this;switch(this.mode){case"text":if(e===this.children_.data)break;this.children_.data=e;break;case"collection":if(e===this.children_)break;void Object.freeze(e),void e.reduce(function(e,t){var r=e.indexOf(t);return r===-1?e:(void e.splice(r,1),e)},this.children_.slice()).forEach(function(e){return void e.element.remove()}),void e.forEach(function(e){return void t.element_.appendChild(e.element)}),this.children_=e;break;case"struct":if(e===this.children_)break;void this.structkeys.forEach(function(r){return t.children_[r]&&t.children_[r].element.parentElement===t.element_?void t.element_.replaceChild(e[r].element,t.children_[r].element):void t.element_.appendChild(e[r].element)}),void this.observe(e),this.children_=e}},enumerable:!0,configurable:!0}),e.prototype.observe=function(e){var t=this;void Object.defineProperties(e,this.structkeys.reduce(function(r,n){var i=e[n];return r[n]={configurable:!0,enumerable:!0,get:function(){return i},set:function(e){e!==i&&(void t.element_.replaceChild(e.element,i.element),i=e)}},r},{}))},e}();r.TypedHTMLElement=n},{}],4:[function(e,t,r){"use strict";function n(e,t){return void Object.keys(e).forEach(function(r){return void t.setAttribute(r,e[r]||"")}),t}var i=e("./builder");r.TypedHTML=["a","abbr","acronym","address","applet","area","article","aside","audio","b","base","basefont","bdo","big","blockquote","body","br","button","canvas","caption","center","cite","code","col","colgroup","datalist","dd","del","dfn","dir","div","dl","dt","em","embed","fieldset","figcaption","figure","font","footer","form","frame","frameset","h1","h2","h3","h4","h5","h6","head","header","hgroup","hr","html","i","iframe","img","input","ins","isindex","kbd","keygen","label","legend","li","link","listing","map","mark","marquee","menu","meta","meter","nav","nextid","nobr","noframes","noscript","object","ol","optgroup","option","p","param","picture","plaintext","pre","progress","q","rt","ruby","s","samp","script","section","select","small","source","span","strike","strong","style","sub","sup","table","tbody","td","template","textarea","tfoot","th","thead","title","tr","track","tt","u","ul","var","video","wbr","xmp","custom"].reduce(function(e,t){return e[t]=function(e,r,o){return e&&r&&"function"!=typeof r?new i.TypedHTMLElement(n(e,(o||function(){return document.createElement(t)})()),r):new i.TypedHTMLElement((r||function(){return document.createElement(t)})(),e)},e},{})},{"./builder":3}],5:[function(e,t,r){"use strict";var n=e("./dom/html");r.default=n.TypedHTML},{"./dom/html":4}],6:[function(e,t,r){arguments[4][1][0].apply(r,arguments)},{dup:1}],"typed-dom":[function(e,t,r){"use strict";function n(e){for(var t in e)r.hasOwnProperty(t)||(r[t]=e[t])}n(e("./src/export"));var i=e("./src/export");r.default=i.default,r.__esModule=!0},{"./src/export":5}]},{},[1,2,6,"typed-dom"]); | ||
/*! typed-dom v0.0.23 https://github.com/falsandtru/typed-dom | (c) 2016, falsandtru | MIT License */ | ||
require=function e(t,r,n){function i(c,s){if(!r[c]){if(!t[c]){var d="function"==typeof require&&require;if(!s&&d)return d(c,!0);if(o)return o(c,!0);var u=new Error("Cannot find module '"+c+"'");throw u.code="MODULE_NOT_FOUND",u}var a=r[c]={exports:{}};t[c][0].call(a.exports,function(e){var r=t[c][1][e];return i(r?r:e)},a,a.exports,e,t,r,n)}return r[c].exports}for(var o="function"==typeof require&&require,c=0;c<n.length;c++)i(n[c]);return i}({1:[function(e,t,r){},{}],2:[function(e,t,r){arguments[4][1][0].apply(r,arguments)},{dup:1}],3:[function(e,t,r){"use strict";var n=this&&this.__assign||Object.assign||function(e){for(var t,r=1,n=arguments.length;r<n;r++){t=arguments[r];for(var i in t)Object.prototype.hasOwnProperty.call(t,i)&&(e[i]=t[i])}return e},i=function(){function e(e,t){var r=this;if(this.element_=e,this.children_=t,this.mode=void 0===this.children_?"empty":"string"==typeof this.children_?"text":Array.isArray(this.children_)?"collection":"struct",this.structkeys="struct"===this.mode?Object.keys(this.children_):[],void 0!==t)switch(this.mode){case"text":this.children_=document.createTextNode(""),void this.element_.appendChild(this.children_),this.children=t;break;case"collection":this.children_=Object.freeze([]),this.children=t;break;case"struct":this.children_=this.observe(n({},t)),void this.structkeys.forEach(function(e){return void r.element_.appendChild(t[e].element)})}}return Object.defineProperty(e.prototype,"element",{get:function(){return this.element_},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"children",{get:function(){switch(this.mode){case"text":return this.children_.data;default:return this.children_}},set:function(e){var t=this;switch(this.mode){case"text":if(e===this.children_.data)break;this.children_.data=e;break;case"collection":if(e===this.children_)break;if(!Object.isFrozen(this.children_))throw new Error("TypedHTMLElement collections cannot be updated recursively.");void e.reduce(function(e,t){var r=e.indexOf(t);return r===-1?e:(void e.splice(r,1),e)},this.children_.slice()).forEach(function(e){return void e.element.remove()}),this.children_=[],void e.forEach(function(e,r){return t.children_[r]=e,void t.element_.appendChild(e.element)}),void Object.freeze(this.children_);break;case"struct":if(e===this.children_)break;void this.structkeys.forEach(function(r){return t.children_[r]=e[r]})}},enumerable:!0,configurable:!0}),e.prototype.observe=function(e){var t=this;return Object.defineProperties(e,this.structkeys.reduce(function(r,n){var i=e[n];return r[n]={configurable:!0,enumerable:!0,get:function(){return i},set:function(e){var r=i;e!==r&&(i=e,void t.element_.replaceChild(e.element,r.element))}},r},{}))},e}();r.TypedHTMLElement=i},{}],4:[function(e,t,r){"use strict";function n(e,t){return void Object.keys(e).forEach(function(r){return void t.setAttribute(r,e[r]||"")}),t}var i=e("./builder");r.TypedHTML=["a","abbr","acronym","address","applet","area","article","aside","audio","b","base","basefont","bdo","big","blockquote","body","br","button","canvas","caption","center","cite","code","col","colgroup","datalist","dd","del","dfn","dir","div","dl","dt","em","embed","fieldset","figcaption","figure","font","footer","form","frame","frameset","h1","h2","h3","h4","h5","h6","head","header","hgroup","hr","html","i","iframe","img","input","ins","isindex","kbd","keygen","label","legend","li","link","listing","map","mark","marquee","menu","meta","meter","nav","nextid","nobr","noframes","noscript","object","ol","optgroup","option","p","param","picture","plaintext","pre","progress","q","rt","ruby","s","samp","script","section","select","small","source","span","strike","strong","style","sub","sup","table","tbody","td","template","textarea","tfoot","th","thead","title","tr","track","tt","u","ul","var","video","wbr","xmp","custom"].reduce(function(e,t){return e[t]=function(e,r,o){return e&&r&&"function"!=typeof r?new i.TypedHTMLElement(n(e,(o||function(){return document.createElement(t)})()),r):new i.TypedHTMLElement((r||function(){return document.createElement(t)})(),e)},e},{})},{"./builder":3}],5:[function(e,t,r){"use strict";var n=e("./dom/html");r.default=n.TypedHTML},{"./dom/html":4}],6:[function(e,t,r){arguments[4][1][0].apply(r,arguments)},{dup:1}],"typed-dom":[function(e,t,r){"use strict";function n(e){for(var t in e)r.hasOwnProperty(t)||(r[t]=e[t])}n(e("./src/export"));var i=e("./src/export");r.default=i.default,r.__esModule=!0},{"./src/export":5}]},{},[1,2,6,"typed-dom"]); |
{ | ||
"name": "typed-dom", | ||
"version": "0.0.22", | ||
"version": "0.0.23", | ||
"description": "Static typed dom component builder.", | ||
@@ -33,5 +33,5 @@ "private": false, | ||
"devDependencies": { | ||
"@types/mocha": "^2.2.37", | ||
"@types/mocha": "^2.2.38", | ||
"@types/power-assert": "1.4.29", | ||
"browserify": "^13.3.0", | ||
"browserify": "^14.0.0", | ||
"del": "^2.2.2", | ||
@@ -44,3 +44,3 @@ "extend": "^3.0.0", | ||
"gulp-rename": "^1.2.2", | ||
"gulp-uglify": "^2.0.0", | ||
"gulp-uglify": "^2.0.1", | ||
"gulp-unassert": "^1.0.1", | ||
@@ -47,0 +47,0 @@ "karma": "1.4.0", |
@@ -36,12 +36,23 @@ import { TypedHTMLElement as ITypedHTMLElement } from 'typed-dom'; | ||
case 'collection': | ||
void Object.freeze(children_); | ||
this.children_ = <C><TypedHTMLElementChildren.Collection>[]; | ||
this.children_ = <C><TypedHTMLElementChildren.Collection><never[]>Object.freeze([]); | ||
this.children = children_; | ||
break; | ||
case 'struct': | ||
this.children_ = <C><TypedHTMLElementChildren.Struct>Object.create(null); | ||
this.children = children_; | ||
this.children_ = <C>this.observe({ ...<TypedHTMLElementChildren.Struct>children_ }); | ||
void this.structkeys | ||
.forEach(k => | ||
void this.element_.appendChild(children_[k].element)); | ||
break; | ||
} | ||
} | ||
private readonly mode: 'empty' | 'text' | 'collection' | 'struct' = this.children_ === void 0 | ||
? 'empty' | ||
: typeof this.children_ === 'string' | ||
? 'text' | ||
: Array.isArray(this.children_) | ||
? 'collection' | ||
: 'struct'; | ||
private readonly structkeys: string[] = this.mode === 'struct' | ||
? Object.keys(this.children_) | ||
: []; | ||
public get element(): E { | ||
@@ -67,3 +78,3 @@ return this.element_; | ||
if (children === this.children_) break; | ||
void Object.freeze(children); | ||
if (!Object.isFrozen(this.children_)) throw new Error('TypedHTMLElement collections cannot be updated recursively.'); | ||
void (<TypedHTMLElementChildren.Collection>children) | ||
@@ -78,6 +89,8 @@ .reduce<TypedHTMLElementChildren.Collection>((ccs, ic) => { | ||
void child.element.remove()); | ||
this.children_ = <C><TypedHTMLElementChildren.Collection>[]; | ||
void (<TypedHTMLElementChildren.Collection>children) | ||
.forEach(child => | ||
void this.element_.appendChild(child.element)); | ||
this.children_ = children; | ||
.forEach((child, i) => ( | ||
this.children_[i] = child, | ||
void this.element_.appendChild(child.element))); | ||
void Object.freeze(this.children_); | ||
break; | ||
@@ -89,7 +102,3 @@ | ||
.forEach(k => | ||
this.children_[k] && this.children_[k].element.parentElement === this.element_ | ||
? void this.element_.replaceChild(children[k].element, this.children_[k].element) | ||
: void this.element_.appendChild(children[k].element)); | ||
void this.observe(<TypedHTMLElementChildren.Struct>children); | ||
this.children_ = children; | ||
this.children_[k] = children[k]); | ||
break; | ||
@@ -99,6 +108,6 @@ | ||
} | ||
private observe(children: TypedHTMLElementChildren.Struct): void { | ||
void Object.defineProperties(children, this.structkeys | ||
private observe<C extends TypedHTMLElementChildren.Struct>(children: C): C { | ||
return Object.defineProperties(children, this.structkeys | ||
.reduce<PropertyDescriptorMap>((descs, key) => { | ||
let oldChild = children[key]; | ||
let current = children[key]; | ||
descs[key] = { | ||
@@ -108,8 +117,9 @@ configurable: true, | ||
get: (): ITypedHTMLElement<string, HTMLElement, any> => { | ||
return oldChild; | ||
return current; | ||
}, | ||
set: (newChild: TypedHTMLElement<string, HTMLElement, any>) => { | ||
const oldChild = current; | ||
if (newChild === oldChild) return; | ||
current = newChild; | ||
void this.element_.replaceChild(newChild.element, oldChild.element); | ||
oldChild = newChild; | ||
} | ||
@@ -120,12 +130,2 @@ }; | ||
} | ||
private readonly mode: 'empty' | 'text' | 'collection' | 'struct' = this.children_ === void 0 | ||
? 'empty' | ||
: typeof this.children_ === 'string' | ||
? 'text' | ||
: Array.isArray(this.children_) | ||
? 'collection' | ||
: 'struct'; | ||
private readonly structkeys: string[] = this.mode === 'struct' | ||
? Object.keys(this.children_) | ||
: []; | ||
} |
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
51928
1195