Skip to content

Commit

Permalink
revert length back to count
Browse files Browse the repository at this point in the history
  • Loading branch information
weepy committed Apr 2, 2012
1 parent 9b57051 commit cd3e427
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 31 deletions.
4 changes: 2 additions & 2 deletions examples/todos/index.html
Expand Up @@ -15,7 +15,7 @@ <h1>Todos</h1>
<span class="ui-tooltip-top" data-bind="visible: showTooltip()" style="display: none;">Press Enter to save this task</span>
</div>
<div id="todos">
<div data-bind="visible: todos.length()">
<div data-bind="visible: todos.count()">
<input id="check-all" class="check" type="checkbox" data-bind="value: allCompleted" />
<label for="check-all">Mark all as complete</label>
</div>
Expand Down Expand Up @@ -49,7 +49,7 @@ <h1>Todos</h1>
</div>
</div>
<ul id="instructions">
<li data-bind="visible: todos.length()">Double-click to edit a todo.</li>
<li data-bind="visible: todos.count()">Double-click to edit a todo.</li>
</ul>
<div id="credits">
Created by
Expand Down
2 changes: 1 addition & 1 deletion examples/todos/js/todos.js
Expand Up @@ -76,7 +76,7 @@

//count of todos that are not complete
self.remainingCount = o_O(function () {
return self.todos.length() - self.completedCount();
return self.todos.count() - self.completedCount();
})

