Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Download
80512 views
1
var Flummox =
2
/******/ (function(modules) { // webpackBootstrap
3
/******/ // The module cache
4
/******/ var installedModules = {};
5
6
/******/ // The require function
7
/******/ function __webpack_require__(moduleId) {
8
9
/******/ // Check if module is in cache
10
/******/ if(installedModules[moduleId])
11
/******/ return installedModules[moduleId].exports;
12
13
/******/ // Create a new module (and put it into the cache)
14
/******/ var module = installedModules[moduleId] = {
15
/******/ exports: {},
16
/******/ id: moduleId,
17
/******/ loaded: false
18
/******/ };
19
20
/******/ // Execute the module function
21
/******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);
22
23
/******/ // Flag the module as loaded
24
/******/ module.loaded = true;
25
26
/******/ // Return the exports of the module
27
/******/ return module.exports;
28
/******/ }
29
30
31
/******/ // expose the modules object (__webpack_modules__)
32
/******/ __webpack_require__.m = modules;
33
34
/******/ // expose the module cache
35
/******/ __webpack_require__.c = installedModules;
36
37
/******/ // __webpack_public_path__
38
/******/ __webpack_require__.p = "";
39
40
/******/ // Load entry module and return exports
41
/******/ return __webpack_require__(0);
42
/******/ })
43
/************************************************************************/
44
/******/ ([
45
/* 0 */
46
/***/ function(module, exports, __webpack_require__) {
47
48
'use strict';
49
50
var _interopRequire = function (obj) { return obj && obj.__esModule ? obj['default'] : obj; };
51
52
var _bind = Function.prototype.bind;
53
54
var _classCallCheck = function (instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError('Cannot call a class as a function'); } };
55
56
var _inherits = function (subClass, superClass) { if (typeof superClass !== 'function' && superClass !== null) { throw new TypeError('Super expression must either be null or a function, not ' + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) subClass.__proto__ = superClass; };
57
58
exports.__esModule = true;
59
/**
60
* Flux
61
*
62
* The main Flux class.
63
*/
64
65
var _Store = __webpack_require__(1);
66
67
var Store = _interopRequire(_Store);
68
69
var _Actions = __webpack_require__(2);
70
71
var Actions = _interopRequire(_Actions);
72
73
var _Dispatcher = __webpack_require__(3);
74
75
var _EventEmitter2 = __webpack_require__(4);
76
77
var EventEmitter = _interopRequire(_EventEmitter2);
78
79
var _assign = __webpack_require__(5);
80
81
var assign = _interopRequire(_assign);
82
83
var Flux = (function (_EventEmitter) {
84
function Flux() {
85
_classCallCheck(this, Flux);
86
87
_EventEmitter.call(this);
88
89
this.dispatcher = new _Dispatcher.Dispatcher();
90
91
this._stores = {};
92
this._actions = {};
93
}
94
95
_inherits(Flux, _EventEmitter);
96
97
Flux.prototype.createStore = function createStore(key, _Store) {
98
for (var _len = arguments.length, constructorArgs = Array(_len > 2 ? _len - 2 : 0), _key = 2; _key < _len; _key++) {
99
constructorArgs[_key - 2] = arguments[_key];
100
}
101
102
if (!(_Store.prototype instanceof Store)) {
103
var className = getClassName(_Store);
104
105
throw new Error('You\'ve attempted to create a store from the class ' + className + ', which ' + 'does not have the base Store class in its prototype chain. Make sure ' + ('you\'re using the `extends` keyword: `class ' + className + ' extends ') + 'Store { ... }`');
106
}
107
108
if (this._stores.hasOwnProperty(key) && this._stores[key]) {
109
throw new Error('You\'ve attempted to create multiple stores with key ' + key + '. Keys must ' + 'be unique.');
110
}
111
112
var store = new (_bind.apply(_Store, [null].concat(constructorArgs)))();
113
var token = this.dispatcher.register(store.handler.bind(store));
114
115
store._waitFor = this.waitFor.bind(this);
116
store._token = token;
117
store._getAllActionIds = this.getAllActionIds.bind(this);
118
119
this._stores[key] = store;
120
121
return store;
122
};
123
124
Flux.prototype.getStore = function getStore(key) {
125
return this._stores.hasOwnProperty(key) ? this._stores[key] : undefined;
126
};
127
128
Flux.prototype.removeStore = function removeStore(key) {
129
if (this._stores.hasOwnProperty(key)) {
130
this._stores[key].removeAllListeners();
131
this.dispatcher.unregister(this._stores[key]._token);
132
delete this._stores[key];
133
} else {
134
throw new Error('You\'ve attempted to remove store with key ' + key + ' which does not exist.');
135
}
136
};
137
138
Flux.prototype.createActions = function createActions(key, _Actions) {
139
for (var _len2 = arguments.length, constructorArgs = Array(_len2 > 2 ? _len2 - 2 : 0), _key2 = 2; _key2 < _len2; _key2++) {
140
constructorArgs[_key2 - 2] = arguments[_key2];
141
}
142
143
if (!(_Actions.prototype instanceof Actions) && _Actions !== Actions) {
144
if (typeof _Actions === 'function') {
145
var className = getClassName(_Actions);
146
147
throw new Error('You\'ve attempted to create actions from the class ' + className + ', which ' + 'does not have the base Actions class in its prototype chain. Make ' + ('sure you\'re using the `extends` keyword: `class ' + className + ' ') + 'extends Actions { ... }`');
148
} else {
149
var properties = _Actions;
150
_Actions = (function (_Actions2) {
151
var _class = function () {
152
_classCallCheck(this, _class);
153
154
if (_Actions2 != null) {
155
_Actions2.apply(this, arguments);
156
}
157
};
158
159
_inherits(_class, _Actions2);
160
161
return _class;
162
})(Actions);
163
assign(_Actions.prototype, properties);
164
}
165
}
166
167
if (this._actions.hasOwnProperty(key) && this._actions[key]) {
168
throw new Error('You\'ve attempted to create multiple actions with key ' + key + '. Keys ' + 'must be unique.');
169
}
170
171
var actions = new (_bind.apply(_Actions, [null].concat(constructorArgs)))();
172
actions.dispatch = this.dispatch.bind(this);
173
actions.dispatchAsync = this.dispatchAsync.bind(this);
174
175
this._actions[key] = actions;
176
177
return actions;
178
};
179
180
Flux.prototype.getActions = function getActions(key) {
181
return this._actions.hasOwnProperty(key) ? this._actions[key] : undefined;
182
};
183
184
Flux.prototype.getActionIds = function getActionIds(key) {
185
var actions = this.getActions(key);
186
187
if (!actions) {
188
return;
189
}return actions.getConstants();
190
};
191
192
Flux.prototype.removeActions = function removeActions(key) {
193
if (this._actions.hasOwnProperty(key)) {
194
delete this._actions[key];
195
} else {
196
throw new Error('You\'ve attempted to remove actions with key ' + key + ' which does not exist.');
197
}
198
};
199
200
Flux.prototype.getAllActionIds = function getAllActionIds() {
201
var actionIds = [];
202
203
for (var key in this._actions) {
204
if (!this._actions.hasOwnProperty(key)) continue;
205
206
var actionConstants = this._actions[key].getConstants();
207
208
actionIds = actionIds.concat(getValues(actionConstants));
209
}
210
211
return actionIds;
212
};
213
214
Flux.prototype.dispatch = function dispatch(actionId, body) {
215
this._dispatch({ actionId: actionId, body: body });
216
};
217
218
Flux.prototype.dispatchAsync = function dispatchAsync(actionId, promise, actionArgs) {
219
var _this = this;
220
221
var payload = {
222
actionId: actionId,
223
async: 'begin'
224
};
225
226
if (actionArgs) payload.actionArgs = actionArgs;
227
228
this._dispatch(payload);
229
230
return promise.then(function (body) {
231
_this._dispatch({
232
actionId: actionId,
233
body: body,
234
async: 'success'
235
});
236
237
return body;
238
}, function (error) {
239
_this._dispatch({
240
actionId: actionId,
241
error: error,
242
async: 'failure'
243
});
244
})['catch'](function (error) {
245
_this.emit('error', error);
246
247
throw error;
248
});
249
};
250
251
Flux.prototype._dispatch = function _dispatch(payload) {
252
this.dispatcher.dispatch(payload);
253
this.emit('dispatch', payload);
254
};
255
256
Flux.prototype.waitFor = function waitFor(tokensOrStores) {
257
258
if (!Array.isArray(tokensOrStores)) tokensOrStores = [tokensOrStores];
259
260
var ensureIsToken = function ensureIsToken(tokenOrStore) {
261
return tokenOrStore instanceof Store ? tokenOrStore._token : tokenOrStore;
262
};
263
264
var tokens = tokensOrStores.map(ensureIsToken);
265
266
this.dispatcher.waitFor(tokens);
267
};
268
269
Flux.prototype.removeAllStoreListeners = function removeAllStoreListeners(event) {
270
for (var key in this._stores) {
271
if (!this._stores.hasOwnProperty(key)) continue;
272
273
var store = this._stores[key];
274
275
store.removeAllListeners(event);
276
}
277
};
278
279
Flux.prototype.serialize = function serialize() {
280
var stateTree = {};
281
282
for (var key in this._stores) {
283
if (!this._stores.hasOwnProperty(key)) continue;
284
285
var store = this._stores[key];
286
287
var serialize = store.constructor.serialize;
288
289
if (typeof serialize !== 'function') continue;
290
291
var serializedStoreState = serialize(store.state);
292
293
if (typeof serializedStoreState !== 'string') {
294
var className = store.constructor.name;
295
296
if ((undefined) !== 'production') {
297
console.warn('The store with key \'' + key + '\' was not serialized because the static ' + ('method `' + className + '.serialize()` returned a non-string with type ') + ('\'' + typeof serializedStoreState + '\'.'));
298
}
299
}
300
301
stateTree[key] = serializedStoreState;
302
303
if (typeof store.constructor.deserialize !== 'function') {
304
var className = store.constructor.name;
305
306
if ((undefined) !== 'production') {
307
console.warn('The class `' + className + '` has a `serialize()` method, but no ' + 'corresponding `deserialize()` method.');
308
}
309
}
310
}
311
312
return JSON.stringify(stateTree);
313
};
314
315
Flux.prototype.deserialize = function deserialize(serializedState) {
316
var stateMap = undefined;
317
318
try {
319
stateMap = JSON.parse(serializedState);
320
} catch (error) {
321
var className = this.constructor.name;
322
323
if ((undefined) !== 'production') {
324
throw new Error('Invalid value passed to `' + className + '#deserialize()`: ' + ('' + serializedState));
325
}
326
}
327
328
for (var key in this._stores) {
329
if (!this._stores.hasOwnProperty(key)) continue;
330
331
var store = this._stores[key];
332
333
var deserialize = store.constructor.deserialize;
334
335
if (typeof deserialize !== 'function') continue;
336
337
var storeStateString = stateMap[key];
338
var storeState = deserialize(storeStateString);
339
340
store.replaceState(storeState);
341
342
if (typeof store.constructor.serialize !== 'function') {
343
var className = store.constructor.name;
344
345
if ((undefined) !== 'production') {
346
console.warn('The class `' + className + '` has a `deserialize()` method, but no ' + 'corresponding `serialize()` method.');
347
}
348
}
349
}
350
};
351
352
return Flux;
353
})(EventEmitter);
354
355
exports['default'] = Flux;
356
357
// Aliases
358
Flux.prototype.getConstants = Flux.prototype.getActionIds;
359
Flux.prototype.getAllConstants = Flux.prototype.getAllActionIds;
360
Flux.prototype.dehydrate = Flux.prototype.serialize;
361
Flux.prototype.hydrate = Flux.prototype.deserialize;
362
363
function getClassName(Class) {
364
return Class.prototype.constructor.name;
365
}
366
367
function getValues(object) {
368
var values = [];
369
370
for (var key in object) {
371
if (!object.hasOwnProperty(key)) continue;
372
373
values.push(object[key]);
374
}
375
376
return values;
377
}
378
379
var Flummox = Flux;
380
381
exports.Flux = Flux;
382
exports.Flummox = Flummox;
383
exports.Store = Store;
384
exports.Actions = Actions;
385
386
/***/ },
387
/* 1 */
388
/***/ function(module, exports, __webpack_require__) {
389
390
'use strict';
391
392
var _interopRequire = function (obj) { return obj && obj.__esModule ? obj['default'] : obj; };
393
394
var _classCallCheck = function (instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError('Cannot call a class as a function'); } };
395
396
var _inherits = function (subClass, superClass) { if (typeof superClass !== 'function' && superClass !== null) { throw new TypeError('Super expression must either be null or a function, not ' + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) subClass.__proto__ = superClass; };
397
398
/**
399
* Store
400
*
401
* Stores hold application state. They respond to actions sent by the dispatcher
402
* and broadcast change events to listeners, so they can grab the latest data.
403
* The key thing to remember is that the only way stores receive information
404
* from the outside world is via the dispatcher.
405
*/
406
407
var _EventEmitter2 = __webpack_require__(4);
408
409
var EventEmitter = _interopRequire(_EventEmitter2);
410
411
var _assign = __webpack_require__(5);
412
413
var assign = _interopRequire(_assign);
414
415
var Store = (function (_EventEmitter) {
416
417
/**
418
* Stores are initialized with a reference
419
* @type {Object}
420
*/
421
422
function Store() {
423
_classCallCheck(this, Store);
424
425
_EventEmitter.call(this);
426
427
this.state = null;
428
429
this._handlers = {};
430
this._asyncHandlers = {};
431
this._catchAllHandlers = [];
432
this._catchAllAsyncHandlers = {
433
begin: [],
434
success: [],
435
failure: [] };
436
}
437
438
_inherits(Store, _EventEmitter);
439
440
Store.prototype.setState = function setState(newState) {
441
// Do a transactional state update if a function is passed
442
if (typeof newState === 'function') {
443
var prevState = this._isHandlingDispatch ? this._pendingState : this.state;
444
445
newState = newState(prevState);
446
}
447
448
if (this._isHandlingDispatch) {
449
this._pendingState = this._assignState(this._pendingState, newState);
450
this._emitChangeAfterHandlingDispatch = true;
451
} else {
452
this.state = this._assignState(this.state, newState);
453
this.emit('change');
454
}
455
};
456
457
Store.prototype.replaceState = function replaceState(newState) {
458
if (this._isHandlingDispatch) {
459
this._pendingState = this._assignState(undefined, newState);
460
this._emitChangeAfterHandlingDispatch = true;
461
} else {
462
this.state = this._assignState(undefined, newState);
463
this.emit('change');
464
}
465
};
466
467
Store.prototype.getStateAsObject = function getStateAsObject() {
468
return this.state;
469
};
470
471
Store.assignState = function assignState(oldState, newState) {
472
return assign({}, oldState, newState);
473
};
474
475
Store.prototype._assignState = function _assignState() {
476
for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) {
477
args[_key] = arguments[_key];
478
}
479
480
return (this.constructor.assignState || Store.assignState).apply(undefined, args);
481
};
482
483
Store.prototype.forceUpdate = function forceUpdate() {
484
if (this._isHandlingDispatch) {
485
this._emitChangeAfterHandlingDispatch = true;
486
} else {
487
this.emit('change');
488
}
489
};
490
491
Store.prototype.register = function register(actionId, handler) {
492
actionId = ensureActionId(actionId);
493
494
if (typeof handler !== 'function') {
495
return;
496
}this._handlers[actionId] = handler.bind(this);
497
};
498
499
Store.prototype.registerAsync = function registerAsync(actionId, beginHandler, successHandler, failureHandler) {
500
actionId = ensureActionId(actionId);
501
502
var asyncHandlers = this._bindAsyncHandlers({
503
begin: beginHandler,
504
success: successHandler,
505
failure: failureHandler });
506
507
this._asyncHandlers[actionId] = asyncHandlers;
508
};
509
510
Store.prototype.registerAll = function registerAll(handler) {
511
if (typeof handler !== 'function') {
512
return;
513
}this._catchAllHandlers.push(handler.bind(this));
514
};
515
516
Store.prototype.registerAllAsync = function registerAllAsync(beginHandler, successHandler, failureHandler) {
517
var _this = this;
518
519
var asyncHandlers = this._bindAsyncHandlers({
520
begin: beginHandler,
521
success: successHandler,
522
failure: failureHandler });
523
524
Object.keys(asyncHandlers).forEach(function (key) {
525
_this._catchAllAsyncHandlers[key].push(asyncHandlers[key]);
526
});
527
};
528
529
Store.prototype._bindAsyncHandlers = function _bindAsyncHandlers(asyncHandlers) {
530
for (var key in asyncHandlers) {
531
if (!asyncHandlers.hasOwnProperty(key)) continue;
532
533
var handler = asyncHandlers[key];
534
535
if (typeof handler === 'function') {
536
asyncHandlers[key] = handler.bind(this);
537
} else {
538
delete asyncHandlers[key];
539
}
540
}
541
542
return asyncHandlers;
543
};
544
545
Store.prototype.waitFor = function waitFor(tokensOrStores) {
546
this._waitFor(tokensOrStores);
547
};
548
549
Store.prototype.handler = function handler(payload) {
550
var body = payload.body;
551
var actionId = payload.actionId;
552
var _async = payload.async;
553
var actionArgs = payload.actionArgs;
554
var error = payload.error;
555
556
var _allHandlers = this._catchAllHandlers;
557
var _handler = this._handlers[actionId];
558
559
var _allAsyncHandlers = this._catchAllAsyncHandlers[_async];
560
var _asyncHandler = this._asyncHandlers[actionId] && this._asyncHandlers[actionId][_async];
561
562
if (_async) {
563
var beginOrFailureHandlers = _allAsyncHandlers.concat([_asyncHandler]);
564
565
switch (_async) {
566
case 'begin':
567
this._performHandler(beginOrFailureHandlers, actionArgs);
568
return;
569
case 'failure':
570
this._performHandler(beginOrFailureHandlers, [error]);
571
return;
572
case 'success':
573
this._performHandler(_allAsyncHandlers.concat([_asyncHandler || _handler].concat(_asyncHandler && [] || _allHandlers)), [body]);
574
return;
575
default:
576
return;
577
}
578
}
579
580
this._performHandler(_allHandlers.concat([_handler]), [body]);
581
};
582
583
Store.prototype._performHandler = function _performHandler(_handlers, args) {
584
this._isHandlingDispatch = true;
585
this._pendingState = this._assignState(undefined, this.state);
586
this._emitChangeAfterHandlingDispatch = false;
587
588
try {
589
this._performHandlers(_handlers, args);
590
} finally {
591
if (this._emitChangeAfterHandlingDispatch) {
592
this.state = this._pendingState;
593
this.emit('change');
594
}
595
596
this._isHandlingDispatch = false;
597
this._pendingState = undefined;
598
this._emitChangeAfterHandlingDispatch = false;
599
}
600
};
601
602
Store.prototype._performHandlers = function _performHandlers(_handlers, args) {
603
var _this2 = this;
604
605
_handlers.forEach(function (_handler) {
606
return typeof _handler === 'function' && _handler.apply(_this2, args);
607
});
608
};
609
610
return Store;
611
})(EventEmitter);
612
613
module.exports = Store;
614
615
function ensureActionId(actionOrActionId) {
616
return typeof actionOrActionId === 'function' ? actionOrActionId._id : actionOrActionId;
617
}
618
619
/***/ },
620
/* 2 */
621
/***/ function(module, exports, __webpack_require__) {
622
623
'use strict';
624
625
var _interopRequire = function (obj) { return obj && obj.__esModule ? obj['default'] : obj; };
626
627
var _classCallCheck = function (instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError('Cannot call a class as a function'); } };
628
629
/**
630
* Actions
631
*
632
* Instances of the Actions class represent a set of actions. (In Flux parlance,
633
* these might be more accurately denoted as Action Creators, while Action
634
* refers to the payload sent to the dispatcher, but this is... confusing. We
635
* will use Action to mean the function you call to trigger a dispatch.)
636
*
637
* Create actions by extending from the base Actions class and adding methods.
638
* All methods on the prototype (except the constructor) will be
639
* converted into actions. The return value of an action is used as the body
640
* of the payload sent to the dispatcher.
641
*/
642
643
var _uniqueId = __webpack_require__(7);
644
645
var uniqueId = _interopRequire(_uniqueId);
646
647
var Actions = (function () {
648
function Actions() {
649
_classCallCheck(this, Actions);
650
651
this._baseId = uniqueId();
652
653
var methodNames = this._getActionMethodNames();
654
for (var i = 0; i < methodNames.length; i++) {
655
var methodName = methodNames[i];
656
this._wrapAction(methodName);
657
}
658
659
this.getConstants = this.getActionIds;
660
}
661
662
Actions.prototype.getActionIds = function getActionIds() {
663
var _this = this;
664
665
return this._getActionMethodNames().reduce(function (result, actionName) {
666
result[actionName] = _this[actionName]._id;
667
return result;
668
}, {});
669
};
670
671
Actions.prototype._getActionMethodNames = function _getActionMethodNames(instance) {
672
var _this2 = this;
673
674
return Object.getOwnPropertyNames(this.constructor.prototype).filter(function (name) {
675
return name !== 'constructor' && typeof _this2[name] === 'function';
676
});
677
};
678
679
Actions.prototype._wrapAction = function _wrapAction(methodName) {
680
var _this3 = this;
681
682
var originalMethod = this[methodName];
683
var actionId = this._createActionId(methodName);
684
685
var action = function action() {
686
for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) {
687
args[_key] = arguments[_key];
688
}
689
690
var body = originalMethod.apply(_this3, args);
691
692
if (isPromise(body)) {
693
var promise = body;
694
_this3._dispatchAsync(actionId, promise, args, methodName);
695
} else {
696
_this3._dispatch(actionId, body, args, methodName);
697
}
698
699
// Return original method's return value to caller
700
return body;
701
};
702
703
action._id = actionId;
704
705
this[methodName] = action;
706
};
707
708
/**
709
* Create unique string constant for an action method, using
710
* @param {string} methodName - Name of the action method
711
*/
712
713
Actions.prototype._createActionId = function _createActionId(methodName) {
714
return '' + this._baseId + '-' + methodName;
715
};
716
717
Actions.prototype._dispatch = function _dispatch(actionId, body, args, methodName) {
718
if (typeof this.dispatch === 'function') {
719
if (typeof body !== 'undefined') {
720
this.dispatch(actionId, body, args);
721
}
722
} else {
723
if ((undefined) !== 'production') {
724
console.warn('You\'ve attempted to perform the action ' + ('' + this.constructor.name + '#' + methodName + ', but it hasn\'t been added ') + 'to a Flux instance.');
725
}
726
}
727
728
return body;
729
};
730
731
Actions.prototype._dispatchAsync = function _dispatchAsync(actionId, promise, args, methodName) {
732
if (typeof this.dispatchAsync === 'function') {
733
this.dispatchAsync(actionId, promise, args);
734
} else {
735
if ((undefined) !== 'production') {
736
console.warn('You\'ve attempted to perform the asynchronous action ' + ('' + this.constructor.name + '#' + methodName + ', but it hasn\'t been added ') + 'to a Flux instance.');
737
}
738
}
739
};
740
741
return Actions;
742
})();
743
744
module.exports = Actions;
745
746
function isPromise(value) {
747
return value && typeof value.then === 'function';
748
}
749
750
/***/ },
751
/* 3 */
752
/***/ function(module, exports, __webpack_require__) {
753
754
/**
755
* Copyright (c) 2014, Facebook, Inc.
756
* All rights reserved.
757
*
758
* This source code is licensed under the BSD-style license found in the
759
* LICENSE file in the root directory of this source tree. An additional grant
760
* of patent rights can be found in the PATENTS file in the same directory.
761
*/
762
763
module.exports.Dispatcher = __webpack_require__(6)
764
765
766
/***/ },
767
/* 4 */
768
/***/ function(module, exports, __webpack_require__) {
769
770
'use strict';
771
772
/**
773
* Representation of a single EventEmitter function.
774
*
775
* @param {Function} fn Event handler to be called.
776
* @param {Mixed} context Context for function execution.
777
* @param {Boolean} once Only emit once
778
* @api private
779
*/
780
function EE(fn, context, once) {
781
this.fn = fn;
782
this.context = context;
783
this.once = once || false;
784
}
785
786
/**
787
* Minimal EventEmitter interface that is molded against the Node.js
788
* EventEmitter interface.
789
*
790
* @constructor
791
* @api public
792
*/
793
function EventEmitter() { /* Nothing to set */ }
794
795
/**
796
* Holds the assigned EventEmitters by name.
797
*
798
* @type {Object}
799
* @private
800
*/
801
EventEmitter.prototype._events = undefined;
802
803
/**
804
* Return a list of assigned event listeners.
805
*
806
* @param {String} event The events that should be listed.
807
* @returns {Array}
808
* @api public
809
*/
810
EventEmitter.prototype.listeners = function listeners(event) {
811
if (!this._events || !this._events[event]) return [];
812
if (this._events[event].fn) return [this._events[event].fn];
813
814
for (var i = 0, l = this._events[event].length, ee = new Array(l); i < l; i++) {
815
ee[i] = this._events[event][i].fn;
816
}
817
818
return ee;
819
};
820
821
/**
822
* Emit an event to all registered event listeners.
823
*
824
* @param {String} event The name of the event.
825
* @returns {Boolean} Indication if we've emitted an event.
826
* @api public
827
*/
828
EventEmitter.prototype.emit = function emit(event, a1, a2, a3, a4, a5) {
829
if (!this._events || !this._events[event]) return false;
830
831
var listeners = this._events[event]
832
, len = arguments.length
833
, args
834
, i;
835
836
if ('function' === typeof listeners.fn) {
837
if (listeners.once) this.removeListener(event, listeners.fn, true);
838
839
switch (len) {
840
case 1: return listeners.fn.call(listeners.context), true;
841
case 2: return listeners.fn.call(listeners.context, a1), true;
842
case 3: return listeners.fn.call(listeners.context, a1, a2), true;
843
case 4: return listeners.fn.call(listeners.context, a1, a2, a3), true;
844
case 5: return listeners.fn.call(listeners.context, a1, a2, a3, a4), true;
845
case 6: return listeners.fn.call(listeners.context, a1, a2, a3, a4, a5), true;
846
}
847
848
for (i = 1, args = new Array(len -1); i < len; i++) {
849
args[i - 1] = arguments[i];
850
}
851
852
listeners.fn.apply(listeners.context, args);
853
} else {
854
var length = listeners.length
855
, j;
856
857
for (i = 0; i < length; i++) {
858
if (listeners[i].once) this.removeListener(event, listeners[i].fn, true);
859
860
switch (len) {
861
case 1: listeners[i].fn.call(listeners[i].context); break;
862
case 2: listeners[i].fn.call(listeners[i].context, a1); break;
863
case 3: listeners[i].fn.call(listeners[i].context, a1, a2); break;
864
default:
865
if (!args) for (j = 1, args = new Array(len -1); j < len; j++) {
866
args[j - 1] = arguments[j];
867
}
868
869
listeners[i].fn.apply(listeners[i].context, args);
870
}
871
}
872
}
873
874
return true;
875
};
876
877
/**
878
* Register a new EventListener for the given event.
879
*
880
* @param {String} event Name of the event.
881
* @param {Functon} fn Callback function.
882
* @param {Mixed} context The context of the function.
883
* @api public
884
*/
885
EventEmitter.prototype.on = function on(event, fn, context) {
886
var listener = new EE(fn, context || this);
887
888
if (!this._events) this._events = {};
889
if (!this._events[event]) this._events[event] = listener;
890
else {
891
if (!this._events[event].fn) this._events[event].push(listener);
892
else this._events[event] = [
893
this._events[event], listener
894
];
895
}
896
897
return this;
898
};
899
900
/**
901
* Add an EventListener that's only called once.
902
*
903
* @param {String} event Name of the event.
904
* @param {Function} fn Callback function.
905
* @param {Mixed} context The context of the function.
906
* @api public
907
*/
908
EventEmitter.prototype.once = function once(event, fn, context) {
909
var listener = new EE(fn, context || this, true);
910
911
if (!this._events) this._events = {};
912
if (!this._events[event]) this._events[event] = listener;
913
else {
914
if (!this._events[event].fn) this._events[event].push(listener);
915
else this._events[event] = [
916
this._events[event], listener
917
];
918
}
919
920
return this;
921
};
922
923
/**
924
* Remove event listeners.
925
*
926
* @param {String} event The event we want to remove.
927
* @param {Function} fn The listener that we need to find.
928
* @param {Boolean} once Only remove once listeners.
929
* @api public
930
*/
931
EventEmitter.prototype.removeListener = function removeListener(event, fn, once) {
932
if (!this._events || !this._events[event]) return this;
933
934
var listeners = this._events[event]
935
, events = [];
936
937
if (fn) {
938
if (listeners.fn && (listeners.fn !== fn || (once && !listeners.once))) {
939
events.push(listeners);
940
}
941
if (!listeners.fn) for (var i = 0, length = listeners.length; i < length; i++) {
942
if (listeners[i].fn !== fn || (once && !listeners[i].once)) {
943
events.push(listeners[i]);
944
}
945
}
946
}
947
948
//
949
// Reset the array, or remove it completely if we have no more listeners.
950
//
951
if (events.length) {
952
this._events[event] = events.length === 1 ? events[0] : events;
953
} else {
954
delete this._events[event];
955
}
956
957
return this;
958
};
959
960
/**
961
* Remove all listeners or only the listeners for the specified event.
962
*
963
* @param {String} event The event want to remove all listeners for.
964
* @api public
965
*/
966
EventEmitter.prototype.removeAllListeners = function removeAllListeners(event) {
967
if (!this._events) return this;
968
969
if (event) delete this._events[event];
970
else this._events = {};
971
972
return this;
973
};
974
975
//
976
// Alias methods names because people roll like that.
977
//
978
EventEmitter.prototype.off = EventEmitter.prototype.removeListener;
979
EventEmitter.prototype.addListener = EventEmitter.prototype.on;
980
981
//
982
// This function doesn't apply anymore.
983
//
984
EventEmitter.prototype.setMaxListeners = function setMaxListeners() {
985
return this;
986
};
987
988
//
989
// Expose the module.
990
//
991
EventEmitter.EventEmitter = EventEmitter;
992
EventEmitter.EventEmitter2 = EventEmitter;
993
EventEmitter.EventEmitter3 = EventEmitter;
994
995
//
996
// Expose the module.
997
//
998
module.exports = EventEmitter;
999
1000
1001
/***/ },
1002
/* 5 */
1003
/***/ function(module, exports, __webpack_require__) {
1004
1005
'use strict';
1006
1007
function ToObject(val) {
1008
if (val == null) {
1009
throw new TypeError('Object.assign cannot be called with null or undefined');
1010
}
1011
1012
return Object(val);
1013
}
1014
1015
module.exports = Object.assign || function (target, source) {
1016
var from;
1017
var keys;
1018
var to = ToObject(target);
1019
1020
for (var s = 1; s < arguments.length; s++) {
1021
from = arguments[s];
1022
keys = Object.keys(Object(from));
1023
1024
for (var i = 0; i < keys.length; i++) {
1025
to[keys[i]] = from[keys[i]];
1026
}
1027
}
1028
1029
return to;
1030
};
1031
1032
1033
/***/ },
1034
/* 6 */
1035
/***/ function(module, exports, __webpack_require__) {
1036
1037
/*
1038
* Copyright (c) 2014, Facebook, Inc.
1039
* All rights reserved.
1040
*
1041
* This source code is licensed under the BSD-style license found in the
1042
* LICENSE file in the root directory of this source tree. An additional grant
1043
* of patent rights can be found in the PATENTS file in the same directory.
1044
*
1045
* @providesModule Dispatcher
1046
* @typechecks
1047
*/
1048
1049
"use strict";
1050
1051
var invariant = __webpack_require__(8);
1052
1053
var _lastID = 1;
1054
var _prefix = 'ID_';
1055
1056
/**
1057
* Dispatcher is used to broadcast payloads to registered callbacks. This is
1058
* different from generic pub-sub systems in two ways:
1059
*
1060
* 1) Callbacks are not subscribed to particular events. Every payload is
1061
* dispatched to every registered callback.
1062
* 2) Callbacks can be deferred in whole or part until other callbacks have
1063
* been executed.
1064
*
1065
* For example, consider this hypothetical flight destination form, which
1066
* selects a default city when a country is selected:
1067
*
1068
* var flightDispatcher = new Dispatcher();
1069
*
1070
* // Keeps track of which country is selected
1071
* var CountryStore = {country: null};
1072
*
1073
* // Keeps track of which city is selected
1074
* var CityStore = {city: null};
1075
*
1076
* // Keeps track of the base flight price of the selected city
1077
* var FlightPriceStore = {price: null}
1078
*
1079
* When a user changes the selected city, we dispatch the payload:
1080
*
1081
* flightDispatcher.dispatch({
1082
* actionType: 'city-update',
1083
* selectedCity: 'paris'
1084
* });
1085
*
1086
* This payload is digested by `CityStore`:
1087
*
1088
* flightDispatcher.register(function(payload) {
1089
* if (payload.actionType === 'city-update') {
1090
* CityStore.city = payload.selectedCity;
1091
* }
1092
* });
1093
*
1094
* When the user selects a country, we dispatch the payload:
1095
*
1096
* flightDispatcher.dispatch({
1097
* actionType: 'country-update',
1098
* selectedCountry: 'australia'
1099
* });
1100
*
1101
* This payload is digested by both stores:
1102
*
1103
* CountryStore.dispatchToken = flightDispatcher.register(function(payload) {
1104
* if (payload.actionType === 'country-update') {
1105
* CountryStore.country = payload.selectedCountry;
1106
* }
1107
* });
1108
*
1109
* When the callback to update `CountryStore` is registered, we save a reference
1110
* to the returned token. Using this token with `waitFor()`, we can guarantee
1111
* that `CountryStore` is updated before the callback that updates `CityStore`
1112
* needs to query its data.
1113
*
1114
* CityStore.dispatchToken = flightDispatcher.register(function(payload) {
1115
* if (payload.actionType === 'country-update') {
1116
* // `CountryStore.country` may not be updated.
1117
* flightDispatcher.waitFor([CountryStore.dispatchToken]);
1118
* // `CountryStore.country` is now guaranteed to be updated.
1119
*
1120
* // Select the default city for the new country
1121
* CityStore.city = getDefaultCityForCountry(CountryStore.country);
1122
* }
1123
* });
1124
*
1125
* The usage of `waitFor()` can be chained, for example:
1126
*
1127
* FlightPriceStore.dispatchToken =
1128
* flightDispatcher.register(function(payload) {
1129
* switch (payload.actionType) {
1130
* case 'country-update':
1131
* flightDispatcher.waitFor([CityStore.dispatchToken]);
1132
* FlightPriceStore.price =
1133
* getFlightPriceStore(CountryStore.country, CityStore.city);
1134
* break;
1135
*
1136
* case 'city-update':
1137
* FlightPriceStore.price =
1138
* FlightPriceStore(CountryStore.country, CityStore.city);
1139
* break;
1140
* }
1141
* });
1142
*
1143
* The `country-update` payload will be guaranteed to invoke the stores'
1144
* registered callbacks in order: `CountryStore`, `CityStore`, then
1145
* `FlightPriceStore`.
1146
*/
1147
1148
function Dispatcher() {
1149
this.$Dispatcher_callbacks = {};
1150
this.$Dispatcher_isPending = {};
1151
this.$Dispatcher_isHandled = {};
1152
this.$Dispatcher_isDispatching = false;
1153
this.$Dispatcher_pendingPayload = null;
1154
}
1155
1156
/**
1157
* Registers a callback to be invoked with every dispatched payload. Returns
1158
* a token that can be used with `waitFor()`.
1159
*
1160
* @param {function} callback
1161
* @return {string}
1162
*/
1163
Dispatcher.prototype.register=function(callback) {
1164
var id = _prefix + _lastID++;
1165
this.$Dispatcher_callbacks[id] = callback;
1166
return id;
1167
};
1168
1169
/**
1170
* Removes a callback based on its token.
1171
*
1172
* @param {string} id
1173
*/
1174
Dispatcher.prototype.unregister=function(id) {
1175
invariant(
1176
this.$Dispatcher_callbacks[id],
1177
'Dispatcher.unregister(...): `%s` does not map to a registered callback.',
1178
id
1179
);
1180
delete this.$Dispatcher_callbacks[id];
1181
};
1182
1183
/**
1184
* Waits for the callbacks specified to be invoked before continuing execution
1185
* of the current callback. This method should only be used by a callback in
1186
* response to a dispatched payload.
1187
*
1188
* @param {array<string>} ids
1189
*/
1190
Dispatcher.prototype.waitFor=function(ids) {
1191
invariant(
1192
this.$Dispatcher_isDispatching,
1193
'Dispatcher.waitFor(...): Must be invoked while dispatching.'
1194
);
1195
for (var ii = 0; ii < ids.length; ii++) {
1196
var id = ids[ii];
1197
if (this.$Dispatcher_isPending[id]) {
1198
invariant(
1199
this.$Dispatcher_isHandled[id],
1200
'Dispatcher.waitFor(...): Circular dependency detected while ' +
1201
'waiting for `%s`.',
1202
id
1203
);
1204
continue;
1205
}
1206
invariant(
1207
this.$Dispatcher_callbacks[id],
1208
'Dispatcher.waitFor(...): `%s` does not map to a registered callback.',
1209
id
1210
);
1211
this.$Dispatcher_invokeCallback(id);
1212
}
1213
};
1214
1215
/**
1216
* Dispatches a payload to all registered callbacks.
1217
*
1218
* @param {object} payload
1219
*/
1220
Dispatcher.prototype.dispatch=function(payload) {
1221
invariant(
1222
!this.$Dispatcher_isDispatching,
1223
'Dispatch.dispatch(...): Cannot dispatch in the middle of a dispatch.'
1224
);
1225
this.$Dispatcher_startDispatching(payload);
1226
try {
1227
for (var id in this.$Dispatcher_callbacks) {
1228
if (this.$Dispatcher_isPending[id]) {
1229
continue;
1230
}
1231
this.$Dispatcher_invokeCallback(id);
1232
}
1233
} finally {
1234
this.$Dispatcher_stopDispatching();
1235
}
1236
};
1237
1238
/**
1239
* Is this Dispatcher currently dispatching.
1240
*
1241
* @return {boolean}
1242
*/
1243
Dispatcher.prototype.isDispatching=function() {
1244
return this.$Dispatcher_isDispatching;
1245
};
1246
1247
/**
1248
* Call the callback stored with the given id. Also do some internal
1249
* bookkeeping.
1250
*
1251
* @param {string} id
1252
* @internal
1253
*/
1254
Dispatcher.prototype.$Dispatcher_invokeCallback=function(id) {
1255
this.$Dispatcher_isPending[id] = true;
1256
this.$Dispatcher_callbacks[id](this.$Dispatcher_pendingPayload);
1257
this.$Dispatcher_isHandled[id] = true;
1258
};
1259
1260
/**
1261
* Set up bookkeeping needed when dispatching.
1262
*
1263
* @param {object} payload
1264
* @internal
1265
*/
1266
Dispatcher.prototype.$Dispatcher_startDispatching=function(payload) {
1267
for (var id in this.$Dispatcher_callbacks) {
1268
this.$Dispatcher_isPending[id] = false;
1269
this.$Dispatcher_isHandled[id] = false;
1270
}
1271
this.$Dispatcher_pendingPayload = payload;
1272
this.$Dispatcher_isDispatching = true;
1273
};
1274
1275
/**
1276
* Clear bookkeeping used for dispatching.
1277
*
1278
* @internal
1279
*/
1280
Dispatcher.prototype.$Dispatcher_stopDispatching=function() {
1281
this.$Dispatcher_pendingPayload = null;
1282
this.$Dispatcher_isDispatching = false;
1283
};
1284
1285
1286
module.exports = Dispatcher;
1287
1288
1289
/***/ },
1290
/* 7 */
1291
/***/ function(module, exports, __webpack_require__) {
1292
1293
'use strict';
1294
1295
1296
var count = 0;
1297
1298
/**
1299
* Generate a unique ID.
1300
*
1301
* Optionally pass a prefix to prepend, a suffix to append, or a
1302
* multiplier to use on the ID.
1303
*
1304
* ```js
1305
* uniqueId(); //=> '25'
1306
*
1307
* uniqueId({prefix: 'apple_'});
1308
* //=> 'apple_10'
1309
*
1310
* uniqueId({suffix: '_orange'});
1311
* //=> '10_orange'
1312
*
1313
* uniqueId({multiplier: 5});
1314
* //=> 5, 10, 15, 20...
1315
* ```
1316
*
1317
* To reset the `id` to zero, do `id.reset()`.
1318
*
1319
* @param {Object} `options` Optionally pass a `prefix`, `suffix` and/or `multiplier.
1320
* @return {String} The unique id.
1321
* @api public
1322
*/
1323
1324
var id = module.exports = function (options) {
1325
options = options || {};
1326
1327
var prefix = options.prefix;
1328
var suffix = options.suffix;
1329
1330
var id = ++count * (options.multiplier || 1);
1331
1332
if (prefix == null) {
1333
prefix = '';
1334
}
1335
1336
if (suffix == null) {
1337
suffix = '';
1338
}
1339
1340
return String(prefix) + id + String(suffix);
1341
};
1342
1343
1344
id.reset = function() {
1345
return count = 0;
1346
};
1347
1348
/***/ },
1349
/* 8 */
1350
/***/ function(module, exports, __webpack_require__) {
1351
1352
/**
1353
* Copyright (c) 2014, Facebook, Inc.
1354
* All rights reserved.
1355
*
1356
* This source code is licensed under the BSD-style license found in the
1357
* LICENSE file in the root directory of this source tree. An additional grant
1358
* of patent rights can be found in the PATENTS file in the same directory.
1359
*
1360
* @providesModule invariant
1361
*/
1362
1363
"use strict";
1364
1365
/**
1366
* Use invariant() to assert state which your program assumes to be true.
1367
*
1368
* Provide sprintf-style format (only %s is supported) and arguments
1369
* to provide information about what broke and what you were
1370
* expecting.
1371
*
1372
* The invariant message will be stripped in production, but the invariant
1373
* will remain to ensure logic does not differ in production.
1374
*/
1375
1376
var invariant = function(condition, format, a, b, c, d, e, f) {
1377
if (false) {
1378
if (format === undefined) {
1379
throw new Error('invariant requires an error message argument');
1380
}
1381
}
1382
1383
if (!condition) {
1384
var error;
1385
if (format === undefined) {
1386
error = new Error(
1387
'Minified exception occurred; use the non-minified dev environment ' +
1388
'for the full error message and additional helpful warnings.'
1389
);
1390
} else {
1391
var args = [a, b, c, d, e, f];
1392
var argIndex = 0;
1393
error = new Error(
1394
'Invariant Violation: ' +
1395
format.replace(/%s/g, function() { return args[argIndex++]; })
1396
);
1397
}
1398
1399
error.framesToPop = 1; // we don't care about invariant's own frame
1400
throw error;
1401
}
1402
};
1403
1404
module.exports = invariant;
1405
1406
1407
/***/ }
1408
/******/ ]);
1409