Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

change api to .prev() / .next()

  • Loading branch information...
commit b47877ba0889b4b98b5a3e631f3bb4c49139867c 1 parent 46096c0
@tj tj authored
Showing with 44 additions and 44 deletions.
  1. +2 −2 Readme.md
  2. +2 −2 index.js
  3. +40 −40 test/history.js
View
4 Readme.md
@@ -21,11 +21,11 @@ $ component install component/history
This method resets the history index, meaning the next call
to `.back()` will be this latest value.
-### History#back()
+### History#prev()
Cycle backwards through history, returning a value added by `.add()`.
-### History#back()
+### History#next()
Cycle forwards through history, returning a value added by `.add()`.
View
4 index.js
@@ -68,7 +68,7 @@ History.prototype.add = function(val){
* @api public
*/
-History.prototype.back = function(){
+History.prototype.prev = function(){
if (this.i < 0) return;
return this.vals[this.i--];
};
@@ -80,7 +80,7 @@ History.prototype.back = function(){
* @api public
*/
-History.prototype.forward = function(){
+History.prototype.next = function(){
var len = this.vals.length;
if (this.i == len - 1) return;
return this.vals[++this.i];
View
80 test/history.js
@@ -6,9 +6,9 @@ describe('History', function(){
describe('(arr)', function(){
it('should populate the history', function(){
var history = new History(['foo', 'bar', 'baz']);
- history.back().should.equal('baz');
- history.back().should.equal('bar');
- history.back().should.equal('foo');
+ history.prev().should.equal('baz');
+ history.prev().should.equal('bar');
+ history.prev().should.equal('foo');
})
})
@@ -18,9 +18,9 @@ describe('History', function(){
history.add('foo');
history.add('bar');
history.add('baz');
- history.back().should.equal('baz');
- history.back().should.equal('bar');
- history.back().should.equal('foo');
+ history.prev().should.equal('baz');
+ history.prev().should.equal('bar');
+ history.prev().should.equal('foo');
})
it('should reset the index', function(){
@@ -28,61 +28,61 @@ describe('History', function(){
history.add('foo');
history.add('bar');
history.add('baz');
- history.back().should.equal('baz');
- history.back().should.equal('bar');
+ history.prev().should.equal('baz');
+ history.prev().should.equal('bar');
history.add('hey');
- history.back().should.equal('hey');
- history.back().should.equal('baz');
- history.back().should.equal('bar');
+ history.prev().should.equal('hey');
+ history.prev().should.equal('baz');
+ history.prev().should.equal('bar');
})
})
- describe('.back()', function(){
+ describe('.prev()', function(){
it('should cycle through the history', function(){
var history = new History;
history.add('foo');
history.add('bar');
history.add('baz');
- history.back().should.equal('baz');
- history.back().should.equal('bar');
- history.back().should.equal('foo');
+ history.prev().should.equal('baz');
+ history.prev().should.equal('bar');
+ history.prev().should.equal('foo');
})
it('should cap the index', function(){
var history = new History;
history.add('foo');
- history.back().should.equal('foo');
- history.back();
- history.back();
- history.back();
- history.back();
- history.forward().should.equal('foo');
+ history.prev().should.equal('foo');
+ history.prev();
+ history.prev();
+ history.prev();
+ history.prev();
+ history.next().should.equal('foo');
})
})
- describe('.forward()', function(){
+ describe('.next()', function(){
it('should cycle through the history', function(){
var history = new History;
history.add('foo');
history.add('bar');
history.add('baz');
- history.back().should.equal('baz');
- history.back().should.equal('bar');
- history.back().should.equal('foo');
- history.forward().should.equal('foo');
- history.forward().should.equal('bar');
- history.forward().should.equal('baz');
+ history.prev().should.equal('baz');
+ history.prev().should.equal('bar');
+ history.prev().should.equal('foo');
+ history.next().should.equal('foo');
+ history.next().should.equal('bar');
+ history.next().should.equal('baz');
})
it('should cap the index', function(){
var history = new History;
history.add('foo');
- history.forward();
- history.forward();
- history.forward();
- history.forward();
- history.forward();
- history.back().should.equal('foo');
+ history.next();
+ history.next();
+ history.next();
+ history.next();
+ history.next();
+ history.prev().should.equal('foo');
})
})
@@ -94,14 +94,14 @@ describe('History', function(){
history.add('bar');
history.add('baz');
- history.back().should.equal('baz');
- history.back().should.equal('bar');
- assert(null == history.back());
+ history.prev().should.equal('baz');
+ history.prev().should.equal('bar');
+ assert(null == history.prev());
history.add('raz');
- history.back().should.equal('raz');
- history.back().should.equal('baz');
- assert(null == history.back());
+ history.prev().should.equal('raz');
+ history.prev().should.equal('baz');
+ assert(null == history.prev());
})
})
})
Please sign in to comment.
Something went wrong with that request. Please try again.