//writeable computed observable to handle marking all complete/incomplete
Expand Down
12 changes: 6 additions & 6 deletions o_O.js
Expand Up @@ -727,7 +727,7 @@ function array(models) {
if(this.constructor != array) return new array(models)

this.items = []
this.length = o_O(function(){
this.count = o_O(function(){
return self.items.length
})

Expand All @@ -748,7 +748,7 @@ function _add(col, o, index) {
}else{
col.emit('add', o, col, index)
}
col.length.incr()
col.count.incr()
return col.items.length
}

Expand All @@ -759,7 +759,7 @@ function _remove(col, o, index) {
} else {
col.emit('remove', o, index)
}
col.length.incr(-1) //force re-binding
col.count.incr(-1) //force re-binding
return o
}

Expand Down Expand Up @@ -788,7 +788,7 @@ proto.find = function(fn){
}

proto.map = proto.each = proto.forEach = function(fn) {
this.length(); // force the dependency
this.count(); // force the dependency
var ret = []
for(var i = 0; i < this.items.length; i++) {
var result = fn.call(this, this.items[i], i)
Expand Down Expand Up @@ -818,14 +818,14 @@ proto.at = function(index) {
}

proto.insert = function(o, index) {
if(index < 0 || index > this.length()) return false
if(index < 0 || index > this.count()) return false
this.items.splice(index, 0, o)
_add(this, o, index)
return o
}

proto.removeAt = function(index) {
if(index < 0 || index > this.length()) return false
if(index < 0 || index > this.count()) return false
var o = this.items[index]
this.items.splice(index, 1)
_remove(this, o, index)
Expand Down
8 changes: 4 additions & 4 deletions o_O.list.js
Expand Up @@ -11,7 +11,7 @@ function list(models) {
if(this.constructor != list) return new list(models)

this.objects = {}
this.length = o_O(0)
this.count = o_O(0)

o_O.eventize(this)
if(models) {
Expand Down Expand Up @@ -41,7 +41,7 @@ proto.add = function(o) {
else
this.emit('add', o)

this.length.incr()
this.count.incr()
}

proto._onevent = function(ev, o, list) {
Expand All @@ -65,7 +65,7 @@ proto.find = function(i) {
}

proto.each = proto.forEach = function(fn) {
this.length(); // force the dependency
this.count(); // force the dependency
for(var i in this.objects)
fn.call(this, this.find(i), i)
}
Expand All @@ -74,7 +74,7 @@ proto.remove = function(o) {
if(undefined === this.objects[o.id])
return
delete this.objects[o.id]
this.length.incr(-1)
this.count.incr(-1)

if(this == o.list) delete o.list
if(o.off) {
Expand Down
26 changes: 13 additions & 13 deletions test/test.array.js
Expand Up @@ -11,7 +11,7 @@ describe('an array', function() {
})

it('has a count of 0', function() {
expect(col.length()).to.be(0)
expect(col.count()).to.be(0)
})

describe('adding/removing', function() {
Expand All @@ -22,16 +22,16 @@ describe('an array', function() {
})

it('has a count of 1', function() {
expect(col.length()).to.be(1)
expect(col.count()).to.be(1)
})

it('handles the removal of an item it doesn\'t have gracefully', function() {
col.remove({foo: 'bar'})
expect(col.length()).to.be(1)
expect(col.count()).to.be(1)
})

it('increases count after add', function() {
expect(col.length()).to.be(1)
expect(col.count()).to.be(1)
})

it('triggers the *add* event after add', function() {
Expand All @@ -51,7 +51,7 @@ describe('an array', function() {

it('decreases count after remove', function() {
col.remove(obj)
expect(col.length()).to.be(0)
expect(col.count()).to.be(0)
})

it('triggers the *remove* event after remove', function() {
Expand Down Expand Up @@ -90,7 +90,7 @@ describe('an array', function() {
col.push(m)
col.push(m)

expect(col.length()).to.be(5)
expect(col.count()).to.be(5)
})

it('returns the removed item', function() {
Expand All @@ -113,7 +113,7 @@ describe('an array', function() {

it('decrements the count', function() {
col.shift()
expect(col.length()).to.be(2)
expect(col.count()).to.be(2)
})

it('removes an item from the front of the array', function() {
Expand All @@ -136,7 +136,7 @@ describe('an array', function() {
it('decrements the count', function() {
col.pop()

expect(col.length()).to.be(2)
expect(col.count()).to.be(2)
})

it('removes an item from the end of the array', function() {
Expand All @@ -158,7 +158,7 @@ describe('an array', function() {
})

it('increments the count', function() {
expect(col.length()).to.be(3)
expect(col.count()).to.be(3)
})

it('adds an item to the end of the array', function() {
Expand All @@ -179,7 +179,7 @@ describe('an array', function() {
})

it('increments the count', function() {
expect(col.length()).to.be(3)
expect(col.count()).to.be(3)
})

it('adds an item to the start of the array', function() {
Expand All @@ -199,7 +199,7 @@ describe('an array', function() {
})

it('increments the count', function() {
expect(col.length()).to.be(2)
expect(col.count()).to.be(2)
})

it('adds an item to the start of the array', function() {
Expand All @@ -216,7 +216,7 @@ describe('an array', function() {
it('fails if inserting to invalid place', function() {
expect(col.insert({}, -1)).to.be(false)
expect(col.insert({}, 4)).to.be(false)
expect(col.length()).to.be(2)
expect(col.count()).to.be(2)
})


Expand All @@ -235,7 +235,7 @@ describe('an array', function() {

it('decrements the count', function() {
col.removeAt(0)
expect(col.length()).to.be(2)
expect(col.count()).to.be(2)
})

it('removes the item to the start of the array', function() {
Expand Down
10 changes: 5 additions & 5 deletions test/test.list.js
Expand Up @@ -11,7 +11,7 @@ describe('a list', function() {
})

it('has a count of 0', function() {
expect(col.length()).to.be(0)
expect(col.count()).to.be(0)
})

describe('adding/removing', function() {
Expand All @@ -22,16 +22,16 @@ describe('a list', function() {
})

it('has a count of 1', function() {
expect(col.length()).to.be(1)
expect(col.count()).to.be(1)
})

it('handles the removal of an item it doesn\'t have gracefully', function() {
col.remove({foo: 'bar'})
expect(col.length()).to.be(1)
expect(col.count()).to.be(1)
})

it('increases count after add', function() {
expect(col.length()).to.be(1)
expect(col.count()).to.be(1)
})

it('triggers the *add* event after add', function() {
Expand All @@ -51,7 +51,7 @@ describe('a list', function() {

it('decreases count after remove', function() {
col.remove(obj)
expect(col.length()).to.be(0)
expect(col.count()).to.be(0)
})

it('triggers the *remove* event after remove', function() {
Expand Down

0 comments on commit cd3e427

Please sign in to comment.