Forráskód Böngészése

computed properties now use $get and $set to be more explicit

Evan You 12 éve
szülő
commit
f87f603d03

+ 2 - 2
examples/todomvc/js/app.js

@@ -75,10 +75,10 @@ var app = new Seed({
         },
         },
 
 
         allDone: {
         allDone: {
-            get: function () {
+            $get: function () {
                 return this.remaining === 0
                 return this.remaining === 0
             },
             },
-            set: function (value) {
+            $set: function (value) {
                 this.todos.forEach(function (todo) {
                 this.todos.forEach(function (todo) {
                     todo.completed = value
                     todo.completed = value
                 })
                 })

+ 7 - 7
src/compiler.js

@@ -429,7 +429,7 @@ CompilerProto.createBinding = function (key, isExp, isFn) {
             log('  created anonymous binding: ' + key)
             log('  created anonymous binding: ' + key)
             binding.value = isFn
             binding.value = isFn
                 ? result.getter
                 ? result.getter
-                : { get: result.getter }
+                : { $get: result.getter }
             compiler.markComputed(binding)
             compiler.markComputed(binding)
             compiler.exps.push(binding)
             compiler.exps.push(binding)
             // need to create the bindings for keys
             // need to create the bindings for keys
@@ -500,7 +500,7 @@ CompilerProto.define = function (key, binding) {
         value = binding.value = vm[key], // save the value before redefinening it
         value = binding.value = vm[key], // save the value before redefinening it
         type = utils.typeOf(value)
         type = utils.typeOf(value)
 
 
-    if (type === 'Object' && value.get) {
+    if (type === 'Object' && value.$get) {
         // computed property
         // computed property
         compiler.markComputed(binding)
         compiler.markComputed(binding)
     } else if (type === 'Object' || type === 'Array') {
     } else if (type === 'Object' || type === 'Array') {
@@ -521,14 +521,14 @@ CompilerProto.define = function (key, binding) {
                 ob.emit('get', key)
                 ob.emit('get', key)
             }
             }
             return binding.isComputed
             return binding.isComputed
-                ? value.get()
+                ? value.$get()
                 : value
                 : value
         },
         },
         set: function (newVal) {
         set: function (newVal) {
             var value = binding.value
             var value = binding.value
             if (binding.isComputed) {
             if (binding.isComputed) {
-                if (value.set) {
-                    value.set(newVal)
+                if (value.$set) {
+                    value.$set(newVal)
                 }
                 }
             } else if (newVal !== value) {
             } else if (newVal !== value) {
                 // unwatch the old value
                 // unwatch the old value
@@ -555,8 +555,8 @@ CompilerProto.markComputed = function (binding) {
     if (binding.isFn) {
     if (binding.isFn) {
         binding.value = value.bind(vm)
         binding.value = value.bind(vm)
     } else {
     } else {
-        value.get = value.get.bind(vm)
-        if (value.set) value.set = value.set.bind(vm)
+        value.$get = value.$get.bind(vm)
+        if (value.$set) value.$set = value.$set.bind(vm)
     }
     }
     // keep track for dep parsing later
     // keep track for dep parsing later
     this.computed.push(binding)
     this.computed.push(binding)

+ 1 - 1
src/deps-parser.js

@@ -17,7 +17,7 @@ function catchDeps (binding) {
         binding.deps.push(dep)
         binding.deps.push(dep)
         dep.subs.push(binding)
         dep.subs.push(binding)
     })
     })
-    binding.value.get()
+    binding.value.$get()
     observer.off('get')
     observer.off('get')
 }
 }
 
 

+ 1 - 1
src/directive.js

@@ -146,7 +146,7 @@ DirProto.refresh = function (value) {
     if (this.isFn) {
     if (this.isFn) {
         value = this.value
         value = this.value
     } else {
     } else {
-        value = this.value.get({
+        value = this.value.$get({
             el: this.el,
             el: this.el,
             vm: this.vm
             vm: this.vm
         })
         })

+ 5 - 3
test/functional/fixtures/nested-props.html

@@ -44,9 +44,11 @@
                         this.a.b.c = 'three'
                         this.a.b.c = 'three'
                         this.a.c = 3
                         this.a.c = 3
                     },
                     },
-                    d: {get: function () {
-                        return this.msg + (this.a.b.c || '') + (this.a.c || '')
-                    }}
+                    d: {
+                        $get: function () {
+                            return this.msg + (this.a.b.c || '') + (this.a.c || '')
+                        }
+                    }
                 }
                 }
             })
             })
             var app = new Demo({ el: '#a' })
             var app = new Demo({ el: '#a' })

+ 1 - 1
test/functional/fixtures/share-data.html

@@ -43,7 +43,7 @@
                 scope: {
                 scope: {
                     shared: shared,
                     shared: shared,
                     source: {
                     source: {
-                        get: function () {
+                        $get: function () {
                             return JSON.stringify(this.shared)
                             return JSON.stringify(this.shared)
                         }
                         }
                     }
                     }

+ 1 - 1
test/unit/specs/deps-parser.js

@@ -18,7 +18,7 @@ describe('UNIT: Dependency Parser', function () {
                 deps: [],
                 deps: [],
                 subs: [],
                 subs: [],
                 value: {
                 value: {
-                    get: function () {
+                    $get: function () {
                         if (i > 0) {
                         if (i > 0) {
                             ob.emit('get', bindings[b.depId])
                             ob.emit('get', bindings[b.depId])
                         }
                         }

+ 1 - 1
test/unit/specs/directive.js

@@ -223,7 +223,7 @@ describe('UNIT: Directive', function () {
             applied = false,
             applied = false,
             el = 1, vm = 2,
             el = 1, vm = 2,
             value = {
             value = {
-                get: function (ctx) {
+                $get: function (ctx) {
                     return ctx.el + ctx.vm
                     return ctx.el + ctx.vm
                 }
                 }
             }
             }