Skip to content

Commit e704538

Browse files
committed
fix babel export default problem
1 parent 8b3d322 commit e704538

File tree

2 files changed

+46
-40
lines changed

2 files changed

+46
-40
lines changed

lib/main.js

Lines changed: 5 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,45 +1,10 @@
1-
import { bindAsync } from 'run-callback'
1+
import { first, last, run } from './run'
22

3-
export var last = {}
4-
export var first = {}
5-
6-
export default function () {
3+
export default function sequence() {
74
return run.bind(null, arguments)
85
}
96

10-
export function run(things, initial, done) {
11-
if (arguments.length < 3) {
12-
if (typeof initial === 'function') {
13-
done = initial
14-
initial = null
15-
}
16-
}
17-
18-
next(things, initial, done || function () {}, [], 0)
19-
}
20-
21-
function next(things, initial, done, res, i) {
22-
if (i >= things.length) {
23-
return done(null, res)
24-
}
25-
bind(things[i], res, initial)((err, r) => {
26-
if (err) {
27-
return done(err, res)
28-
}
29-
res.push(r)
30-
next(things, initial, done, res, ++i)
31-
})
32-
}
33-
34-
function bind(fn, res, initial) {
35-
return bindAsync.apply(null, [].concat(fn).map((j) => {
36-
if (j === last) {
37-
return res.length === 0 ? initial : res[res.length - 1]
38-
}
39-
if (j === first) {
40-
return initial == null ? res[0] : initial
41-
}
42-
return j
43-
}))
44-
}
7+
sequence.last = last
8+
sequence.first = first
9+
sequence.run = run
4510

lib/run.js

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
import { bindAsync } from 'run-callback'
2+
3+
export var last = {}
4+
export var first = {}
5+
6+
export function run(things, initial, done) {
7+
if (arguments.length < 3) {
8+
if (typeof initial === 'function') {
9+
done = initial
10+
initial = null
11+
}
12+
}
13+
14+
next(things, initial, done || function () {}, [], 0)
15+
}
16+
17+
function next(things, initial, done, res, i) {
18+
if (i >= things.length) {
19+
return done(null, res)
20+
}
21+
bind(things[i], res, initial)((err, r) => {
22+
if (err) {
23+
return done(err, res)
24+
}
25+
res.push(r)
26+
next(things, initial, done, res, ++i)
27+
})
28+
}
29+
30+
function bind(fn, res, initial) {
31+
return bindAsync.apply(null, [].concat(fn).map((j) => {
32+
if (j === last) {
33+
return res.length === 0 ? initial : res[res.length - 1]
34+
}
35+
if (j === first) {
36+
return initial == null ? res[0] : initial
37+
}
38+
return j
39+
}))
40+
}
41+

0 commit comments

Comments
 (0)