-
Notifications
You must be signed in to change notification settings - Fork 0
/
dance.js
63 lines (44 loc) · 1.53 KB
/
dance.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
var DanceJs = function () {
this.stacks = {}
}
DanceJs.prototype = {
constructor: DanceJs,
err: function (msg) {
return console.error(msg)
},
step: function (notation, steps) {
if (!notation) {
return this.err('Please insert notation name')
}
if (typeof notation != 'string') {
return this.err('Please set notation as string')
}
if (!this.stacks[notation]) {
this.stacks[notation] = {
steps: {}
}
}
var notationNames = Object.keys(steps)
for (var i = 0; i < notationNames.length; i++) {
this.stacks[notation].steps[notationNames[i]] = steps[notationNames[i]]
}
return this
},
letRoll: function (notation, firstRun) {
if (!this.stacks[notation]) {
return this.err('No ' + notation + ' name, please add step by step([step name], [steps])')
}
var notationNames = Object.keys(this.stacks[notation].steps)
var next = function (nextStepName, data) {
var nextStep = this.stacks[notation].steps[nextStepName]
if (typeof nextStep !== 'function') {
return
}
this.stacks[notation].steps[nextStepName](next, data)
}.bind(this)
if (this.stacks[notation].steps[firstRun] == 'string') {
return this.stacks[notation].steps[firstRun](next)
}
this.stacks[notation].steps[notationNames[0]](next)
}
}