Skip to content

Commit f87f603

Browse files
author
Evan You
committed
computed properties now use $get and $set to be more explicit
1 parent f772e84 commit f87f603

File tree

8 files changed

+19
-17
lines changed

8 files changed

+19
-17
lines changed

examples/todomvc/js/app.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,10 +75,10 @@ var app = new Seed({
7575
},
7676

7777
allDone: {
78-
get: function () {
78+
$get: function () {
7979
return this.remaining === 0
8080
},
81-
set: function (value) {
81+
$set: function (value) {
8282
this.todos.forEach(function (todo) {
8383
todo.completed = value
8484
})

src/compiler.js

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -429,7 +429,7 @@ CompilerProto.createBinding = function (key, isExp, isFn) {
429429
log(' created anonymous binding: ' + key)
430430
binding.value = isFn
431431
? result.getter
432-
: { get: result.getter }
432+
: { $get: result.getter }
433433
compiler.markComputed(binding)
434434
compiler.exps.push(binding)
435435
// need to create the bindings for keys
@@ -500,7 +500,7 @@ CompilerProto.define = function (key, binding) {
500500
value = binding.value = vm[key], // save the value before redefinening it
501501
type = utils.typeOf(value)
502502

503-
if (type === 'Object' && value.get) {
503+
if (type === 'Object' && value.$get) {
504504
// computed property
505505
compiler.markComputed(binding)
506506
} else if (type === 'Object' || type === 'Array') {
@@ -521,14 +521,14 @@ CompilerProto.define = function (key, binding) {
521521
ob.emit('get', key)
522522
}
523523
return binding.isComputed
524-
? value.get()
524+
? value.$get()
525525
: value
526526
},
527527
set: function (newVal) {
528528
var value = binding.value
529529
if (binding.isComputed) {
530-
if (value.set) {
531-
value.set(newVal)
530+
if (value.$set) {
531+
value.$set(newVal)
532532
}
533533
} else if (newVal !== value) {
534534
// unwatch the old value
@@ -555,8 +555,8 @@ CompilerProto.markComputed = function (binding) {
555555
if (binding.isFn) {
556556
binding.value = value.bind(vm)
557557
} else {
558-
value.get = value.get.bind(vm)
559-
if (value.set) value.set = value.set.bind(vm)
558+
value.$get = value.$get.bind(vm)
559+
if (value.$set) value.$set = value.$set.bind(vm)
560560
}
561561
// keep track for dep parsing later
562562
this.computed.push(binding)

src/deps-parser.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ function catchDeps (binding) {
1717
binding.deps.push(dep)
1818
dep.subs.push(binding)
1919
})
20-
binding.value.get()
20+
binding.value.$get()
2121
observer.off('get')
2222
}
2323

src/directive.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ DirProto.refresh = function (value) {
146146
if (this.isFn) {
147147
value = this.value
148148
} else {
149-
value = this.value.get({
149+
value = this.value.$get({
150150
el: this.el,
151151
vm: this.vm
152152
})

test/functional/fixtures/nested-props.html

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,11 @@ <h3>Computed property that concats the two: <span sd-text="d"></span></h3>
4444
this.a.b.c = 'three'
4545
this.a.c = 3
4646
},
47-
d: {get: function () {
48-
return this.msg + (this.a.b.c || '') + (this.a.c || '')
49-
}}
47+
d: {
48+
$get: function () {
49+
return this.msg + (this.a.b.c || '') + (this.a.c || '')
50+
}
51+
}
5052
}
5153
})
5254
var app = new Demo({ el: '#a' })

test/functional/fixtures/share-data.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@
4343
scope: {
4444
shared: shared,
4545
source: {
46-
get: function () {
46+
$get: function () {
4747
return JSON.stringify(this.shared)
4848
}
4949
}

test/unit/specs/deps-parser.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ describe('UNIT: Dependency Parser', function () {
1818
deps: [],
1919
subs: [],
2020
value: {
21-
get: function () {
21+
$get: function () {
2222
if (i > 0) {
2323
ob.emit('get', bindings[b.depId])
2424
}

test/unit/specs/directive.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,7 @@ describe('UNIT: Directive', function () {
223223
applied = false,
224224
el = 1, vm = 2,
225225
value = {
226-
get: function (ctx) {
226+
$get: function (ctx) {
227227
return ctx.el + ctx.vm
228228
}
229229
}

0 commit comments

Comments
 (0)