Просмотр исходного кода

filter value should not be written

Evan You 13 лет назад
Родитель
Сommit
3eb7f6fc72
3 измененных файлов с 43 добавлено и 11 удалено
  1. 11 6
      dev.html
  2. 3 0
      src/directives.js
  3. 29 5
      src/main.js

+ 11 - 6
dev.html

@@ -7,10 +7,12 @@
 	</head>
 	</head>
 	<body>
 	<body>
 		<div id="test" sd-on-click="changeMessage | .button">
 		<div id="test" sd-on-click="changeMessage | .button">
-            <p sd-text="msg | capitalize"></p>
-            <p sd-show="something">YOYOYO</p>
-            <p class="button" sd-text="msg"></p>
+            <p sd-text="msg.wow | capitalize" sd-on-click="remove"></p>
+            <p sd-text="msg.wow" class="button"></p>
             <p sd-class-red="error" sd-text="hello"></p>
             <p sd-class-red="error" sd-text="hello"></p>
+            <div sd-repeat="todos">
+            	<span sd-text="text"></span>
+            </div>
         </div>
         </div>
 		<script>
 		<script>
 			var Seed = require('seed')
 			var Seed = require('seed')
@@ -18,10 +20,13 @@
 			    id: 'test',
 			    id: 'test',
 			    // template
 			    // template
 			    scope: {
 			    scope: {
-			        msg: 'hello',
-			        hello: 'WHWHWHW',
+			        'msg.wow': 'wow',
+			        hello: 'hello',
 			        changeMessage: function () {
 			        changeMessage: function () {
-			            app.scope.msg = 'hola'
+			            app.scope['msg.wow'] = 'hola'
+			        },
+			        remove: function () {
+			            app.destroy()
 			        }
 			        }
 			    }
 			    }
 			})
 			})

+ 3 - 0
src/directives.js

@@ -36,5 +36,8 @@ module.exports = {
                 if (match) handler.apply(this, arguments)
                 if (match) handler.apply(this, arguments)
             }
             }
         }
         }
+    },
+    repeat: function () {
+        
     }
     }
 }
 }

+ 29 - 5
src/main.js

@@ -9,9 +9,9 @@ function Seed (opts) {
 
 
     var self = this,
     var self = this,
         root = this.el = document.getElementById(opts.id),
         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
     self.scope = {} // external interface
 
 
     // process nodes for directives
     // 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
 // clone attributes so they don't change
 function cloneAttributes (attributes) {
 function cloneAttributes (attributes) {
     return [].map.call(attributes, function (attr) {
     return [].map.call(attributes, function (attr) {
@@ -44,6 +67,7 @@ function cloneAttributes (attributes) {
 }
 }
 
 
 function bindDirective (seed, el, bindings, directive) {
 function bindDirective (seed, el, bindings, directive) {
+    directive.el = el
     el.removeAttribute(directive.attr.name)
     el.removeAttribute(directive.attr.name)
     var key = directive.key,
     var key = directive.key,
         binding = bindings[key]
         binding = bindings[key]
@@ -53,7 +77,6 @@ function bindDirective (seed, el, bindings, directive) {
             directives: []
             directives: []
         }
         }
     }
     }
-    directive.el = el
     binding.directives.push(directive)
     binding.directives.push(directive)
     // invoke bind hook if exists
     // invoke bind hook if exists
     if (directive.bind) {
     if (directive.bind) {
@@ -72,12 +95,13 @@ function bindAccessors (seed, key, binding) {
         set: function (value) {
         set: function (value) {
             binding.value = value
             binding.value = value
             binding.directives.forEach(function (directive) {
             binding.directives.forEach(function (directive) {
+                var filteredValue = value
                 if (value && directive.filters) {
                 if (value && directive.filters) {
-                    value = applyFilters(value, directive)
+                    filteredValue = applyFilters(value, directive)
                 }
                 }
                 directive.update(
                 directive.update(
                     directive.el,
                     directive.el,
-                    value,
+                    filteredValue,
                     directive.argument,
                     directive.argument,
                     directive,
                     directive,
                     seed
                     seed