(function(f){if(typeof exports==="object"&&typeof module!=="undefined"){module.exports=f()}else if(typeof define==="function"&&define.amd){define([],f)}else{var g;if(typeof window!=="undefined"){g=window}else if(typeof global!=="undefined"){g=global}else if(typeof self!=="undefined"){g=self}else{g=this}g.Flux = f()}})(function(){var define,module,exports;return (function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(require,module,exports){1/**2* Copyright (c) 2014-2015, Facebook, Inc.3* All rights reserved.4*5* This source code is licensed under the BSD-style license found in the6* LICENSE file in the root directory of this source tree. An additional grant7* of patent rights can be found in the PATENTS file in the same directory.8*/910module.exports.Dispatcher = require('./lib/Dispatcher')1112},{"./lib/Dispatcher":2}],2:[function(require,module,exports){13/**14* Copyright (c) 2014-2015, Facebook, Inc.15* All rights reserved.16*17* This source code is licensed under the BSD-style license found in the18* LICENSE file in the root directory of this source tree. An additional grant19* of patent rights can be found in the PATENTS file in the same directory.20*21* @providesModule Dispatcher22* @typechecks23* @preventMunge24*/2526"use strict";2728var invariant = require('./invariant');2930var _prefix = 'ID_';3132/**33* Dispatcher is used to broadcast payloads to registered callbacks. This is34* different from generic pub-sub systems in two ways:35*36* 1) Callbacks are not subscribed to particular events. Every payload is37* dispatched to every registered callback.38* 2) Callbacks can be deferred in whole or part until other callbacks have39* been executed.40*41* For example, consider this hypothetical flight destination form, which42* selects a default city when a country is selected:43*44* var flightDispatcher = new Dispatcher();45*46* // Keeps track of which country is selected47* var CountryStore = {country: null};48*49* // Keeps track of which city is selected50* var CityStore = {city: null};51*52* // Keeps track of the base flight price of the selected city53* var FlightPriceStore = {price: null}54*55* When a user changes the selected city, we dispatch the payload:56*57* flightDispatcher.dispatch({58* actionType: 'city-update',59* selectedCity: 'paris'60* });61*62* This payload is digested by `CityStore`:63*64* flightDispatcher.register(function(payload) {65* if (payload.actionType === 'city-update') {66* CityStore.city = payload.selectedCity;67* }68* });69*70* When the user selects a country, we dispatch the payload:71*72* flightDispatcher.dispatch({73* actionType: 'country-update',74* selectedCountry: 'australia'75* });76*77* This payload is digested by both stores:78*79* CountryStore.dispatchToken = flightDispatcher.register(function(payload) {80* if (payload.actionType === 'country-update') {81* CountryStore.country = payload.selectedCountry;82* }83* });84*85* When the callback to update `CountryStore` is registered, we save a reference86* to the returned token. Using this token with `waitFor()`, we can guarantee87* that `CountryStore` is updated before the callback that updates `CityStore`88* needs to query its data.89*90* CityStore.dispatchToken = flightDispatcher.register(function(payload) {91* if (payload.actionType === 'country-update') {92* // `CountryStore.country` may not be updated.93* flightDispatcher.waitFor([CountryStore.dispatchToken]);94* // `CountryStore.country` is now guaranteed to be updated.95*96* // Select the default city for the new country97* CityStore.city = getDefaultCityForCountry(CountryStore.country);98* }99* });100*101* The usage of `waitFor()` can be chained, for example:102*103* FlightPriceStore.dispatchToken =104* flightDispatcher.register(function(payload) {105* switch (payload.actionType) {106* case 'country-update':107* case 'city-update':108* flightDispatcher.waitFor([CityStore.dispatchToken]);109* FlightPriceStore.price =110* getFlightPriceStore(CountryStore.country, CityStore.city);111* break;112* }113* });114*115* The `country-update` payload will be guaranteed to invoke the stores'116* registered callbacks in order: `CountryStore`, `CityStore`, then117* `FlightPriceStore`.118*/119120function Dispatcher() {121this._lastID = 1;122this._callbacks = {};123this._isPending = {};124this._isHandled = {};125this._isDispatching = false;126this._pendingPayload = null;127}128129/**130* Registers a callback to be invoked with every dispatched payload. Returns131* a token that can be used with `waitFor()`.132*133* @param {function} callback134* @return {string}135*/136Dispatcher.prototype.register=function(callback) {137var id = _prefix + this._lastID++;138this._callbacks[id] = callback;139return id;140};141142/**143* Removes a callback based on its token.144*145* @param {string} id146*/147Dispatcher.prototype.unregister=function(id) {148invariant(149this._callbacks[id],150'Dispatcher.unregister(...): `%s` does not map to a registered callback.',151id152);153delete this._callbacks[id];154};155156/**157* Waits for the callbacks specified to be invoked before continuing execution158* of the current callback. This method should only be used by a callback in159* response to a dispatched payload.160*161* @param {array<string>} ids162*/163Dispatcher.prototype.waitFor=function(ids) {164invariant(165this._isDispatching,166'Dispatcher.waitFor(...): Must be invoked while dispatching.'167);168for (var ii = 0; ii < ids.length; ii++) {169var id = ids[ii];170if (this._isPending[id]) {171invariant(172this._isHandled[id],173'Dispatcher.waitFor(...): Circular dependency detected while ' +174'waiting for `%s`.',175id176);177continue;178}179invariant(180this._callbacks[id],181'Dispatcher.waitFor(...): `%s` does not map to a registered callback.',182id183);184this._invokeCallback(id);185}186};187188/**189* Dispatches a payload to all registered callbacks.190*191* @param {object} payload192*/193Dispatcher.prototype.dispatch=function(payload) {194invariant(195!this._isDispatching,196'Dispatch.dispatch(...): Cannot dispatch in the middle of a dispatch.'197);198this._startDispatching(payload);199try {200for (var id in this._callbacks) {201if (this._isPending[id]) {202continue;203}204this._invokeCallback(id);205}206} finally {207this._stopDispatching();208}209};210211/**212* Is this Dispatcher currently dispatching.213*214* @return {boolean}215*/216Dispatcher.prototype.isDispatching=function() {217return this._isDispatching;218};219220/**221* Call the callback stored with the given id. Also do some internal222* bookkeeping.223*224* @param {string} id225* @internal226*/227Dispatcher.prototype._invokeCallback=function(id) {228this._isPending[id] = true;229this._callbacks[id](this._pendingPayload);230this._isHandled[id] = true;231};232233/**234* Set up bookkeeping needed when dispatching.235*236* @param {object} payload237* @internal238*/239Dispatcher.prototype._startDispatching=function(payload) {240for (var id in this._callbacks) {241this._isPending[id] = false;242this._isHandled[id] = false;243}244this._pendingPayload = payload;245this._isDispatching = true;246};247248/**249* Clear bookkeeping used for dispatching.250*251* @internal252*/253Dispatcher.prototype._stopDispatching=function() {254this._pendingPayload = null;255this._isDispatching = false;256};257258259module.exports = Dispatcher;260261},{"./invariant":3}],3:[function(require,module,exports){262/**263* Copyright (c) 2014-2015, Facebook, Inc.264* All rights reserved.265*266* This source code is licensed under the BSD-style license found in the267* LICENSE file in the root directory of this source tree. An additional grant268* of patent rights can be found in the PATENTS file in the same directory.269*270* @providesModule invariant271*/272273"use strict";274275/**276* Use invariant() to assert state which your program assumes to be true.277*278* Provide sprintf-style format (only %s is supported) and arguments279* to provide information about what broke and what you were280* expecting.281*282* The invariant message will be stripped in production, but the invariant283* will remain to ensure logic does not differ in production.284*/285286var invariant = function(condition, format, a, b, c, d, e, f) {287if (false) {288if (format === undefined) {289throw new Error('invariant requires an error message argument');290}291}292293if (!condition) {294var error;295if (format === undefined) {296error = new Error(297'Minified exception occurred; use the non-minified dev environment ' +298'for the full error message and additional helpful warnings.'299);300} else {301var args = [a, b, c, d, e, f];302var argIndex = 0;303error = new Error(304'Invariant Violation: ' +305format.replace(/%s/g, function() { return args[argIndex++]; })306);307}308309error.framesToPop = 1; // we don't care about invariant's own frame310throw error;311}312};313314module.exports = invariant;315316},{}]},{},[1])(1)317});318319