]> git.proxmox.com Git - extjs.git/blame - extjs/packages/core/src/app/route/Queue.js
add extjs 6.0.1 sources
[extjs.git] / extjs / packages / core / src / app / route / Queue.js
CommitLineData
6527f429
DM
1/**\r
2 * A Queue is a queue of {@link Ext.app.route.Route} instances managed by the\r
3 * {@link Ext.app.route.Router} singleton if queueActions is set to `true`.\r
4 * \r
5 * A developer shouldn't need to use this class as {@link Ext.app.route.Router} should\r
6 * manage this class. When a {@link Ext.app.route.Route} is executed,it will automatically\r
7 * keep running the queue until the queue is empty.\r
8 * @private\r
9 */\r
10Ext.define('Ext.app.route.Queue', {\r
11 /**\r
12 * The {@link Ext.util.MixedCollection} that will hold the queued\r
13 * {@link Ext.app.route.Route} and recognized arguments.\r
14 *\r
15 * @private\r
16 */\r
17 queue: null,\r
18\r
19 /**\r
20 * The token from the {@link Ext.app.route.Router} that is being enacted on.\r
21 */\r
22 token: null,\r
23\r
24 constructor : function(config) {\r
25 Ext.apply(this, config);\r
26\r
27 //Create the queue MixedCollection\r
28 this.queue = new Ext.util.MixedCollection();\r
29 },\r
30\r
31 /**\r
32 * Add a {@link Ext.app.route.Route} to the queue.\r
33 *\r
34 * @param {Ext.app.route.Route} route The route to add to the queue.\r
35 * @param {Object} args The arguments recognized by the {Ext.app.route.Route}.\r
36 */\r
37 queueAction : function (route, args) {\r
38 this.queue.add({\r
39 route : route,\r
40 args : args\r
41 });\r
42 },\r
43\r
44 /**\r
45 * Clear all queued actions.\r
46 */\r
47 clearQueue : function() {\r
48 this.queue.removeAll();\r
49 },\r
50\r
51 /**\r
52 * Run the queue one by one.\r
53 */\r
54 runQueue : function() {\r
55 var queue = this.queue,\r
56 action = queue.removeAt(0),\r
57 route;\r
58\r
59 if (action) {\r
60 route = action && action.route;\r
61\r
62 route.execute(this.token, action.args, this.onActionExecute, this);\r
63 }\r
64 },\r
65\r
66 /**\r
67 * Handle the execution of a queued action and optionally clear all queued actions.\r
68 *\r
69 * @param {Boolean} clearQueue If `true` was returned, will clear all queued actions.\r
70 */\r
71 onActionExecute : function(clearQueue) {\r
72 if (clearQueue) {\r
73 //clear all queued actions\r
74 this.clearQueue();\r
75 } else {\r
76 //continue with queue execution\r
77 this.runQueue();\r
78 }\r
79 }\r
80});\r