collect-your-stuff 1.2.7 → 1.2.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2525 -2525
- package/browser/collect-your-stuff.js +22766 -22761
- package/browser/collect-your-stuff.min.js +1 -1
- package/dist/collections/arrayable/ArrayElement.d.ts +36 -36
- package/dist/collections/arrayable/ArrayElement.js +64 -64
- package/dist/collections/arrayable/Arrayable.d.ts +108 -108
- package/dist/collections/arrayable/Arrayable.js +188 -188
- package/dist/collections/doubly-linked-list/DoubleLinker.d.ts +46 -46
- package/dist/collections/doubly-linked-list/DoubleLinker.js +69 -69
- package/dist/collections/doubly-linked-list/DoublyLinkedList.d.ts +113 -113
- package/dist/collections/doubly-linked-list/DoublyLinkedList.js +274 -269
- package/dist/collections/doubly-linked-list/DoublyLinkedList.min.js +1 -1
- package/dist/collections/linked-list/LinkedList.d.ts +109 -109
- package/dist/collections/linked-list/LinkedList.js +233 -233
- package/dist/collections/linked-list/Linker.d.ts +43 -43
- package/dist/collections/linked-list/Linker.js +80 -80
- package/dist/collections/linked-tree-list/LinkedTreeList.d.ts +135 -135
- package/dist/collections/linked-tree-list/LinkedTreeList.js +252 -252
- package/dist/collections/linked-tree-list/TreeLinker.d.ts +63 -63
- package/dist/collections/linked-tree-list/TreeLinker.js +79 -79
- package/dist/collections/queue/Queue.d.ts +63 -63
- package/dist/collections/queue/Queue.js +130 -130
- package/dist/collections/queue/Queueable.d.ts +77 -77
- package/dist/collections/queue/Queueable.js +141 -141
- package/dist/collections/stack/Stack.d.ts +63 -63
- package/dist/collections/stack/Stack.js +106 -106
- package/dist/collections/stack/Stackable.d.ts +56 -56
- package/dist/collections/stack/Stackable.js +83 -83
- package/dist/main.d.ts +40 -40
- package/dist/main.js +50 -50
- package/dist/recipes/ArrayIterator.d.ts +10 -10
- package/dist/recipes/ArrayIterator.js +29 -29
- package/dist/recipes/DoubleLinkerIterator.d.ts +9 -9
- package/dist/recipes/DoubleLinkerIterator.js +24 -24
- package/dist/recipes/IsArrayable.d.ts +105 -105
- package/dist/recipes/IsArrayable.js +5 -5
- package/dist/recipes/IsDoubleLinker.d.ts +14 -14
- package/dist/recipes/IsDoubleLinker.js +5 -5
- package/dist/recipes/IsElement.d.ts +14 -14
- package/dist/recipes/IsElement.js +5 -5
- package/dist/recipes/IsLinker.d.ts +10 -10
- package/dist/recipes/IsLinker.js +5 -5
- package/dist/recipes/IsTree.d.ts +11 -11
- package/dist/recipes/IsTree.js +5 -5
- package/dist/recipes/IsTreeNode.d.ts +29 -29
- package/dist/recipes/IsTreeNode.js +5 -5
- package/dist/recipes/LinkerIterator.d.ts +9 -9
- package/dist/recipes/LinkerIterator.js +24 -24
- package/dist/recipes/Runnable.d.ts +54 -54
- package/dist/recipes/Runnable.js +68 -68
- package/dist/recipes/TreeLinkerIterator.d.ts +9 -9
- package/dist/recipes/TreeLinkerIterator.js +25 -25
- package/dist/recipes/recipes.d.ts +15 -15
- package/dist/recipes/recipes.js +22 -22
- package/dist/services/parseTree.d.ts +9 -9
- package/dist/services/parseTree.js +24 -24
- package/dist/services/parseTreeNext.d.ts +14 -14
- package/dist/services/parseTreeNext.js +47 -47
- package/dist/services/services.d.ts +13 -13
- package/dist/services/services.js +22 -22
- package/package.json +1 -1
|
@@ -1,77 +1,77 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @file queueable item.
|
|
3
|
-
* @author Joshua Heagle <joshuaheagle@gmail.com>
|
|
4
|
-
* @version 1.1.0
|
|
5
|
-
* @memberOf module:collect-your-stuff
|
|
6
|
-
*/
|
|
7
|
-
import { completeResponse, IsRunnable } from '../../recipes/Runnable';
|
|
8
|
-
import { IsLinker } from '../../recipes/IsLinker';
|
|
9
|
-
/**
|
|
10
|
-
* Queueable represents a runnable entry in a queue.
|
|
11
|
-
* @extends Linker
|
|
12
|
-
*/
|
|
13
|
-
export declare class Queueable implements IsLinker, IsRunnable {
|
|
14
|
-
readonly classType: typeof Queueable;
|
|
15
|
-
data: any;
|
|
16
|
-
next: Queueable | null;
|
|
17
|
-
complete: boolean;
|
|
18
|
-
ready: Function | boolean;
|
|
19
|
-
running: boolean;
|
|
20
|
-
/**
|
|
21
|
-
* Create a queueable item that can be used in a queue.
|
|
22
|
-
* @param {Object} [queueableData={}]
|
|
23
|
-
* @param {*} [queueableData.task=null] The data to be stored in this queueable
|
|
24
|
-
* @param {Queueable|null} [queueableData.next=null] The reference to the next queueable if any
|
|
25
|
-
* @param {boolean|Function} [queueableData.ready=false] Indicate if the queueable is ready to run
|
|
26
|
-
*/
|
|
27
|
-
constructor({ task, next, ready }?: {
|
|
28
|
-
task?: any;
|
|
29
|
-
next?: Queueable | null;
|
|
30
|
-
ready?: boolean;
|
|
31
|
-
});
|
|
32
|
-
/**
|
|
33
|
-
* Check ready state.
|
|
34
|
-
* @return {boolean}
|
|
35
|
-
*/
|
|
36
|
-
get isReady(): boolean;
|
|
37
|
-
/**
|
|
38
|
-
* Retrieve the data which should be formed as a task.
|
|
39
|
-
* @return {*}
|
|
40
|
-
*/
|
|
41
|
-
get task(): any;
|
|
42
|
-
/**
|
|
43
|
-
* Set this queueable as completed.
|
|
44
|
-
* @param {Object} completeResponse
|
|
45
|
-
* @param {*} [completeResponse.success=true] Indicate when the task failed (use false) or give a success message
|
|
46
|
-
* @param {*} [completeResponse.error=false] Indicate a task was error-free (use false) or give an error message
|
|
47
|
-
* @param {*} [completeResponse.context=null] Provide additional data in the response
|
|
48
|
-
* @return {completeResponse}
|
|
49
|
-
*/
|
|
50
|
-
markCompleted({ success, error, context }?: {
|
|
51
|
-
success?: any;
|
|
52
|
-
error?: any;
|
|
53
|
-
context?: any;
|
|
54
|
-
}): completeResponse;
|
|
55
|
-
/**
|
|
56
|
-
* Intend to run the queued task when it is ready. If ready, mark this task as running and run the task.
|
|
57
|
-
* @return {completeResponse}
|
|
58
|
-
*/
|
|
59
|
-
run(): completeResponse;
|
|
60
|
-
/**
|
|
61
|
-
* Make a new Queueable from the data given if it is not already a valid Queueable.
|
|
62
|
-
* @param {Queueable|*} queueable Return a valid Queueable instance from given data, or even an already valid one.
|
|
63
|
-
* @param {IsLinker} [classType=Queueable] Provide the type of IsLinker to use.
|
|
64
|
-
* @return {Queueable}
|
|
65
|
-
*/
|
|
66
|
-
static make: (queueable: Queueable | any, classType?: any) => IsLinker;
|
|
67
|
-
/**
|
|
68
|
-
* Convert an array into Queueable instances, return the head and tail Queueables.
|
|
69
|
-
* @param {Array} values Provide an array of data that will be converted to a chain of queueable linkers.
|
|
70
|
-
* @param {IsLinker} [classType=Queueable] Provide the type of IsLinker to use.
|
|
71
|
-
* @returns {{head: Queueable, tail: Queueable}}
|
|
72
|
-
*/
|
|
73
|
-
static fromArray: (values: Array<any>, classType?: any) => {
|
|
74
|
-
head: IsLinker;
|
|
75
|
-
tail: IsLinker;
|
|
76
|
-
};
|
|
77
|
-
}
|
|
1
|
+
/**
|
|
2
|
+
* @file queueable item.
|
|
3
|
+
* @author Joshua Heagle <joshuaheagle@gmail.com>
|
|
4
|
+
* @version 1.1.0
|
|
5
|
+
* @memberOf module:collect-your-stuff
|
|
6
|
+
*/
|
|
7
|
+
import { completeResponse, IsRunnable } from '../../recipes/Runnable';
|
|
8
|
+
import { IsLinker } from '../../recipes/IsLinker';
|
|
9
|
+
/**
|
|
10
|
+
* Queueable represents a runnable entry in a queue.
|
|
11
|
+
* @extends Linker
|
|
12
|
+
*/
|
|
13
|
+
export declare class Queueable implements IsLinker, IsRunnable {
|
|
14
|
+
readonly classType: typeof Queueable;
|
|
15
|
+
data: any;
|
|
16
|
+
next: Queueable | null;
|
|
17
|
+
complete: boolean;
|
|
18
|
+
ready: Function | boolean;
|
|
19
|
+
running: boolean;
|
|
20
|
+
/**
|
|
21
|
+
* Create a queueable item that can be used in a queue.
|
|
22
|
+
* @param {Object} [queueableData={}]
|
|
23
|
+
* @param {*} [queueableData.task=null] The data to be stored in this queueable
|
|
24
|
+
* @param {Queueable|null} [queueableData.next=null] The reference to the next queueable if any
|
|
25
|
+
* @param {boolean|Function} [queueableData.ready=false] Indicate if the queueable is ready to run
|
|
26
|
+
*/
|
|
27
|
+
constructor({ task, next, ready }?: {
|
|
28
|
+
task?: any;
|
|
29
|
+
next?: Queueable | null;
|
|
30
|
+
ready?: boolean;
|
|
31
|
+
});
|
|
32
|
+
/**
|
|
33
|
+
* Check ready state.
|
|
34
|
+
* @return {boolean}
|
|
35
|
+
*/
|
|
36
|
+
get isReady(): boolean;
|
|
37
|
+
/**
|
|
38
|
+
* Retrieve the data which should be formed as a task.
|
|
39
|
+
* @return {*}
|
|
40
|
+
*/
|
|
41
|
+
get task(): any;
|
|
42
|
+
/**
|
|
43
|
+
* Set this queueable as completed.
|
|
44
|
+
* @param {Object} completeResponse
|
|
45
|
+
* @param {*} [completeResponse.success=true] Indicate when the task failed (use false) or give a success message
|
|
46
|
+
* @param {*} [completeResponse.error=false] Indicate a task was error-free (use false) or give an error message
|
|
47
|
+
* @param {*} [completeResponse.context=null] Provide additional data in the response
|
|
48
|
+
* @return {completeResponse}
|
|
49
|
+
*/
|
|
50
|
+
markCompleted({ success, error, context }?: {
|
|
51
|
+
success?: any;
|
|
52
|
+
error?: any;
|
|
53
|
+
context?: any;
|
|
54
|
+
}): completeResponse;
|
|
55
|
+
/**
|
|
56
|
+
* Intend to run the queued task when it is ready. If ready, mark this task as running and run the task.
|
|
57
|
+
* @return {completeResponse}
|
|
58
|
+
*/
|
|
59
|
+
run(): completeResponse;
|
|
60
|
+
/**
|
|
61
|
+
* Make a new Queueable from the data given if it is not already a valid Queueable.
|
|
62
|
+
* @param {Queueable|*} queueable Return a valid Queueable instance from given data, or even an already valid one.
|
|
63
|
+
* @param {IsLinker} [classType=Queueable] Provide the type of IsLinker to use.
|
|
64
|
+
* @return {Queueable}
|
|
65
|
+
*/
|
|
66
|
+
static make: (queueable: Queueable | any, classType?: any) => IsLinker;
|
|
67
|
+
/**
|
|
68
|
+
* Convert an array into Queueable instances, return the head and tail Queueables.
|
|
69
|
+
* @param {Array} values Provide an array of data that will be converted to a chain of queueable linkers.
|
|
70
|
+
* @param {IsLinker} [classType=Queueable] Provide the type of IsLinker to use.
|
|
71
|
+
* @returns {{head: Queueable, tail: Queueable}}
|
|
72
|
+
*/
|
|
73
|
+
static fromArray: (values: Array<any>, classType?: any) => {
|
|
74
|
+
head: IsLinker;
|
|
75
|
+
tail: IsLinker;
|
|
76
|
+
};
|
|
77
|
+
}
|
|
@@ -1,141 +1,141 @@
|
|
|
1
|
-
'use strict'
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, '__esModule', {
|
|
4
|
-
value: true
|
|
5
|
-
})
|
|
6
|
-
exports.Queueable = void 0
|
|
7
|
-
var _Linker = require('../linked-list/Linker')
|
|
8
|
-
/**
|
|
9
|
-
* Queueable represents a runnable entry in a queue.
|
|
10
|
-
* @extends Linker
|
|
11
|
-
*/
|
|
12
|
-
class Queueable {
|
|
13
|
-
/**
|
|
14
|
-
* Create a queueable item that can be used in a queue.
|
|
15
|
-
* @param {Object} [queueableData={}]
|
|
16
|
-
* @param {*} [queueableData.task=null] The data to be stored in this queueable
|
|
17
|
-
* @param {Queueable|null} [queueableData.next=null] The reference to the next queueable if any
|
|
18
|
-
* @param {boolean|Function} [queueableData.ready=false] Indicate if the queueable is ready to run
|
|
19
|
-
*/
|
|
20
|
-
constructor ({
|
|
21
|
-
task = null,
|
|
22
|
-
next = null,
|
|
23
|
-
ready = false
|
|
24
|
-
} = {}) {
|
|
25
|
-
this.data = null
|
|
26
|
-
this.next = null
|
|
27
|
-
this.complete = false
|
|
28
|
-
this.ready = false
|
|
29
|
-
this.running = false
|
|
30
|
-
this.classType = Queueable
|
|
31
|
-
this.data = task
|
|
32
|
-
this.next = next
|
|
33
|
-
this.complete = false
|
|
34
|
-
this.ready = ready
|
|
35
|
-
this.running = false
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
/**
|
|
39
|
-
* Check ready state.
|
|
40
|
-
* @return {boolean}
|
|
41
|
-
*/
|
|
42
|
-
get isReady () {
|
|
43
|
-
return typeof this.ready === 'function' ? this.ready() : this.ready
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
/**
|
|
47
|
-
* Retrieve the data which should be formed as a task.
|
|
48
|
-
* @return {*}
|
|
49
|
-
*/
|
|
50
|
-
get task () {
|
|
51
|
-
if (typeof this.data === 'function') {
|
|
52
|
-
return this.data
|
|
53
|
-
}
|
|
54
|
-
return complete => typeof complete === 'function' ? complete({
|
|
55
|
-
context: this.data
|
|
56
|
-
}).context : this.data
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
/**
|
|
60
|
-
* Set this queueable as completed.
|
|
61
|
-
* @param {Object} completeResponse
|
|
62
|
-
* @param {*} [completeResponse.success=true] Indicate when the task failed (use false) or give a success message
|
|
63
|
-
* @param {*} [completeResponse.error=false] Indicate a task was error-free (use false) or give an error message
|
|
64
|
-
* @param {*} [completeResponse.context=null] Provide additional data in the response
|
|
65
|
-
* @return {completeResponse}
|
|
66
|
-
*/
|
|
67
|
-
markCompleted ({
|
|
68
|
-
success = true,
|
|
69
|
-
error = false,
|
|
70
|
-
context = null
|
|
71
|
-
} = {}) {
|
|
72
|
-
this.complete = true
|
|
73
|
-
this.running = false
|
|
74
|
-
return {
|
|
75
|
-
success: success,
|
|
76
|
-
error: error,
|
|
77
|
-
context: context
|
|
78
|
-
}
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
/**
|
|
82
|
-
* Intend to run the queued task when it is ready. If ready, mark this task as running and run the task.
|
|
83
|
-
* @return {completeResponse}
|
|
84
|
-
*/
|
|
85
|
-
run () {
|
|
86
|
-
if (!this.isReady) {
|
|
87
|
-
// Not yet ready, return with errors
|
|
88
|
-
return {
|
|
89
|
-
success: false,
|
|
90
|
-
error: 'Task is not ready',
|
|
91
|
-
context: this.data
|
|
92
|
-
}
|
|
93
|
-
}
|
|
94
|
-
if (this.running) {
|
|
95
|
-
// Already running, return error since we cannot run again
|
|
96
|
-
return {
|
|
97
|
-
success: false,
|
|
98
|
-
error: 'Queued task is already running, possible missing \'complete\' callback',
|
|
99
|
-
context: this.data
|
|
100
|
-
}
|
|
101
|
-
}
|
|
102
|
-
this.running = true
|
|
103
|
-
// Wrap the task in the markCompleted function, so we can set flags and format the response
|
|
104
|
-
return this.task(this.markCompleted.bind(this))
|
|
105
|
-
}
|
|
106
|
-
}
|
|
107
|
-
/**
|
|
108
|
-
* Make a new Queueable from the data given if it is not already a valid Queueable.
|
|
109
|
-
* @param {Queueable|*} queueable Return a valid Queueable instance from given data, or even an already valid one.
|
|
110
|
-
* @param {IsLinker} [classType=Queueable] Provide the type of IsLinker to use.
|
|
111
|
-
* @return {Queueable}
|
|
112
|
-
*/
|
|
113
|
-
exports.Queueable = Queueable
|
|
114
|
-
Queueable.make = (queueable, classType = Queueable) => {
|
|
115
|
-
if (typeof queueable !== 'object') {
|
|
116
|
-
// It is not an object, so instantiate the Queueable with an element as the data
|
|
117
|
-
return new classType({
|
|
118
|
-
task: queueable,
|
|
119
|
-
ready: true
|
|
120
|
-
})
|
|
121
|
-
}
|
|
122
|
-
if (queueable.classType) {
|
|
123
|
-
// Already valid Queueable, return as-is
|
|
124
|
-
return queueable
|
|
125
|
-
}
|
|
126
|
-
if (!queueable.task) {
|
|
127
|
-
queueable = {
|
|
128
|
-
task: queueable,
|
|
129
|
-
ready: true
|
|
130
|
-
}
|
|
131
|
-
}
|
|
132
|
-
// Create the new node as the configured #classType
|
|
133
|
-
return new classType(queueable)
|
|
134
|
-
}
|
|
135
|
-
/**
|
|
136
|
-
* Convert an array into Queueable instances, return the head and tail Queueables.
|
|
137
|
-
* @param {Array} values Provide an array of data that will be converted to a chain of queueable linkers.
|
|
138
|
-
* @param {IsLinker} [classType=Queueable] Provide the type of IsLinker to use.
|
|
139
|
-
* @returns {{head: Queueable, tail: Queueable}}
|
|
140
|
-
*/
|
|
141
|
-
Queueable.fromArray = (values, classType = Queueable) => _Linker.Linker.fromArray(values, classType)
|
|
1
|
+
'use strict'
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', {
|
|
4
|
+
value: true
|
|
5
|
+
})
|
|
6
|
+
exports.Queueable = void 0
|
|
7
|
+
var _Linker = require('../linked-list/Linker')
|
|
8
|
+
/**
|
|
9
|
+
* Queueable represents a runnable entry in a queue.
|
|
10
|
+
* @extends Linker
|
|
11
|
+
*/
|
|
12
|
+
class Queueable {
|
|
13
|
+
/**
|
|
14
|
+
* Create a queueable item that can be used in a queue.
|
|
15
|
+
* @param {Object} [queueableData={}]
|
|
16
|
+
* @param {*} [queueableData.task=null] The data to be stored in this queueable
|
|
17
|
+
* @param {Queueable|null} [queueableData.next=null] The reference to the next queueable if any
|
|
18
|
+
* @param {boolean|Function} [queueableData.ready=false] Indicate if the queueable is ready to run
|
|
19
|
+
*/
|
|
20
|
+
constructor ({
|
|
21
|
+
task = null,
|
|
22
|
+
next = null,
|
|
23
|
+
ready = false
|
|
24
|
+
} = {}) {
|
|
25
|
+
this.data = null
|
|
26
|
+
this.next = null
|
|
27
|
+
this.complete = false
|
|
28
|
+
this.ready = false
|
|
29
|
+
this.running = false
|
|
30
|
+
this.classType = Queueable
|
|
31
|
+
this.data = task
|
|
32
|
+
this.next = next
|
|
33
|
+
this.complete = false
|
|
34
|
+
this.ready = ready
|
|
35
|
+
this.running = false
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* Check ready state.
|
|
40
|
+
* @return {boolean}
|
|
41
|
+
*/
|
|
42
|
+
get isReady () {
|
|
43
|
+
return typeof this.ready === 'function' ? this.ready() : this.ready
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* Retrieve the data which should be formed as a task.
|
|
48
|
+
* @return {*}
|
|
49
|
+
*/
|
|
50
|
+
get task () {
|
|
51
|
+
if (typeof this.data === 'function') {
|
|
52
|
+
return this.data
|
|
53
|
+
}
|
|
54
|
+
return complete => typeof complete === 'function' ? complete({
|
|
55
|
+
context: this.data
|
|
56
|
+
}).context : this.data
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* Set this queueable as completed.
|
|
61
|
+
* @param {Object} completeResponse
|
|
62
|
+
* @param {*} [completeResponse.success=true] Indicate when the task failed (use false) or give a success message
|
|
63
|
+
* @param {*} [completeResponse.error=false] Indicate a task was error-free (use false) or give an error message
|
|
64
|
+
* @param {*} [completeResponse.context=null] Provide additional data in the response
|
|
65
|
+
* @return {completeResponse}
|
|
66
|
+
*/
|
|
67
|
+
markCompleted ({
|
|
68
|
+
success = true,
|
|
69
|
+
error = false,
|
|
70
|
+
context = null
|
|
71
|
+
} = {}) {
|
|
72
|
+
this.complete = true
|
|
73
|
+
this.running = false
|
|
74
|
+
return {
|
|
75
|
+
success: success,
|
|
76
|
+
error: error,
|
|
77
|
+
context: context
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
/**
|
|
82
|
+
* Intend to run the queued task when it is ready. If ready, mark this task as running and run the task.
|
|
83
|
+
* @return {completeResponse}
|
|
84
|
+
*/
|
|
85
|
+
run () {
|
|
86
|
+
if (!this.isReady) {
|
|
87
|
+
// Not yet ready, return with errors
|
|
88
|
+
return {
|
|
89
|
+
success: false,
|
|
90
|
+
error: 'Task is not ready',
|
|
91
|
+
context: this.data
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
if (this.running) {
|
|
95
|
+
// Already running, return error since we cannot run again
|
|
96
|
+
return {
|
|
97
|
+
success: false,
|
|
98
|
+
error: 'Queued task is already running, possible missing \'complete\' callback',
|
|
99
|
+
context: this.data
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
this.running = true
|
|
103
|
+
// Wrap the task in the markCompleted function, so we can set flags and format the response
|
|
104
|
+
return this.task(this.markCompleted.bind(this))
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
/**
|
|
108
|
+
* Make a new Queueable from the data given if it is not already a valid Queueable.
|
|
109
|
+
* @param {Queueable|*} queueable Return a valid Queueable instance from given data, or even an already valid one.
|
|
110
|
+
* @param {IsLinker} [classType=Queueable] Provide the type of IsLinker to use.
|
|
111
|
+
* @return {Queueable}
|
|
112
|
+
*/
|
|
113
|
+
exports.Queueable = Queueable
|
|
114
|
+
Queueable.make = (queueable, classType = Queueable) => {
|
|
115
|
+
if (typeof queueable !== 'object') {
|
|
116
|
+
// It is not an object, so instantiate the Queueable with an element as the data
|
|
117
|
+
return new classType({
|
|
118
|
+
task: queueable,
|
|
119
|
+
ready: true
|
|
120
|
+
})
|
|
121
|
+
}
|
|
122
|
+
if (queueable.classType) {
|
|
123
|
+
// Already valid Queueable, return as-is
|
|
124
|
+
return queueable
|
|
125
|
+
}
|
|
126
|
+
if (!queueable.task) {
|
|
127
|
+
queueable = {
|
|
128
|
+
task: queueable,
|
|
129
|
+
ready: true
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
// Create the new node as the configured #classType
|
|
133
|
+
return new classType(queueable)
|
|
134
|
+
}
|
|
135
|
+
/**
|
|
136
|
+
* Convert an array into Queueable instances, return the head and tail Queueables.
|
|
137
|
+
* @param {Array} values Provide an array of data that will be converted to a chain of queueable linkers.
|
|
138
|
+
* @param {IsLinker} [classType=Queueable] Provide the type of IsLinker to use.
|
|
139
|
+
* @returns {{head: Queueable, tail: Queueable}}
|
|
140
|
+
*/
|
|
141
|
+
Queueable.fromArray = (values, classType = Queueable) => _Linker.Linker.fromArray(values, classType)
|
|
@@ -1,63 +1,63 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @file stack.
|
|
3
|
-
* @author Joshua Heagle <joshuaheagle@gmail.com>
|
|
4
|
-
* @version 1.0.0
|
|
5
|
-
* @memberOf module:collect-your-stuff
|
|
6
|
-
*/
|
|
7
|
-
import { Stackable } from './Stackable';
|
|
8
|
-
import { IsArrayable } from '../../recipes/IsArrayable';
|
|
9
|
-
import { IsLinker } from '../../recipes/IsLinker';
|
|
10
|
-
import { completeResponse } from '../../recipes/Runnable';
|
|
11
|
-
/**
|
|
12
|
-
* Store a collection of items which can only be inserted and removed from the top.
|
|
13
|
-
*/
|
|
14
|
-
export declare class Stack {
|
|
15
|
-
stackedList: IsArrayable<any>;
|
|
16
|
-
private listClass;
|
|
17
|
-
private stackableClass;
|
|
18
|
-
/**
|
|
19
|
-
* Instantiate the state with the starter stacked list.
|
|
20
|
-
* @param {Iterable|LinkedList} stackedList
|
|
21
|
-
* @param {IsArrayable} listClass
|
|
22
|
-
* @param {Stackable} stackableClass
|
|
23
|
-
*/
|
|
24
|
-
constructor(stackedList?: IsArrayable<any>, listClass?: any, stackableClass?: typeof Stackable);
|
|
25
|
-
/**
|
|
26
|
-
* Return true if the stack is empty (there are no tasks in the stacked list)
|
|
27
|
-
* @return {boolean}
|
|
28
|
-
*/
|
|
29
|
-
empty(): boolean;
|
|
30
|
-
/**
|
|
31
|
-
* Take a look at the next stacked task
|
|
32
|
-
* @return {Stackable}
|
|
33
|
-
*/
|
|
34
|
-
top(): IsLinker;
|
|
35
|
-
/**
|
|
36
|
-
* Remove the next stacked task and return it.
|
|
37
|
-
* @return {Stackable|null}
|
|
38
|
-
*/
|
|
39
|
-
pop(): Stackable | completeResponse | null;
|
|
40
|
-
/**
|
|
41
|
-
* Push a stackable task to the top of the stack.
|
|
42
|
-
* @param {Stackable|*} stackable Add a new stackable to the top of the stack
|
|
43
|
-
*/
|
|
44
|
-
push(stackable: any): void;
|
|
45
|
-
/**
|
|
46
|
-
* Remove the next stacked task and return it.
|
|
47
|
-
* @return {Stackable|null}
|
|
48
|
-
*/
|
|
49
|
-
remove(): Stackable | null;
|
|
50
|
-
/**
|
|
51
|
-
* Get the size of the current stack.
|
|
52
|
-
* @return {number}
|
|
53
|
-
*/
|
|
54
|
-
size(): number;
|
|
55
|
-
/**
|
|
56
|
-
* Convert an array to a Stack.
|
|
57
|
-
* @param {Array} values An array of values which will be converted to stackables in this queue
|
|
58
|
-
* @param {Stackable} stackableClass The class to use for each stackable
|
|
59
|
-
* @param {Stack|Iterable} listClass The class to use to manage the stackables
|
|
60
|
-
* @returns {Stack}
|
|
61
|
-
*/
|
|
62
|
-
static fromArray: (values?: Array<any>, stackableClass?: typeof Stackable, listClass?: any) => Stack;
|
|
63
|
-
}
|
|
1
|
+
/**
|
|
2
|
+
* @file stack.
|
|
3
|
+
* @author Joshua Heagle <joshuaheagle@gmail.com>
|
|
4
|
+
* @version 1.0.0
|
|
5
|
+
* @memberOf module:collect-your-stuff
|
|
6
|
+
*/
|
|
7
|
+
import { Stackable } from './Stackable';
|
|
8
|
+
import { IsArrayable } from '../../recipes/IsArrayable';
|
|
9
|
+
import { IsLinker } from '../../recipes/IsLinker';
|
|
10
|
+
import { completeResponse } from '../../recipes/Runnable';
|
|
11
|
+
/**
|
|
12
|
+
* Store a collection of items which can only be inserted and removed from the top.
|
|
13
|
+
*/
|
|
14
|
+
export declare class Stack {
|
|
15
|
+
stackedList: IsArrayable<any>;
|
|
16
|
+
private listClass;
|
|
17
|
+
private stackableClass;
|
|
18
|
+
/**
|
|
19
|
+
* Instantiate the state with the starter stacked list.
|
|
20
|
+
* @param {Iterable|LinkedList} stackedList
|
|
21
|
+
* @param {IsArrayable} listClass
|
|
22
|
+
* @param {Stackable} stackableClass
|
|
23
|
+
*/
|
|
24
|
+
constructor(stackedList?: IsArrayable<any>, listClass?: any, stackableClass?: typeof Stackable);
|
|
25
|
+
/**
|
|
26
|
+
* Return true if the stack is empty (there are no tasks in the stacked list)
|
|
27
|
+
* @return {boolean}
|
|
28
|
+
*/
|
|
29
|
+
empty(): boolean;
|
|
30
|
+
/**
|
|
31
|
+
* Take a look at the next stacked task
|
|
32
|
+
* @return {Stackable}
|
|
33
|
+
*/
|
|
34
|
+
top(): IsLinker;
|
|
35
|
+
/**
|
|
36
|
+
* Remove the next stacked task and return it.
|
|
37
|
+
* @return {Stackable|null}
|
|
38
|
+
*/
|
|
39
|
+
pop(): Stackable | completeResponse | null;
|
|
40
|
+
/**
|
|
41
|
+
* Push a stackable task to the top of the stack.
|
|
42
|
+
* @param {Stackable|*} stackable Add a new stackable to the top of the stack
|
|
43
|
+
*/
|
|
44
|
+
push(stackable: any): void;
|
|
45
|
+
/**
|
|
46
|
+
* Remove the next stacked task and return it.
|
|
47
|
+
* @return {Stackable|null}
|
|
48
|
+
*/
|
|
49
|
+
remove(): Stackable | null;
|
|
50
|
+
/**
|
|
51
|
+
* Get the size of the current stack.
|
|
52
|
+
* @return {number}
|
|
53
|
+
*/
|
|
54
|
+
size(): number;
|
|
55
|
+
/**
|
|
56
|
+
* Convert an array to a Stack.
|
|
57
|
+
* @param {Array} values An array of values which will be converted to stackables in this queue
|
|
58
|
+
* @param {Stackable} stackableClass The class to use for each stackable
|
|
59
|
+
* @param {Stack|Iterable} listClass The class to use to manage the stackables
|
|
60
|
+
* @returns {Stack}
|
|
61
|
+
*/
|
|
62
|
+
static fromArray: (values?: Array<any>, stackableClass?: typeof Stackable, listClass?: any) => Stack;
|
|
63
|
+
}
|