-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathqueue.js
52 lines (46 loc) · 942 Bytes
/
queue.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
'use strict';
//
// Required modules.
//
var merge = require('predefine').merge;
/**
* Queue constructor.
*
* @Constructor
* @api public
*/
function Queue() {
this.store = {};
}
/**
* Enlist data for specific template type.
*
* @param {String} type
* @param {Object} data
* @return {Queue} this
* @api public
*/
Queue.prototype.enlist = function enlist(type, data) {
data = merge((this.store[type] || {}), data);
this.store[type] = data;
return this;
};
/**
* Discharge data, remove it from the store after use.
*
* @param {String} type
* @param {Object} data
* @return {Object} object from store
* @api public
*/
Queue.prototype.discharge = function discharge(type) {
if (!(type in this.store)) return {};
var value = this.store[type];
// Remove the content so it does not infect other templates.
delete this.store[type];
return value;
};
//
// Expose the constructor
//
module.exports = new Queue;