stricter check for computed properties

This commit is contained in:
Evan You 2013-08-13 13:20:49 -04:00
parent 829874eb5b
commit 5bfb4b5ef2
3 changed files with 11 additions and 8 deletions

View File

@ -28,7 +28,7 @@
<li <li
class="todo" class="todo"
sd-each="todo:todos" sd-each="todo:todos"
sd-show="filterTodo" sd-show="todoFiltered"
sd-class="completed:todo.completed, editing:todo.editing" sd-class="completed:todo.completed, editing:todo.editing"
> >
<div class="view"> <div class="view">
@ -56,9 +56,9 @@
<strong sd-text="remaining"></strong> {{remaining | pluralize item}} left <strong sd-text="remaining"></strong> {{remaining | pluralize item}} left
</span> </span>
<ul id="filters"> <ul id="filters">
<li><a href="#/all" sd-class="selected:checkFilter">All</a></li> <li><a href="#/all" sd-class="selected:filterSelected">All</a></li>
<li><a href="#/active" sd-class="selected:checkFilter">Active</a></li> <li><a href="#/active" sd-class="selected:filterSelected">Active</a></li>
<li><a href="#/completed" sd-class="selected:checkFilter">Completed</a></li> <li><a href="#/completed" sd-class="selected:filterSelected">Completed</a></li>
</ul> </ul>
<button id="clear-completed" sd-on="click:removeCompleted" sd-show="completed"> <button id="clear-completed" sd-on="click:removeCompleted" sd-show="completed">
Remove Completed ({{completed}}) Remove Completed ({{completed}})

View File

@ -16,12 +16,12 @@ Seed.controller('todos', function (scope) {
}} }}
// dynamic context computed property using info from target scope // dynamic context computed property using info from target scope
scope.filterTodo = {get: function (ctx) { scope.todoFiltered = {get: function (ctx) {
return filters[scope.filter](ctx.scope.completed) return filters[scope.filter](ctx.scope.completed)
}} }}
// dynamic context computed property using info from target element // dynamic context computed property using info from target element
scope.checkFilter = {get: function (ctx) { scope.filterSelected = {get: function (ctx) {
return scope.filter === ctx.el.textContent.toLowerCase() return scope.filter === ctx.el.textContent.toLowerCase()
}} }}

View File

@ -31,8 +31,11 @@ BindingProto.inspect = function (value) {
self = this self = this
// preprocess the value depending on its type // preprocess the value depending on its type
if (type === 'Object') { if (type === 'Object') {
if (value.get || value.set) { // computed property if (value.get) {
self.isComputed = true var l = Object.keys(value).length
if (l === 1 || (l === 2 && value.set)) {
self.isComputed = true // computed property
}
} }
} else if (type === 'Array') { } else if (type === 'Array') {
utils.watchArray(value) utils.watchArray(value)