Skip to content

Commit

Permalink
Merge pull request facebook#130 from zertosh/prevent-munge
Browse files Browse the repository at this point in the history
Add @preventMunge
  • Loading branch information
fisherwebdev committed Jan 24, 2015
2 parents 6c94d1d + dc6daed commit 974e13f
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 35 deletions.
69 changes: 35 additions & 34 deletions dist/Flux.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
module.exports.Dispatcher = require('./lib/Dispatcher')

},{"./lib/Dispatcher":2}],2:[function(require,module,exports){
/*
/**
* Copyright (c) 2014, Facebook, Inc.
* All rights reserved.
*
Expand All @@ -21,6 +21,7 @@ module.exports.Dispatcher = require('./lib/Dispatcher')
*
* @providesModule Dispatcher
* @typechecks
* @preventMunge
*/

"use strict";
Expand Down Expand Up @@ -119,11 +120,11 @@ var _prefix = 'ID_';
*/

function Dispatcher() {
this.$Dispatcher_callbacks = {};
this.$Dispatcher_isPending = {};
this.$Dispatcher_isHandled = {};
this.$Dispatcher_isDispatching = false;
this.$Dispatcher_pendingPayload = null;
this._callbacks = {};
this._isPending = {};
this._isHandled = {};
this._isDispatching = false;
this._pendingPayload = null;
}

/**
Expand All @@ -135,7 +136,7 @@ var _prefix = 'ID_';
*/
Dispatcher.prototype.register=function(callback) {
var id = _prefix + _lastID++;
this.$Dispatcher_callbacks[id] = callback;
this._callbacks[id] = callback;
return id;
};

Expand All @@ -146,11 +147,11 @@ var _prefix = 'ID_';
*/
Dispatcher.prototype.unregister=function(id) {
invariant(
this.$Dispatcher_callbacks[id],
this._callbacks[id],
'Dispatcher.unregister(...): `%s` does not map to a registered callback.',
id
);
delete this.$Dispatcher_callbacks[id];
delete this._callbacks[id];
};

/**
Expand All @@ -162,26 +163,26 @@ var _prefix = 'ID_';
*/
Dispatcher.prototype.waitFor=function(ids) {
invariant(
this.$Dispatcher_isDispatching,
this._isDispatching,
'Dispatcher.waitFor(...): Must be invoked while dispatching.'
);
for (var ii = 0; ii < ids.length; ii++) {
var id = ids[ii];
if (this.$Dispatcher_isPending[id]) {
if (this._isPending[id]) {
invariant(
this.$Dispatcher_isHandled[id],
this._isHandled[id],
'Dispatcher.waitFor(...): Circular dependency detected while ' +
'waiting for `%s`.',
id
);
continue;
}
invariant(
this.$Dispatcher_callbacks[id],
this._callbacks[id],
'Dispatcher.waitFor(...): `%s` does not map to a registered callback.',
id
);
this.$Dispatcher_invokeCallback(id);
this._invokeCallback(id);
}
};

Expand All @@ -192,19 +193,19 @@ var _prefix = 'ID_';
*/
Dispatcher.prototype.dispatch=function(payload) {
invariant(
!this.$Dispatcher_isDispatching,
!this._isDispatching,
'Dispatch.dispatch(...): Cannot dispatch in the middle of a dispatch.'
);
this.$Dispatcher_startDispatching(payload);
this._startDispatching(payload);
try {
for (var id in this.$Dispatcher_callbacks) {
if (this.$Dispatcher_isPending[id]) {
for (var id in this._callbacks) {
if (this._isPending[id]) {
continue;
}
this.$Dispatcher_invokeCallback(id);
this._invokeCallback(id);
}
} finally {
this.$Dispatcher_stopDispatching();
this._stopDispatching();
}
};

Expand All @@ -214,7 +215,7 @@ var _prefix = 'ID_';
* @return {boolean}
*/
Dispatcher.prototype.isDispatching=function() {
return this.$Dispatcher_isDispatching;
return this._isDispatching;
};

/**
Expand All @@ -224,10 +225,10 @@ var _prefix = 'ID_';
* @param {string} id
* @internal
*/
Dispatcher.prototype.$Dispatcher_invokeCallback=function(id) {
this.$Dispatcher_isPending[id] = true;
this.$Dispatcher_callbacks[id](this.$Dispatcher_pendingPayload);
this.$Dispatcher_isHandled[id] = true;
Dispatcher.prototype._invokeCallback=function(id) {
this._isPending[id] = true;
this._callbacks[id](this._pendingPayload);
this._isHandled[id] = true;
};

/**
Expand All @@ -236,23 +237,23 @@ var _prefix = 'ID_';
* @param {object} payload
* @internal
*/
Dispatcher.prototype.$Dispatcher_startDispatching=function(payload) {
for (var id in this.$Dispatcher_callbacks) {
this.$Dispatcher_isPending[id] = false;
this.$Dispatcher_isHandled[id] = false;
Dispatcher.prototype._startDispatching=function(payload) {
for (var id in this._callbacks) {
this._isPending[id] = false;
this._isHandled[id] = false;
}
this.$Dispatcher_pendingPayload = payload;
this.$Dispatcher_isDispatching = true;
this._pendingPayload = payload;
this._isDispatching = true;
};

/**
* Clear bookkeeping used for dispatching.
*
* @internal
*/
Dispatcher.prototype.$Dispatcher_stopDispatching=function() {
this.$Dispatcher_pendingPayload = null;
this.$Dispatcher_isDispatching = false;
Dispatcher.prototype._stopDispatching=function() {
this._pendingPayload = null;
this._isDispatching = false;
};


Expand Down
3 changes: 2 additions & 1 deletion src/Dispatcher.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/*
/**
* Copyright (c) 2014, Facebook, Inc.
* All rights reserved.
*
Expand All @@ -8,6 +8,7 @@
*
* @providesModule Dispatcher
* @typechecks
* @preventMunge
*/

"use strict";
Expand Down

0 comments on commit 974e13f

Please sign in to comment.