Evan You преди 13 години
родител
ревизия
0a45bb813f
променени са 4 файла, в които са добавени 7 реда и са изтрити 10 реда
  1. 1 1
      TODO.md
  2. 1 1
      src/compiler.js
  3. 1 1
      src/deps-parser.js
  4. 4 7
      src/viewmodel.js

+ 1 - 1
TODO.md

@@ -1,7 +1,7 @@
 - fix architecture: objects as single source of truth...
 - auto add .length binding for Arrays
 - $watch / $unwatch & $destroy(now much easier)
-- add a few util methods, e.g. extend, inherits
+- add a few util methods, e.g. extend, inherits, traverse
 - prototypal scope/binding inheritance (Object.create)
 - tests
 - docs

+ 1 - 1
src/compiler.js

@@ -464,8 +464,8 @@ CompilerProto.destroy = function () {
     }
     // unbind/unobserve all own bindings
     for (key in bindings) {
-        binding = bindings[key]
         if (bindings.hasOwnProperty(key)) {
+            binding = bindings[key]
             if (binding.root) {
                 Observer.unobserve(binding.value, binding.key, this.observer)
             }

+ 1 - 1
src/deps-parser.js

@@ -19,6 +19,7 @@ var dummyEl = document.createElement('div'),
 function catchDeps (binding) {
     utils.log('\n─ ' + binding.key)
     observer.on('get', function (dep) {
+        if (binding.deps.indexOf(dep) !== -1) return
         utils.log('  └─ ' + dep.key)
         binding.deps.push(dep)
         dep.subs.push(binding)
@@ -95,7 +96,6 @@ function parseContextDependency (binding) {
         str  = fn.toString(),
         args = str.match(ARGS_RE)
     if (!args) return null
-    binding.isContextual = true
     var depsRE = new RegExp(args[1] + SCOPE_RE_STR, 'g'),
         matches = str.match(depsRE),
         base = args[1].length + 4

+ 4 - 7
src/viewmodel.js

@@ -18,14 +18,11 @@ var VMProto = ViewModel.prototype
  */
 VMProto.$set = function (key, value) {
     var path = key.split('.'),
-        l = path.length - 1,
-        target = this,
-        level = 0
-    while (level < l) {
-        target = target[path[level]]
-        level++
+        obj = this
+    for (var d = 0, l = path.length - 1; d < l; d++) {
+        obj = obj[path[d]]
     }
-    target[path[level]] = value
+    obj[path[d]] = value
 }
 
 /*