|
|
@@ -9,9 +9,9 @@ function Seed (opts) {
|
|
|
|
|
|
var self = this,
|
|
|
root = this.el = document.getElementById(opts.id),
|
|
|
- els = root.querySelectorAll(selector),
|
|
|
- bindings = {} // internal real data
|
|
|
+ els = root.querySelectorAll(selector)
|
|
|
|
|
|
+ var bindings = self._bindings = {} // internal real data
|
|
|
self.scope = {} // external interface
|
|
|
|
|
|
// process nodes for directives
|
|
|
@@ -33,6 +33,29 @@ function Seed (opts) {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+Seed.prototype.dump = function () {
|
|
|
+ var data = {}
|
|
|
+ for (var key in this._bindings) {
|
|
|
+ data[key] = this._bindings[key].value
|
|
|
+ }
|
|
|
+ return data
|
|
|
+}
|
|
|
+
|
|
|
+Seed.prototype.destroy = function () {
|
|
|
+ for (var key in this._bindings) {
|
|
|
+ this._bindings[key].directives.forEach(function (directive) {
|
|
|
+ if (directive.definition.unbind) {
|
|
|
+ directive.definition.unbind(
|
|
|
+ directive.el,
|
|
|
+ directive.argument,
|
|
|
+ directive
|
|
|
+ )
|
|
|
+ }
|
|
|
+ })
|
|
|
+ }
|
|
|
+ this.el.parentNode.remove(this.el)
|
|
|
+}
|
|
|
+
|
|
|
// clone attributes so they don't change
|
|
|
function cloneAttributes (attributes) {
|
|
|
return [].map.call(attributes, function (attr) {
|
|
|
@@ -44,6 +67,7 @@ function cloneAttributes (attributes) {
|
|
|
}
|
|
|
|
|
|
function bindDirective (seed, el, bindings, directive) {
|
|
|
+ directive.el = el
|
|
|
el.removeAttribute(directive.attr.name)
|
|
|
var key = directive.key,
|
|
|
binding = bindings[key]
|
|
|
@@ -53,7 +77,6 @@ function bindDirective (seed, el, bindings, directive) {
|
|
|
directives: []
|
|
|
}
|
|
|
}
|
|
|
- directive.el = el
|
|
|
binding.directives.push(directive)
|
|
|
// invoke bind hook if exists
|
|
|
if (directive.bind) {
|
|
|
@@ -72,12 +95,13 @@ function bindAccessors (seed, key, binding) {
|
|
|
set: function (value) {
|
|
|
binding.value = value
|
|
|
binding.directives.forEach(function (directive) {
|
|
|
+ var filteredValue = value
|
|
|
if (value && directive.filters) {
|
|
|
- value = applyFilters(value, directive)
|
|
|
+ filteredValue = applyFilters(value, directive)
|
|
|
}
|
|
|
directive.update(
|
|
|
directive.el,
|
|
|
- value,
|
|
|
+ filteredValue,
|
|
|
directive.argument,
|
|
|
directive,
|
|
|
seed
|