Compile sequence module as is.

This commit is contained in:
mmcwilliams 2019-10-11 17:53:41 -04:00
parent f1ab4ca1af
commit 591641774a
3 changed files with 94 additions and 104 deletions

View File

@ -1,11 +1,8 @@
'use strict'
const uuid = require('uuid').v4
const log = require('../log')('seq')
'use strict';
const uuid = require('uuid').v4;
const log = require('../log')('seq');
/** Object sequence features */
const sequence = {};
sequence._state = {
arr: [],
active: false,
@ -14,101 +11,93 @@ sequence._state = {
delay: false,
count: 0,
stop: null
}
};
sequence._loop = {
arr: [],
count: 0,
max: 0
}
};
sequence.start = function (options, cb) {
if (sequence._state.active) {
return false
return false;
}
sequence._state.active = true
sequence._state.count = 0
sequence._state.active = true;
sequence._state.count = 0;
if (options.arr) {
sequence._state.arr = options.arr
sequence._state.arr = options.arr;
}
if (options.loop) {
sequence._loop.arr = options.loop
sequence._loop.count = 0
sequence._loop.arr = options.loop;
sequence._loop.count = 0;
}
if (options.maxLoop) {
sequence._loop.max = options.maxLoop
} else {
sequence._loop.max = 0
sequence._loop.max = options.maxLoop;
}
sequence._state.stop = cb
sequence.step()
sequence._state.id = uuid()
return sequence._state.id
else {
sequence._loop.max = 0;
}
sequence._state.stop = cb;
sequence.step();
sequence._state.id = uuid();
return sequence._state.id;
};
sequence.setStop = function () {
sequence._state.active = false
}
sequence._state.active = false;
};
sequence.stop = function () {
sequence._state.active = false
sequence._state.count = 0
sequence._state.arr = []
sequence._loop.count = 0
sequence._loop.max = 0
sequence._loop.arr = []
if (sequence._state.stop) sequence._state.stop()
sequence._state.stop = null
}
sequence._state.active = false;
sequence._state.count = 0;
sequence._state.arr = [];
sequence._loop.count = 0;
sequence._loop.max = 0;
sequence._loop.arr = [];
if (sequence._state.stop)
sequence._state.stop();
sequence._state.stop = null;
};
sequence.pause = function () {
sequence._state.paused = true
}
sequence._state.paused = true;
};
sequence.resume = function () {
sequence._state.paused = false
sequence.step()
}
sequence._state.paused = false;
sequence.step();
};
sequence.step = function () {
if (sequence._state.active && !sequence._state.paused) {
if (sequence._state.arr.length > 0) {
if (sequence._state.count > sequence._state.arr.length - 1) {
return sequence.stop()
return sequence.stop();
}
log.info('step', { count : sequence._state.count, id : sequence._state.id })
log.info('step', { count: sequence._state.count, id: sequence._state.id });
return sequence._state.arr[sequence._state.count](() => {
sequence._state.count++
sequence.step()
})
} else if (sequence._loop.arr.length > 0) {
sequence._state.count++;
sequence.step();
});
}
else if (sequence._loop.arr.length > 0) {
if (sequence._state.count > sequence._loop.arr.length - 1) {
sequence._state.count = 0
sequence._loop.count++
sequence._state.count = 0;
sequence._loop.count++;
}
if (sequence._loop.max > 0 && sequence._loop.count > sequence._loop.max) {
return sequence.stop()
return sequence.stop();
}
log.info('step', { count : sequence._state.count, id : sequence._state.id })
log.info('step', { count: sequence._state.count, id: sequence._state.id });
return sequence._loop.arr[sequence._state.count](() => {
sequence._state.count++
sequence.step()
})
} else{
return sequence.stop()
sequence._state.count++;
sequence.step();
});
}
} else if (sequence._state.paused) {
log.info('step', 'Sequence paused', { loop : sequence._loop.count, count : sequence._state.count })
} else if (!sequence._state.active) {
log.info('step', 'Sequence stopped', { loop : sequence._loop.count, count : sequence._state.count })
else {
return sequence.stop();
}
}
module.exports = sequence
else if (sequence._state.paused) {
log.info('step', 'Sequence paused', { loop: sequence._loop.count, count: sequence._state.count });
}
else if (!sequence._state.active) {
log.info('step', 'Sequence stopped', { loop: sequence._loop.count, count: sequence._state.count });
}
};
module.exports = sequence;
//# sourceMappingURL=index.js.map

View File

@ -0,0 +1 @@
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/sequence/index.ts"],"names":[],"mappings":"AAAA,YAAY,CAAA;AAEZ,MAAM,IAAI,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC,EAAE,CAAA;AAC/B,MAAM,GAAG,GAAG,OAAO,CAAC,QAAQ,CAAC,CAAC,KAAK,CAAC,CAAA;AAEpC,+BAA+B;AAC/B,MAAM,QAAQ,GAAG,EAAE,CAAC;AAEpB,QAAQ,CAAC,MAAM,GAAG;I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