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