Selaa lähdekoodia

shorten some function names since they cant be mangled

Evan You 13 vuotta sitten
vanhempi
commit
fa453830de
4 muutettua tiedostoa jossa 24 lisäystä ja 19 poistoa
  1. 15 12
      src/binding.js
  2. 4 4
      src/deps-parser.js
  3. 1 1
      src/directive-parser.js
  4. 4 2
      src/seed.js

+ 15 - 12
src/binding.js

@@ -1,5 +1,6 @@
 var Emitter  = require('emitter'),
-    observer = require('./deps-parser').observer
+    observer = require('./deps-parser').observer,
+    def      = Object.defineProperty
 
 /*
  *  Binding class.
@@ -13,10 +14,10 @@ function Binding (seed, key) {
     this.key  = key
     var path = key.split('.')
     this.set(getValue(seed.scope, path))
-    this.defineAccessors(seed.scope, path)
+    this.def(seed.scope, path)
     this.instances    = []
-    this.dependents   = []
-    this.dependencies = []
+    this.subs   = []
+    this.deps = []
 }
 
 /*
@@ -33,7 +34,7 @@ Binding.prototype.set = function (value) {
     } else if (type === 'Array') {
         watchArray(value)
         value.on('mutate', function () {
-            self.emitChange()
+            self.pub()
         })
     }
     this.value = value
@@ -41,14 +42,15 @@ Binding.prototype.set = function (value) {
 
 /*
  *  Define getter/setter for this binding on scope
+ *  recursive for nested objects
  */
-Binding.prototype.defineAccessors = function (scope, path) {
+Binding.prototype.def = function (scope, path) {
     var self = this,
         key = path[0]
     if (path.length === 1) {
         // here we are! at the end of the path!
         // define the real value accessors.
-        Object.defineProperty(scope, key, {
+        def(scope, key, {
             get: function () {
                 if (observer.isObserving) {
                     observer.emit('get', self)
@@ -78,7 +80,7 @@ Binding.prototype.defineAccessors = function (scope, path) {
         var subScope = scope[key]
         if (!subScope) {
             subScope = {}
-            Object.defineProperty(scope, key, {
+            def(scope, key, {
                 get: function () {
                     return subScope
                 },
@@ -91,7 +93,8 @@ Binding.prototype.defineAccessors = function (scope, path) {
                 }
             })
         }
-        this.defineAccessors(subScope, path.slice(1))
+        // recurse
+        this.def(subScope, path.slice(1))
     }
 }
 
@@ -103,15 +106,15 @@ Binding.prototype.update = function (value) {
     this.instances.forEach(function (instance) {
         instance.update(value)
     })
-    this.emitChange()
+    this.pub()
 }
 
 /*
  *  Notify computed properties that depend on this binding
  *  to update themselves
  */
-Binding.prototype.emitChange = function () {
-    this.dependents.forEach(function (dept) {
+Binding.prototype.pub = function () {
+    this.subs.forEach(function (dept) {
         dept.refresh()
     })
 }

+ 4 - 4
src/deps-parser.js

@@ -11,7 +11,7 @@ var Emitter  = require('emitter'),
  */
 function catchDeps (binding) {
     observer.on('get', function (dep) {
-        binding.dependencies.push(dep)
+        binding.deps.push(dep)
     })
     binding.value.get()
     observer.off('get')
@@ -22,9 +22,9 @@ function catchDeps (binding) {
  *  Only include dependencies that don't have dependencies themselves.
  */
 function injectDeps (binding) {
-    binding.dependencies.forEach(function (dep) {
-        if (!dep.dependencies.length) {
-            dep.dependents.push.apply(dep.dependents, binding.instances)
+    binding.deps.forEach(function (dep) {
+        if (!dep.deps.length) {
+            dep.subs.push.apply(dep.subs, binding.instances)
         }
     })
 }

+ 1 - 1
src/directive-parser.js

@@ -56,7 +56,7 @@ Directive.prototype.refresh = function () {
         ? this.applyFilters(value)
         : value
     )
-    this.binding.emitChange()
+    this.binding.pub()
 }
 
 /*

+ 4 - 2
src/seed.js

@@ -169,6 +169,7 @@ Seed.prototype._bind = function (directive) {
     var key = directive.key,
         seed = directive.seed = this
 
+    // deal with each block
     if (this.each) {
         if (key.indexOf(this.eachPrefix) === 0) {
             key = directive.key = key.replace(this.eachPrefix, '')
@@ -177,7 +178,8 @@ Seed.prototype._bind = function (directive) {
         }
     }
 
-    seed = getScopeOwner(directive, seed)
+    // deal with nesting
+    seed = trace(directive, seed)
     var binding = seed._bindings[key] || seed._createBinding(key)
 
     // add directive to this binding
@@ -255,7 +257,7 @@ Seed.prototype._dump = function () {
 /*
  *  determine which scope a key belongs to based on nesting symbols
  */
-function getScopeOwner (key, seed) {
+function trace (key, seed) {
     if (key.nesting) {
         var levels = key.nesting
         while (seed.parentSeed && levels--) {