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