Comparing version 0.0.5 to 0.0.6
@@ -24,4 +24,4 @@ 'use strict'; | ||
this._childNodes = []; | ||
this._namedElements = []; | ||
this._propertyElements = []; | ||
this.namedElements = {}; | ||
this.propertyElements = {}; | ||
} | ||
@@ -31,4 +31,10 @@ }, { | ||
value: function _compile() { | ||
this._namedElements = this._processAttributes('data-name'); | ||
this._propertyElements = this._processAttributes('data-property'); | ||
var _this = this; | ||
this._processAttributes('data-name').forEach(function (item) { | ||
_this.namedElements[item.name] = item.value; | ||
}); | ||
this._processAttributes('data-property').forEach(function (item) { | ||
_this.propertyElements[item.name] = item.value; | ||
}); | ||
this._childNodes = [].slice.call(this._dom.childNodes, 0); | ||
@@ -54,6 +60,6 @@ } | ||
value: function reclaimChildren() { | ||
var _this = this; | ||
var _this2 = this; | ||
this._childNodes.forEach(function (element) { | ||
_this._dom.appendChild(element); | ||
return _this2._dom.appendChild(element); | ||
}); | ||
@@ -71,12 +77,2 @@ } | ||
} | ||
}, { | ||
key: 'namedElements', | ||
get: function get() { | ||
return this._namedElements; | ||
} | ||
}, { | ||
key: 'propertyElements', | ||
get: function get() { | ||
return this._propertyElements; | ||
} | ||
}]); | ||
@@ -83,0 +79,0 @@ |
@@ -15,14 +15,8 @@ 'use strict'; | ||
this._properties = []; | ||
this._activeChildElements = []; | ||
this._template = template; | ||
this._exposeNamedElements(); | ||
} | ||
_createClass(View, [{ | ||
key: '_attachTemplate', | ||
value: function _attachTemplate() { | ||
this._exposeNamedElements(); | ||
this._collectPropertyElements(); | ||
} | ||
}, { | ||
key: '_exposeNamedElements', | ||
@@ -32,22 +26,11 @@ value: function _exposeNamedElements() { | ||
this._template.namedElements.forEach(function (val) { | ||
_this[val.name] = val.value; | ||
Object.keys(this._template.namedElements).forEach(function (elementName) { | ||
_this[elementName] = _this._template.namedElements[elementName]; | ||
}); | ||
} | ||
}, { | ||
key: '_collectPropertyElements', | ||
value: function _collectPropertyElements() { | ||
var _this2 = this; | ||
this._template.propertyElements.forEach(function (val) { | ||
_this2._properties[val.name] = val.value; | ||
}); | ||
} | ||
}, { | ||
key: 'activate', | ||
value: function activate(region) { | ||
this._region = region; | ||
this._attachTemplate(); | ||
this._moveDomChildrenToRegion(); | ||
this._tryUpdatePropertiesData(); | ||
} | ||
@@ -57,7 +40,7 @@ }, { | ||
value: function _moveDomChildrenToRegion() { | ||
var _this3 = this; | ||
var _this2 = this; | ||
this._template.childNodes.forEach(function (element) { | ||
_this3._activeChildElements.push(element); | ||
_this3._region.appendChild(element); | ||
_this2._activeChildElements.push(element); | ||
_this2._region.appendChild(element); | ||
}); | ||
@@ -68,3 +51,2 @@ } | ||
value: function deactivate() { | ||
this._properties = []; | ||
this._template.reclaimChildren(); | ||
@@ -76,8 +58,8 @@ this._activeChildElements = []; | ||
value: function getData() { | ||
var _this4 = this; | ||
var _this3 = this; | ||
var result = {}; | ||
this._template.propertyElements.forEach(function (propertyElement) { | ||
var element = propertyElement.value; | ||
result[propertyElement.name] = _this4._getElementValue(element); | ||
Object.keys(this._template.propertyElements).forEach(function (propertyName) { | ||
var element = _this3._template.propertyElements[propertyName]; | ||
result[propertyName] = _this3._getElementValue(element); | ||
}); | ||
@@ -98,4 +80,8 @@ return result; | ||
value: function setData(data) { | ||
this._data = data; | ||
this._tryUpdatePropertiesData(); | ||
var _this4 = this; | ||
Object.keys(data).forEach(function (name) { | ||
var element = _this4._template.propertyElements[name]; | ||
_this4._setElementValue(element, data[name]); | ||
}); | ||
} | ||
@@ -105,36 +91,10 @@ }, { | ||
value: function clearData() { | ||
this._tryClearPropertiesData(); | ||
var _this5 = this; | ||
Object.keys(this._template.propertyElements).forEach(function (name) { | ||
var element = _this5._template.propertyElements[name]; | ||
_this5._setElementValue(element, ''); | ||
}); | ||
} | ||
}, { | ||
key: '_tryUpdatePropertiesData', | ||
value: function _tryUpdatePropertiesData() { | ||
if (this._region !== undefined && this._data !== undefined) { | ||
this._updateProperties(); | ||
} | ||
} | ||
}, { | ||
key: '_updateProperties', | ||
value: function _updateProperties() { | ||
for (var _name in this._data) { | ||
var element = this._properties[_name]; | ||
var data = this._data[_name]; | ||
this._setElementValue(element, data); | ||
} | ||
} | ||
}, { | ||
key: '_tryClearPropertiesData', | ||
value: function _tryClearPropertiesData() { | ||
if (this._region !== undefined && this._properties !== undefined) { | ||
this._clearProperties(); | ||
} | ||
} | ||
}, { | ||
key: '_clearProperties', | ||
value: function _clearProperties() { | ||
for (var i in this._properties) { | ||
var element = this._properties[i]; | ||
this._setElementValue(element, ''); | ||
} | ||
} | ||
}, { | ||
key: '_setElementValue', | ||
@@ -141,0 +101,0 @@ value: function _setElementValue(element, value) { |
{ | ||
"version": "0.0.5", | ||
"version": "0.0.6", | ||
"name": "tplify", | ||
@@ -33,2 +33,3 @@ "description": "A simple html template compiler plugin for Browserify", | ||
"babel": "^5.4.7", | ||
"babel-eslint": "^6.1.2", | ||
"babelify": "^6.1.3", | ||
@@ -39,2 +40,3 @@ "browserify": "^10.2.1", | ||
"eslint": "^1.2.1", | ||
"eslint-plugin-babel": "^3.3.0", | ||
"eslint-plugin-mocha": "^0.5.1", | ||
@@ -41,0 +43,0 @@ "karma": "^0.13.9", |
Sorry, the diff of this file is not supported yet
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
1
15588
22
10
268