/**1* Copyright 2013-2015, Facebook, Inc.2* All rights reserved.3*4* This source code is licensed under the BSD-style license found in the5* LICENSE file in the root directory of this source tree. An additional grant6* of patent rights can be found in the PATENTS file in the same directory.7*8* @providesModule CallbackQueue9*/1011'use strict';1213var PooledClass = require("./PooledClass");1415var assign = require("./Object.assign");16var invariant = require("./invariant");1718/**19* A specialized pseudo-event module to help keep track of components waiting to20* be notified when their DOM representations are available for use.21*22* This implements `PooledClass`, so you should never need to instantiate this.23* Instead, use `CallbackQueue.getPooled()`.24*25* @class ReactMountReady26* @implements PooledClass27* @internal28*/29function CallbackQueue() {30this._callbacks = null;31this._contexts = null;32}3334assign(CallbackQueue.prototype, {3536/**37* Enqueues a callback to be invoked when `notifyAll` is invoked.38*39* @param {function} callback Invoked when `notifyAll` is invoked.40* @param {?object} context Context to call `callback` with.41* @internal42*/43enqueue: function(callback, context) {44this._callbacks = this._callbacks || [];45this._contexts = this._contexts || [];46this._callbacks.push(callback);47this._contexts.push(context);48},4950/**51* Invokes all enqueued callbacks and clears the queue. This is invoked after52* the DOM representation of a component has been created or updated.53*54* @internal55*/56notifyAll: function() {57var callbacks = this._callbacks;58var contexts = this._contexts;59if (callbacks) {60("production" !== process.env.NODE_ENV ? invariant(61callbacks.length === contexts.length,62'Mismatched list of contexts in callback queue'63) : invariant(callbacks.length === contexts.length));64this._callbacks = null;65this._contexts = null;66for (var i = 0, l = callbacks.length; i < l; i++) {67callbacks[i].call(contexts[i]);68}69callbacks.length = 0;70contexts.length = 0;71}72},7374/**75* Resets the internal queue.76*77* @internal78*/79reset: function() {80this._callbacks = null;81this._contexts = null;82},8384/**85* `PooledClass` looks for this.86*/87destructor: function() {88this.reset();89}9091});9293PooledClass.addPoolingTo(CallbackQueue);9495module.exports = CallbackQueue;969798