Permalink
Browse files

New push and unshift; Write as an alias of push

  • Loading branch information...
wdavidw committed Mar 28, 2013
1 parent 24ff019 commit f430da6fabe9a050cd7b92723bb82e42684f0a15
Showing with 59 additions and 6 deletions.
  1. +16 −1 lib/each.js
  2. +11 −1 src/each.coffee
  3. +5 −4 test/{write.coffee → push.coffee}
  4. +27 −0 test/unshift.coffee
View

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.
View
@@ -44,7 +44,7 @@ module.exports = (elements) ->
eacher.paused = 0
eacher.readable = true
end = false
- eacher.write = (item) ->
+ eacher.write = eacher.push = (item) ->
l = arguments.length
if l is 1
elements.push arguments[0]
@@ -54,6 +54,16 @@ module.exports = (elements) ->
elements[arguments[0]] = arguments[1]
eacher.total++
eacher
+ eacher.unshift = (item) ->
+ l = arguments.length
+ if l is 1
+ elements.unshift arguments[0]
+ else if l is 2
+ keys = [] if not keys
+ keys.unshift arguments[0]
+ elements[arguments[0]] = arguments[1]
+ eacher.total++
+ eacher
eacher.pause = ->
eacher.paused++
eacher.resume = ->
@@ -1,13 +1,14 @@
+
should = require 'should'
each = if process.env.EACH_COV then require '../lib-cov/each' else require '../lib/each'
describe 'Write', ->
it 'accept array elements', (next) ->
each()
- .write('hello')
- .write('each')
+ .push('hello')
+ .push('each')
.on 'item', (item, index, next) ->
item.should.eql 'hello' if index is 0
next()
@@ -17,8 +18,8 @@ describe 'Write', ->
it 'accept key value elements', (next) ->
each()
- .write('hello', 'each')
- .write('youre', 'welcome')
+ .push('hello', 'each')
+ .push('youre', 'welcome')
.on 'item', (key, value, next) ->
value.should.eql 'each' if key is 'hello'
next()
View
@@ -0,0 +1,27 @@
+
+should = require 'should'
+each = if process.env.EACH_COV then require '../lib-cov/each' else require '../lib/each'
+
+describe 'Unshift', ->
+
+ it 'accept array elements', (next) ->
+ each()
+ .unshift('hello')
+ .unshift('each')
+ .on 'item', (item, index, next) ->
+ item.should.eql 'each' if index is 0
+ next()
+ .on 'end', (count) ->
+ count.should.eql 2
+ next()
+
+ it 'accept key value elements', (next) ->
+ each()
+ .unshift('hello', 'each')
+ .unshift('youre', 'welcome')
+ .on 'item', (key, value, next) ->
+ value.should.eql 'welcome' if key is 'youre'
+ next()
+ .on 'end', (count) ->
+ count.should.eql 2
+ next()

0 comments on commit f430da6

Please sign in to comment.