Store callback to invoke at the end of a sequence

This commit is contained in:
mmcw-dev 2017-12-20 21:24:51 -05:00
parent c7ed8bed3b
commit 64b0244972
1 changed files with 13 additions and 7 deletions

View File

@ -39,17 +39,20 @@ sequence.start = function (options, cb) {
} else {
sequence._loop.max = 0
}
sequence._state.stop = cb
sequence.step()
}
sequence.stop = function (next) {
sequence.setStop = function () {
sequence._state.active = false
}
sequence.stop = function () {
sequence._state.active = false
sequence._state.count = 0
sequence._loop.count = 0
console.dir(sequence._state.stop)
console.trace()
if (next) next()
if (sequence._state.stop) sequence._state.stop()
sequence._state.stop = null
}
sequence.pause = function () {
@ -63,12 +66,15 @@ sequence.resume = function () {
sequence.step = function () {
if (sequence._state.active && !sequence._state.paused) {
if (sequence._state.arr.length > 0 && typeof sequence._state.arr[sequence._state.count] !== 'undefined') {
if (sequence._state.arr.length > 0) {
if (sequence._state.count > sequence._state.arr.length) {
return sequence.stop()
}
return sequence._state.arr[sequence._state.count](() => {
sequence._state.count++
sequence.step()
})
} else if (sequence._loop.arr.length > 0 && typeof sequence._loop.arr[sequence._state.count] !== 'undefined') {
} else if (sequence._loop.arr.length > 0) {
if (sequence._state.count > sequence._loop.arr.length) {
sequence._state.count = 0
sequence._loop.count++