collect-your-stuff 2.1.2 → 2.2.0
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 +32 -3926
- package/browser/collect-your-stuff.js +912 -549
- package/browser/collect-your-stuff.min.js +1 -1
- package/dist/collections/arrayable/ArrayElement.d.ts +6 -11
- package/dist/collections/arrayable/ArrayElement.js +5 -7
- package/dist/collections/arrayable/Arrayable.d.ts +22 -37
- package/dist/collections/arrayable/Arrayable.js +208 -223
- package/dist/collections/doubly-linked-list/DoubleLinker.d.ts +9 -14
- package/dist/collections/doubly-linked-list/DoubleLinker.js +71 -73
- package/dist/collections/doubly-linked-list/DoublyLinkedList.d.ts +19 -36
- package/dist/collections/doubly-linked-list/DoublyLinkedList.js +310 -327
- package/dist/collections/linked-list/LinkedList.d.ts +20 -36
- package/dist/collections/linked-list/LinkedList.js +283 -296
- package/dist/collections/linked-list/Linker.d.ts +8 -13
- package/dist/collections/linked-list/Linker.js +82 -84
- package/dist/collections/linked-tree-list/LinkedTreeList.d.ts +24 -43
- package/dist/collections/linked-tree-list/LinkedTreeList.js +274 -294
- package/dist/collections/linked-tree-list/TreeLinker.d.ts +14 -20
- package/dist/collections/linked-tree-list/TreeLinker.js +91 -94
- package/dist/collections/queue/Queue.d.ts +10 -14
- package/dist/collections/queue/Queue.js +114 -121
- package/dist/collections/queue/Queueable.d.ts +13 -22
- package/dist/collections/queue/Queueable.js +142 -148
- package/dist/collections/queue/TaskQueue.d.ts +8 -17
- package/dist/collections/queue/TaskQueue.js +128 -137
- package/dist/collections/scoped-collection/ScopedCollection.d.ts +42 -0
- package/dist/collections/scoped-collection/ScopedCollection.js +81 -0
- package/dist/collections/scoped-collection/ScopedCollection.min.js +1 -0
- package/dist/collections/stack/Stack.d.ts +11 -15
- package/dist/collections/stack/Stack.js +122 -129
- package/dist/collections/stack/Stackable.d.ts +9 -16
- package/dist/collections/stack/Stackable.js +81 -85
- package/dist/collections/stack/TaskStack.d.ts +8 -17
- package/dist/collections/stack/TaskStack.js +98 -107
- package/dist/main.d.ts +67 -68
- package/dist/main.js +8 -4
- package/dist/main.min.js +1 -1
- package/dist/recipes/ArrayIterator.d.ts +4 -4
- package/dist/recipes/ArrayIterator.js +4 -4
- package/dist/recipes/DoubleLinkerIterator.d.ts +3 -3
- package/dist/recipes/DoubleLinkerIterator.js +3 -3
- package/dist/recipes/IsArrayable.d.ts +13 -33
- package/dist/recipes/IsQueue.d.ts +4 -9
- package/dist/recipes/IsScopedCollection.d.ts +27 -0
- package/dist/recipes/IsScopedCollection.js +5 -0
- package/dist/recipes/IsScopedCollection.min.js +1 -0
- package/dist/recipes/IsStack.d.ts +4 -9
- package/dist/recipes/IsTreeNode.d.ts +1 -1
- package/dist/recipes/LinkerIterator.d.ts +3 -3
- package/dist/recipes/LinkerIterator.js +3 -3
- package/dist/recipes/Runnable.d.ts +3 -16
- package/dist/recipes/Runnable.js +3 -9
- package/dist/recipes/TreeLinkerIterator.d.ts +4 -4
- package/dist/recipes/TreeLinkerIterator.js +36 -36
- package/dist/recipes/recipes.d.ts +1 -4
- package/dist/recipes/recipes.js +19 -22
- package/dist/services/parseTree.d.ts +2 -3
- package/dist/services/parseTree.js +23 -24
- package/dist/services/parseTreeNext.d.ts +2 -3
- package/dist/services/parseTreeNext.js +2 -3
- package/dist/services/services.d.ts +1 -4
- package/dist/services/services.js +19 -22
- package/package.json +4 -4
|
@@ -1,94 +1,91 @@
|
|
|
1
|
-
'use strict'
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, '__esModule', {
|
|
4
|
-
value: true
|
|
5
|
-
})
|
|
6
|
-
exports.TreeLinker = void 0
|
|
7
|
-
require('core-js/modules/esnext.iterator.constructor.js')
|
|
8
|
-
require('core-js/modules/esnext.iterator.map.js')
|
|
9
|
-
const _DoubleLinker = require('../doubly-linked-list/DoubleLinker')
|
|
10
|
-
const _LinkedTreeList = require('./LinkedTreeList')
|
|
11
|
-
/**
|
|
12
|
-
* TreeLinker represents a node in a LinkedTreeList having a parent (or root) and child nodes.
|
|
13
|
-
* @extends DoubleLinker
|
|
14
|
-
*/
|
|
15
|
-
class TreeLinker {
|
|
16
|
-
/**
|
|
17
|
-
* Create the new TreeLinker instance, provide the data and optionally set references for next, prev, parent, or children.
|
|
18
|
-
* @param
|
|
19
|
-
* @param
|
|
20
|
-
* @param
|
|
21
|
-
* @param
|
|
22
|
-
* @param
|
|
23
|
-
* @param
|
|
24
|
-
* @param
|
|
25
|
-
*/
|
|
26
|
-
constructor ({
|
|
27
|
-
data = null,
|
|
28
|
-
next = null,
|
|
29
|
-
prev = null,
|
|
30
|
-
children = null,
|
|
31
|
-
parent = null,
|
|
32
|
-
listClass = _LinkedTreeList.LinkedTreeList
|
|
33
|
-
} = {}) {
|
|
34
|
-
/** The class used to create this instance, so that it can be recognized as valid without an instanceof check. */
|
|
35
|
-
this.classType = TreeLinker
|
|
36
|
-
/** The data stored in this tree node. */
|
|
37
|
-
this.data = null
|
|
38
|
-
/** The sibling after this node, or null when this is the last child. */
|
|
39
|
-
this.next = null
|
|
40
|
-
/** The sibling before this node, or null when this is the first child. */
|
|
41
|
-
this.prev = null
|
|
42
|
-
/** The node this node is a child of, or null for a root node. */
|
|
43
|
-
this.parent = null
|
|
44
|
-
/** The list of the children of this node, or null when it has none. */
|
|
45
|
-
this.children = null
|
|
46
|
-
this.data = data
|
|
47
|
-
this.next = next
|
|
48
|
-
this.prev = prev
|
|
49
|
-
this.parent = parent
|
|
50
|
-
this.children = this.childrenFromArray(children, listClass)
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
/**
|
|
54
|
-
* Create the children for this tree from an array. Each child becomes a tree linker with this node as its parent: an
|
|
55
|
-
* existing linker is kept as it is, an object with a data property gives the settings of the linker, and anything
|
|
56
|
-
* else is the data of the linker.
|
|
57
|
-
* @param
|
|
58
|
-
* @param
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
//
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
linker
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
list
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
*
|
|
80
|
-
* @param
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
*
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
* @returns {{head: TreeLinker, tail: TreeLinker}}
|
|
93
|
-
*/
|
|
94
|
-
TreeLinker.fromArray = (values = [], classType = TreeLinker) => _DoubleLinker.DoubleLinker.fromArray(values, classType)
|
|
1
|
+
'use strict'
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', {
|
|
4
|
+
value: true
|
|
5
|
+
})
|
|
6
|
+
exports.TreeLinker = void 0
|
|
7
|
+
require('core-js/modules/esnext.iterator.constructor.js')
|
|
8
|
+
require('core-js/modules/esnext.iterator.map.js')
|
|
9
|
+
const _DoubleLinker = require('../doubly-linked-list/DoubleLinker')
|
|
10
|
+
const _LinkedTreeList = require('./LinkedTreeList')
|
|
11
|
+
/**
|
|
12
|
+
* TreeLinker represents a node in a LinkedTreeList having a parent (or root) and child nodes.
|
|
13
|
+
* @extends DoubleLinker
|
|
14
|
+
*/
|
|
15
|
+
class TreeLinker {
|
|
16
|
+
/**
|
|
17
|
+
* Create the new TreeLinker instance, provide the data and optionally set references for next, prev, parent, or children.
|
|
18
|
+
* @param settings The settings for the new tree node.
|
|
19
|
+
* @param settings.data The data to be stored in this tree node
|
|
20
|
+
* @param settings.next The reference to the next linker if any
|
|
21
|
+
* @param settings.prev The reference to the previous linker if any
|
|
22
|
+
* @param settings.children The references to child linkers if any
|
|
23
|
+
* @param settings.parent The reference to a parent linker if any
|
|
24
|
+
* @param listClass Give the type of list to use for storing the children
|
|
25
|
+
*/
|
|
26
|
+
constructor ({
|
|
27
|
+
data = null,
|
|
28
|
+
next = null,
|
|
29
|
+
prev = null,
|
|
30
|
+
children = null,
|
|
31
|
+
parent = null,
|
|
32
|
+
listClass = _LinkedTreeList.LinkedTreeList
|
|
33
|
+
} = {}) {
|
|
34
|
+
/** The class used to create this instance, so that it can be recognized as valid without an instanceof check. */
|
|
35
|
+
this.classType = TreeLinker
|
|
36
|
+
/** The data stored in this tree node. */
|
|
37
|
+
this.data = null
|
|
38
|
+
/** The sibling after this node, or null when this is the last child. */
|
|
39
|
+
this.next = null
|
|
40
|
+
/** The sibling before this node, or null when this is the first child. */
|
|
41
|
+
this.prev = null
|
|
42
|
+
/** The node this node is a child of, or null for a root node. */
|
|
43
|
+
this.parent = null
|
|
44
|
+
/** The list of the children of this node, or null when it has none. */
|
|
45
|
+
this.children = null
|
|
46
|
+
this.data = data
|
|
47
|
+
this.next = next
|
|
48
|
+
this.prev = prev
|
|
49
|
+
this.parent = parent
|
|
50
|
+
this.children = this.childrenFromArray(children, listClass)
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* Create the children for this tree from an array. Each child becomes a tree linker with this node as its parent: an
|
|
55
|
+
* existing linker is kept as it is, an object with a data property gives the settings of the linker, and anything
|
|
56
|
+
* else is the data of the linker.
|
|
57
|
+
* @param children Provide an array of data / linker references to be children of this tree node.
|
|
58
|
+
* @param listClass Give the type of list to use for storing the children
|
|
59
|
+
*/
|
|
60
|
+
childrenFromArray (children = null, listClass = _LinkedTreeList.LinkedTreeList) {
|
|
61
|
+
if (children === null) {
|
|
62
|
+
return null
|
|
63
|
+
}
|
|
64
|
+
// Every child is made into a tree linker (an existing one is kept as it is, and a plain value is the data) and is
|
|
65
|
+
// given this node as its parent
|
|
66
|
+
const nodes = children.map(child => {
|
|
67
|
+
const linker = this.classType.make(child, this.classType)
|
|
68
|
+
linker.parent = this
|
|
69
|
+
return linker
|
|
70
|
+
})
|
|
71
|
+
// Creates a linked-tree-list to store the children, which remembers this node as its parent even when it is empty
|
|
72
|
+
const list = listClass.fromArray(nodes, this.classType)
|
|
73
|
+
list.parent = this
|
|
74
|
+
return list
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* Make a new DoubleLinker from the data given if it is not already a valid Linker.
|
|
79
|
+
* @param linker Return a valid TreeLinker instance from given data, or even an already valid one.
|
|
80
|
+
* @param classType Provide the type of IsTreeNode to use.
|
|
81
|
+
*/
|
|
82
|
+
exports.TreeLinker = TreeLinker
|
|
83
|
+
TreeLinker.make = (linker, classType = TreeLinker) => {
|
|
84
|
+
return _DoubleLinker.DoubleLinker.make(linker, classType)
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* Convert an array into DoubleLinker instances, return the head and tail DoubleLinkers.
|
|
88
|
+
* @param values Provide an array of data that will be converted to a chain of tree-linkers.
|
|
89
|
+
* @param classType Provide the type of IsTreeNode to use.
|
|
90
|
+
*/
|
|
91
|
+
TreeLinker.fromArray = (values = [], classType = TreeLinker) => _DoubleLinker.DoubleLinker.fromArray(values, classType)
|
|
@@ -12,48 +12,44 @@ export declare class Queue<T = any> implements IsQueue<T>, Iterable<T> {
|
|
|
12
12
|
private readonly linkerClass;
|
|
13
13
|
/**
|
|
14
14
|
* Instantiate the queue, optionally with a list of items to start from.
|
|
15
|
-
* @param
|
|
16
|
-
* @param
|
|
17
|
-
* @param
|
|
15
|
+
* @param queuedList The list of linkers to start in this queue (the first is the front)
|
|
16
|
+
* @param listClass The type of list to create when no queued list is given
|
|
17
|
+
* @param linkerClass The class used to hold each queued item
|
|
18
18
|
*/
|
|
19
19
|
constructor(queuedList?: IsArrayable<any> | null, listClass?: any, linkerClass?: typeof Linker);
|
|
20
20
|
/**
|
|
21
21
|
* Take the item from the front of the queue.
|
|
22
|
-
* @
|
|
22
|
+
* @returns The item, or null when the queue is empty
|
|
23
23
|
*/
|
|
24
24
|
dequeue(): T | null;
|
|
25
25
|
/**
|
|
26
26
|
* Check whether the queue has no items.
|
|
27
|
-
* @return {boolean}
|
|
28
27
|
*/
|
|
29
28
|
empty(): boolean;
|
|
30
29
|
/**
|
|
31
30
|
* Add an item to the back of the queue.
|
|
32
|
-
* @param
|
|
33
|
-
* @
|
|
31
|
+
* @param data The item to add
|
|
32
|
+
* @returns This queue, so that adding can be chained
|
|
34
33
|
*/
|
|
35
34
|
enqueue(data: T): this;
|
|
36
35
|
/**
|
|
37
36
|
* Look at the item at the front of the queue, without removing it.
|
|
38
|
-
* @
|
|
37
|
+
* @returns The item, or null when the queue is empty
|
|
39
38
|
*/
|
|
40
39
|
peek(): T | null;
|
|
41
40
|
/**
|
|
42
41
|
* Count the items in the queue.
|
|
43
|
-
* @return {number}
|
|
44
42
|
*/
|
|
45
43
|
size(): number;
|
|
46
44
|
/**
|
|
47
45
|
* Iterate over the items from the front of the queue to the back, without removing them.
|
|
48
|
-
* @return {Iterator}
|
|
49
46
|
*/
|
|
50
47
|
[Symbol.iterator](): Iterator<T>;
|
|
51
48
|
/**
|
|
52
49
|
* Convert an array to a Queue, the first value is at the front.
|
|
53
|
-
* @param
|
|
54
|
-
* @param
|
|
55
|
-
* @param
|
|
56
|
-
* @returns {Queue}
|
|
50
|
+
* @param values The items to queue
|
|
51
|
+
* @param listClass The type of list used to store the items
|
|
52
|
+
* @param linkerClass The class used to hold each queued item
|
|
57
53
|
*/
|
|
58
54
|
static fromArray: <T_1 = any>(values?: Array<T_1>, listClass?: any, linkerClass?: typeof Linker) => Queue<T_1>;
|
|
59
55
|
}
|
|
@@ -1,121 +1,114 @@
|
|
|
1
|
-
'use strict'
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, '__esModule', {
|
|
4
|
-
value: true
|
|
5
|
-
})
|
|
6
|
-
exports.Queue = void 0
|
|
7
|
-
require('core-js/modules/esnext.iterator.constructor.js')
|
|
8
|
-
require('core-js/modules/esnext.iterator.for-each.js')
|
|
9
|
-
const _LinkedList = require('../linked-list/LinkedList')
|
|
10
|
-
const _Linker = require('../linked-list/Linker')
|
|
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
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
*/
|
|
116
|
-
exports.Queue = Queue
|
|
117
|
-
Queue.fromArray = (values = [], listClass = _LinkedList.LinkedList, linkerClass = _Linker.Linker) => {
|
|
118
|
-
const queue = new Queue(null, listClass, linkerClass)
|
|
119
|
-
values.forEach(value => queue.enqueue(value))
|
|
120
|
-
return queue
|
|
121
|
-
}
|
|
1
|
+
'use strict'
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', {
|
|
4
|
+
value: true
|
|
5
|
+
})
|
|
6
|
+
exports.Queue = void 0
|
|
7
|
+
require('core-js/modules/esnext.iterator.constructor.js')
|
|
8
|
+
require('core-js/modules/esnext.iterator.for-each.js')
|
|
9
|
+
const _LinkedList = require('../linked-list/LinkedList')
|
|
10
|
+
const _Linker = require('../linked-list/Linker')
|
|
11
|
+
/**
|
|
12
|
+
* queue
|
|
13
|
+
*/
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* A first-in-first-out collection: items are added to the back with enqueue and taken from the front with dequeue.
|
|
17
|
+
* Any value can be queued (it is stored as it is, whether it is a function, an object or null), and adding and taking
|
|
18
|
+
* are constant time. To queue tasks which are run as they are taken use TaskQueue.
|
|
19
|
+
*/
|
|
20
|
+
class Queue {
|
|
21
|
+
/**
|
|
22
|
+
* Instantiate the queue, optionally with a list of items to start from.
|
|
23
|
+
* @param queuedList The list of linkers to start in this queue (the first is the front)
|
|
24
|
+
* @param listClass The type of list to create when no queued list is given
|
|
25
|
+
* @param linkerClass The class used to hold each queued item
|
|
26
|
+
*/
|
|
27
|
+
constructor (queuedList = null, listClass = _LinkedList.LinkedList, linkerClass = _Linker.Linker) {
|
|
28
|
+
this.linkerClass = linkerClass
|
|
29
|
+
this.queuedList = queuedList === null ? new listClass(linkerClass) : queuedList
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* Take the item from the front of the queue.
|
|
34
|
+
* @returns The item, or null when the queue is empty
|
|
35
|
+
*/
|
|
36
|
+
dequeue () {
|
|
37
|
+
const front = this.queuedList.first
|
|
38
|
+
if (front === null || typeof front === 'undefined') {
|
|
39
|
+
return null
|
|
40
|
+
}
|
|
41
|
+
this.queuedList.remove(front)
|
|
42
|
+
return front.data
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* Check whether the queue has no items.
|
|
47
|
+
*/
|
|
48
|
+
empty () {
|
|
49
|
+
return this.size() <= 0
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* Add an item to the back of the queue.
|
|
54
|
+
* @param data The item to add
|
|
55
|
+
* @returns This queue, so that adding can be chained
|
|
56
|
+
*/
|
|
57
|
+
enqueue (data) {
|
|
58
|
+
// The item is wrapped here rather than left to the list, since the list treats objects that look like a linker's
|
|
59
|
+
// settings (they have a data property) as such, and a queue must give back exactly what it was given
|
|
60
|
+
this.queuedList.append(new this.linkerClass({
|
|
61
|
+
data
|
|
62
|
+
}))
|
|
63
|
+
return this
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* Look at the item at the front of the queue, without removing it.
|
|
68
|
+
* @returns The item, or null when the queue is empty
|
|
69
|
+
*/
|
|
70
|
+
peek () {
|
|
71
|
+
const front = this.queuedList.first
|
|
72
|
+
return front === null || typeof front === 'undefined' ? null : front.data
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
/**
|
|
76
|
+
* Count the items in the queue.
|
|
77
|
+
*/
|
|
78
|
+
size () {
|
|
79
|
+
return this.queuedList.length
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
/**
|
|
83
|
+
* Iterate over the items from the front of the queue to the back, without removing them.
|
|
84
|
+
*/
|
|
85
|
+
[Symbol.iterator] () {
|
|
86
|
+
const linkers = this.queuedList[Symbol.iterator]()
|
|
87
|
+
return {
|
|
88
|
+
next: () => {
|
|
89
|
+
const result = linkers.next()
|
|
90
|
+
return result.done
|
|
91
|
+
? {
|
|
92
|
+
done: true,
|
|
93
|
+
value: undefined
|
|
94
|
+
}
|
|
95
|
+
: {
|
|
96
|
+
done: false,
|
|
97
|
+
value: result.value.data
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
/**
|
|
104
|
+
* Convert an array to a Queue, the first value is at the front.
|
|
105
|
+
* @param values The items to queue
|
|
106
|
+
* @param listClass The type of list used to store the items
|
|
107
|
+
* @param linkerClass The class used to hold each queued item
|
|
108
|
+
*/
|
|
109
|
+
exports.Queue = Queue
|
|
110
|
+
Queue.fromArray = (values = [], listClass = _LinkedList.LinkedList, linkerClass = _Linker.Linker) => {
|
|
111
|
+
const queue = new Queue(null, listClass, linkerClass)
|
|
112
|
+
values.forEach(value => queue.enqueue(value))
|
|
113
|
+
return queue
|
|
114
|
+
}
|
|
@@ -1,8 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
3
|
-
* @author Joshua Heagle <joshuaheagle@gmail.com>
|
|
4
|
-
* @version 1.1.0
|
|
5
|
-
* @memberOf module:collect-your-stuff
|
|
2
|
+
* queueable item.
|
|
6
3
|
*/
|
|
7
4
|
import { completeResponse, IsRunnable } from '../../recipes/Runnable';
|
|
8
5
|
import { IsLinker } from '../../recipes/IsLinker';
|
|
@@ -25,10 +22,10 @@ export declare class Queueable implements IsLinker, IsRunnable {
|
|
|
25
22
|
running: boolean;
|
|
26
23
|
/**
|
|
27
24
|
* Create a queueable item that can be used in a queue.
|
|
28
|
-
* @param
|
|
29
|
-
* @param
|
|
30
|
-
* @param
|
|
31
|
-
* @param
|
|
25
|
+
* @param queueableData The settings for the new queueable.
|
|
26
|
+
* @param queueableData.task The data to be stored in this queueable
|
|
27
|
+
* @param queueableData.next The reference to the next queueable if any
|
|
28
|
+
* @param queueableData.ready Indicate if the queueable is ready to run
|
|
32
29
|
*/
|
|
33
30
|
constructor({ task, next, ready }?: {
|
|
34
31
|
task?: any;
|
|
@@ -37,21 +34,18 @@ export declare class Queueable implements IsLinker, IsRunnable {
|
|
|
37
34
|
});
|
|
38
35
|
/**
|
|
39
36
|
* Check ready state.
|
|
40
|
-
* @return {boolean}
|
|
41
37
|
*/
|
|
42
38
|
get isReady(): boolean;
|
|
43
39
|
/**
|
|
44
40
|
* Retrieve the data which should be formed as a task.
|
|
45
|
-
* @return {*}
|
|
46
41
|
*/
|
|
47
42
|
get task(): any;
|
|
48
43
|
/**
|
|
49
44
|
* Set this queueable as completed.
|
|
50
|
-
* @param
|
|
51
|
-
* @param
|
|
52
|
-
* @param
|
|
53
|
-
* @param
|
|
54
|
-
* @return {completeResponse}
|
|
45
|
+
* @param completeResponse The result to report for the task.
|
|
46
|
+
* @param completeResponse.success Indicate when the task failed (use false) or give a success message
|
|
47
|
+
* @param completeResponse.error Indicate a task was error-free (use false) or give an error message
|
|
48
|
+
* @param completeResponse.context Provide additional data in the response
|
|
55
49
|
*/
|
|
56
50
|
markCompleted({ success, error, context }?: {
|
|
57
51
|
success?: any;
|
|
@@ -60,21 +54,18 @@ export declare class Queueable implements IsLinker, IsRunnable {
|
|
|
60
54
|
}): completeResponse;
|
|
61
55
|
/**
|
|
62
56
|
* Intend to run the queued task when it is ready. If ready, mark this task as running and run the task.
|
|
63
|
-
* @return {completeResponse}
|
|
64
57
|
*/
|
|
65
58
|
run(): completeResponse;
|
|
66
59
|
/**
|
|
67
60
|
* Make a new Queueable from the data given if it is not already a valid Queueable.
|
|
68
|
-
* @param
|
|
69
|
-
* @param
|
|
70
|
-
* @return {Queueable}
|
|
61
|
+
* @param queueable Return a valid Queueable instance from given data, or even an already valid one.
|
|
62
|
+
* @param classType Provide the type of IsLinker to use.
|
|
71
63
|
*/
|
|
72
64
|
static make: (queueable: Queueable | any, classType?: any) => IsLinker;
|
|
73
65
|
/**
|
|
74
66
|
* Convert an array into Queueable instances, return the head and tail Queueables.
|
|
75
|
-
* @param
|
|
76
|
-
* @param
|
|
77
|
-
* @returns {{head: Queueable, tail: Queueable}}
|
|
67
|
+
* @param values Provide an array of data that will be converted to a chain of queueable linkers.
|
|
68
|
+
* @param classType Provide the type of IsLinker to use.
|
|
78
69
|
*/
|
|
79
70
|
static fromArray: (values?: Array<any>, classType?: any) => {
|
|
80
71
|
head: IsLinker;
|