1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 | 'use strict';
|
13 |
|
14 | var _prodInvariant = require('./reactProdInvariant');
|
15 |
|
16 | function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
17 |
|
18 | var PooledClass = require('./PooledClass');
|
19 |
|
20 | var invariant = require('fbjs/lib/invariant');
|
21 |
|
22 |
|
23 |
|
24 |
|
25 |
|
26 |
|
27 |
|
28 |
|
29 |
|
30 |
|
31 |
|
32 |
|
33 |
|
34 | var CallbackQueue = function () {
|
35 | function CallbackQueue(arg) {
|
36 | _classCallCheck(this, CallbackQueue);
|
37 |
|
38 | this._callbacks = null;
|
39 | this._contexts = null;
|
40 | this._arg = arg;
|
41 | }
|
42 |
|
43 | |
44 |
|
45 |
|
46 |
|
47 |
|
48 |
|
49 |
|
50 |
|
51 |
|
52 | CallbackQueue.prototype.enqueue = function enqueue(callback, context) {
|
53 | this._callbacks = this._callbacks || [];
|
54 | this._callbacks.push(callback);
|
55 | this._contexts = this._contexts || [];
|
56 | this._contexts.push(context);
|
57 | };
|
58 |
|
59 | |
60 |
|
61 |
|
62 |
|
63 |
|
64 |
|
65 |
|
66 |
|
67 | CallbackQueue.prototype.notifyAll = function notifyAll() {
|
68 | var callbacks = this._callbacks;
|
69 | var contexts = this._contexts;
|
70 | var arg = this._arg;
|
71 | if (callbacks && contexts) {
|
72 | !(callbacks.length === contexts.length) ? process.env.NODE_ENV !== 'production' ? invariant(false, 'Mismatched list of contexts in callback queue') : _prodInvariant('24') : void 0;
|
73 | this._callbacks = null;
|
74 | this._contexts = null;
|
75 | for (var i = 0; i < callbacks.length; i++) {
|
76 | callbacks[i].call(contexts[i], arg);
|
77 | }
|
78 | callbacks.length = 0;
|
79 | contexts.length = 0;
|
80 | }
|
81 | };
|
82 |
|
83 | CallbackQueue.prototype.checkpoint = function checkpoint() {
|
84 | return this._callbacks ? this._callbacks.length : 0;
|
85 | };
|
86 |
|
87 | CallbackQueue.prototype.rollback = function rollback(len) {
|
88 | if (this._callbacks && this._contexts) {
|
89 | this._callbacks.length = len;
|
90 | this._contexts.length = len;
|
91 | }
|
92 | };
|
93 |
|
94 | |
95 |
|
96 |
|
97 |
|
98 |
|
99 |
|
100 |
|
101 | CallbackQueue.prototype.reset = function reset() {
|
102 | this._callbacks = null;
|
103 | this._contexts = null;
|
104 | };
|
105 |
|
106 | |
107 |
|
108 |
|
109 |
|
110 |
|
111 | CallbackQueue.prototype.destructor = function destructor() {
|
112 | this.reset();
|
113 | };
|
114 |
|
115 | return CallbackQueue;
|
116 | }();
|
117 |
|
118 | module.exports = PooledClass.addPoolingTo(CallbackQueue); |
\ | No newline at end of file |