1(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.Alt = 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){ 2"use strict"; 3 4var globalSymbolRegistryList = {}; 5 6// Aliases & Helpers 7var make = Object.create; 8var defProps = Object.defineProperties; 9var defProp = Object.defineProperty; 10var defValue = function (value) { 11 var opts = arguments[1] === undefined ? {} : arguments[1]; 12 return { 13 value: value, 14 configurable: !!opts.c, 15 writable: !!opts.w, 16 enumerable: !!opts.e 17 }; 18}; 19var isSymbol = function (symbol) { 20 return symbol && symbol[xSymbol.toStringTag] === "Symbol"; 21}; 22 23var supportsAccessors = undefined; 24try { 25 var x = defProp({}, "y", { get: function () { 26 return 1; 27 } }); 28 supportsAccessors = x.y === 1; 29} catch (e) { 30 supportsAccessors = false; 31} 32 33var id = {}; 34var uid = function (desc) { 35 desc = String(desc); 36 var x = ""; 37 var i = 0; 38 while (id[desc + x]) { 39 x = i += 1; 40 } 41 id[desc + x] = 1; 42 43 var tag = "Symbol(" + desc + "" + x + ")"; 44 45 /* istanbul ignore else */ 46 if (supportsAccessors) { 47 // Make the symbols hidden to pre-es6 code 48 defProp(Object.prototype, tag, { 49 get: undefined, 50 set: function (value) { 51 defProp(this, tag, defValue(value, { c: true, w: true })); 52 }, 53 configurable: true, 54 enumerable: false 55 }); 56 } 57 58 return tag; 59}; 60 61// The base symbol 62var SymbolProto = make(null); 63 64// 19.4.1.1 65function xSymbol(descString) { 66 if (this instanceof xSymbol) { 67 throw new TypeError("Symbol is not a constructor"); 68 } 69 70 descString = descString === undefined ? "" : String(descString); 71 72 var tag = uid(descString); 73 74 /* istanbul ignore next */ 75 if (!supportsAccessors) { 76 return tag; 77 } 78 79 return make(SymbolProto, { 80 __description__: defValue(descString), 81 __tag__: defValue(tag) 82 }); 83} 84 85defProps(xSymbol, { 86 // 19.4.2.1 87 "for": defValue(function (key) { 88 var stringKey = String(key); 89 90 if (globalSymbolRegistryList[stringKey]) { 91 return globalSymbolRegistryList[stringKey]; 92 } 93 94 var symbol = xSymbol(stringKey); 95 globalSymbolRegistryList[stringKey] = symbol; 96 97 return symbol; 98 }), 99 100 // 19.4.2.5 101 keyFor: defValue(function (sym) { 102 if (supportsAccessors && !isSymbol(sym)) { 103 throw new TypeError("" + sym + " is not a symbol"); 104 } 105 106 for (var key in globalSymbolRegistryList) { 107 if (globalSymbolRegistryList[key] === sym) { 108 return supportsAccessors ? globalSymbolRegistryList[key].__description__ : globalSymbolRegistryList[key].substr(7, globalSymbolRegistryList[key].length - 8); 109 } 110 } 111 }) 112}); 113 114// 6.1.5.1 115defProps(xSymbol, { 116 hasInstance: defValue(xSymbol("hasInstance")), 117 isConcatSpreadable: defValue(xSymbol("isConcatSpreadable")), 118 iterator: defValue(xSymbol("iterator")), 119 match: defValue(xSymbol("match")), 120 replace: defValue(xSymbol("replace")), 121 search: defValue(xSymbol("search")), 122 species: defValue(xSymbol("species")), 123 split: defValue(xSymbol("split")), 124 toPrimitive: defValue(xSymbol("toPrimitive")), 125 toStringTag: defValue(xSymbol("toStringTag")), 126 unscopables: defValue(xSymbol("unscopables")) 127}); 128 129// 19.4.3 130defProps(SymbolProto, { 131 constructor: defValue(xSymbol), 132 133 // 19.4.3.2 134 toString: defValue(function () { 135 return this.__tag__; 136 }), 137 138 // 19.4.3.3 139 valueOf: defValue(function () { 140 return "Symbol(" + this.__description__ + ")"; 141 }) 142}); 143 144// 19.4.3.5 145/* istanbul ignore else */ 146if (supportsAccessors) { 147 defProp(SymbolProto, xSymbol.toStringTag, defValue("Symbol", { c: true })); 148} 149 150module.exports = typeof Symbol === "function" ? Symbol : xSymbol; 151 152 153},{}],2:[function(require,module,exports){ 154'use strict'; 155 156/** 157 * Representation of a single EventEmitter function. 158 * 159 * @param {Function} fn Event handler to be called. 160 * @param {Mixed} context Context for function execution. 161 * @param {Boolean} once Only emit once 162 * @api private 163 */ 164function EE(fn, context, once) { 165 this.fn = fn; 166 this.context = context; 167 this.once = once || false; 168} 169 170/** 171 * Minimal EventEmitter interface that is molded against the Node.js 172 * EventEmitter interface. 173 * 174 * @constructor 175 * @api public 176 */ 177function EventEmitter() { /* Nothing to set */ } 178 179/** 180 * Holds the assigned EventEmitters by name. 181 * 182 * @type {Object} 183 * @private 184 */ 185EventEmitter.prototype._events = undefined; 186 187/** 188 * Return a list of assigned event listeners. 189 * 190 * @param {String} event The events that should be listed. 191 * @returns {Array} 192 * @api public 193 */ 194EventEmitter.prototype.listeners = function listeners(event) { 195 if (!this._events || !this._events[event]) return []; 196 if (this._events[event].fn) return [this._events[event].fn]; 197 198 for (var i = 0, l = this._events[event].length, ee = new Array(l); i < l; i++) { 199 ee[i] = this._events[event][i].fn; 200 } 201 202 return ee; 203}; 204 205/** 206 * Emit an event to all registered event listeners. 207 * 208 * @param {String} event The name of the event. 209 * @returns {Boolean} Indication if we've emitted an event. 210 * @api public 211 */ 212EventEmitter.prototype.emit = function emit(event, a1, a2, a3, a4, a5) { 213 if (!this._events || !this._events[event]) return false;
214 215 var listeners = this._events[event] 216 , len = arguments.length 217 , args 218 , i; 219 220 if ('function' === typeof listeners.fn) { 221 if (listeners.once) this.removeListener(event, listeners.fn, true); 222 223 switch (len) { 224 case 1: return listeners.fn.call(listeners.context), true; 225 case 2: return listeners.fn.call(listeners.context, a1), true; 226 case 3: return listeners.fn.call(listeners.context, a1, a2), true; 227 case 4: return listeners.fn.call(listeners.context, a1, a2, a3), true; 228 case 5: return listeners.fn.call(listeners.context, a1, a2, a3, a4), true; 229 case 6: return listeners.fn.call(listeners.context, a1, a2, a3, a4, a5), true; 230 } 231 232 for (i = 1, args = new Array(len -1); i < len; i++) { 233 args[i - 1] = arguments[i]; 234 } 235 236 listeners.fn.apply(listeners.context, args); 237 } else { 238 var length = listeners.length 239 , j; 240 241 for (i = 0; i < length; i++) { 242 if (listeners[i].once) this.removeListener(event, listeners[i].fn, true); 243 244 switch (len) { 245 case 1: listeners[i].fn.call(listeners[i].context); break; 246 case 2: listeners[i].fn.call(listeners[i].context, a1); break; 247 case 3: listeners[i].fn.call(listeners[i].context, a1, a2); break; 248 default: 249 if (!args) for (j = 1, args = new Array(len -1); j < len; j++) { 250 args[j - 1] = arguments[j]; 251 } 252 253 listeners[i].fn.apply(listeners[i].context, args); 254 } 255 } 256 } 257 258 return true; 259}; 260 261/** 262 * Register a new EventListener for the given event. 263 * 264 * @param {String} event Name of the event. 265 * @param {Functon} fn Callback function. 266 * @param {Mixed} context The context of the function. 267 * @api public 268 */ 269EventEmitter.prototype.on = function on(event, fn, context) { 270 var listener = new EE(fn, context || this); 271 272 if (!this._events) this._events = {}; 273 if (!this._events[event]) this._events[event] = listener; 274 else { 275 if (!this._events[event].fn) this._events[event].push(listener); 276 else this._events[event] = [ 277 this._events[event], listener 278 ]; 279 } 280 281 return this; 282}; 283 284/** 285 * Add an EventListener that's only called once. 286 * 287 * @param {String} event Name of the event. 288 * @param {Function} fn Callback function. 289 * @param {Mixed} context The context of the function. 290 * @api public 291 */ 292EventEmitter.prototype.once = function once(event, fn, context) { 293 var listener = new EE(fn, context || this, true); 294 295 if (!this._events) this._events = {}; 296 if (!this._events[event]) this._events[event] = listener; 297 else { 298 if (!this._events[event].fn) this._events[event].push(listener); 299 else this._events[event] = [ 300 this._events[event], listener 301 ]; 302 } 303 304 return this; 305}; 306 307/** 308 * Remove event listeners. 309 * 310 * @param {String} event The event we want to remove. 311 * @param {Function} fn The listener that we need to find. 312 * @param {Boolean} once Only remove once listeners. 313 * @api public 314 */ 315EventEmitter.prototype.removeListener = function removeListener(event, fn, once) { 316 if (!this._events || !this._events[event]) return this; 317 318 var listeners = this._events[event] 319 , events = []; 320 321 if (fn) { 322 if (listeners.fn && (listeners.fn !== fn || (once && !listeners.once))) { 323 events.push(listeners); 324 } 325 if (!listeners.fn) for (var i = 0, length = listeners.length; i < length; i++) { 326 if (listeners[i].fn !== fn || (once && !listeners[i].once)) { 327 events.push(listeners[i]); 328 } 329 } 330 } 331 332 // 333 // Reset the array, or remove it completely if we have no more listeners. 334 // 335 if (events.length) { 336 this._events[event] = events.length === 1 ? events[0] : events; 337 } else { 338 delete this._events[event]; 339 } 340 341 return this; 342}; 343 344/** 345 * Remove all listeners or only the listeners for the specified event. 346 * 347 * @param {String} event The event want to remove all listeners for. 348 * @api public 349 */ 350EventEmitter.prototype.removeAllListeners = function removeAllListeners(event) { 351 if (!this._events) return this; 352 353 if (event) delete this._events[event]; 354 else this._events = {}; 355 356 return this; 357}; 358 359// 360// Alias methods names because people roll like that. 361// 362EventEmitter.prototype.off = EventEmitter.prototype.removeListener; 363EventEmitter.prototype.addListener = EventEmitter.prototype.on; 364 365// 366// This function doesn't apply anymore. 367// 368EventEmitter.prototype.setMaxListeners = function setMaxListeners() { 369 return this; 370}; 371 372// 373// Expose the module. 374// 375EventEmitter.EventEmitter = EventEmitter; 376EventEmitter.EventEmitter2 = EventEmitter; 377EventEmitter.EventEmitter3 = EventEmitter; 378 379// 380// Expose the module. 381// 382module.exports = EventEmitter; 383 384},{}],3:[function(require,module,exports){ 385/** 386 * Copyright (c) 2014-2015, Facebook, Inc. 387 * All rights reserved. 388 * 389 * This source code is licensed under the BSD-style license found in the 390 * LICENSE file in the root directory of this source tree. An additional grant 391 * of patent rights can be found in the PATENTS file in the same directory. 392 */ 393 394module.exports.Dispatcher = require('./lib/Dispatcher') 395 396},{"./lib/Dispatcher":4}],4:[function(require,module,exports){ 397/* 398 * Copyright (c) 2014, Facebook, Inc. 399 * All rights reserved. 400 * 401 * This source code is licensed under the BSD-style license found in the 402 * LICENSE file in the root directory of this source tree. An additional grant 403 * of patent rights can be found in the PATENTS file in the same directory. 404 * 405 * @providesModule Dispatcher 406 * @typechecks 407 */ 408 409"use strict"; 410 411var invariant = require('./invariant'); 412 413var _lastID = 1; 414var _prefix = 'ID_'; 415 416/** 417 * Dispatcher is used to broadcast payloads to registered callbacks. This is 418 * different from generic pub-sub systems in two ways: 419 * 420 * 1) Callbacks are not subscribed to particular events. Every payload is 421 * dispatched to every registered callback. 422 * 2) Callbacks can be deferred in whole or part until other callbacks have 423 * been executed. 424 * 425 * For example, consider this hypothetical flight destination form, which 426 * selects a default city when a country is selected: 427 * 428 * var flightDispatcher = new Dispatcher(); 429 * 430 * // Keeps track of which country is selected 431 * var CountryStore = {country: null}; 432 * 433 * // Keeps track of which city is selected 434 * var CityStore = {city: null}; 435 * 436 * // Keeps track of the base flight price of the selected city 437 * var FlightPriceStore = {price: null} 438 * 439 * When a user changes the selected city, we dispatch the payload: 440 * 441 * flightDispatcher.dispatch({ 442 * actionType: 'city-update', 443 * selectedCity: 'paris' 444 * }); 445 * 446 * This payload is digested by `CityStore`: 447 * 448 * flightDispatcher.register(function(payload) { 449 * if (payload.actionType === 'city-update') { 450 * CityStore.city = payload.selectedCity; 451 * } 452 * }); 453 * 454 * When the user selects a country, we dispatch the payload: 455 * 456 * flightDispatcher.dispatch({ 457 * actionType: 'country-update', 458 * selectedCountry: 'australia' 459 * }); 460 * 461 * This payload is digested by both stores: 462 * 463 * CountryStore.dispatchToken = flightDispatcher.register(function(payload) { 464 * if (payload.actionType === 'country-update') { 465 * CountryStore.country = payload.selectedCountry; 466 * } 467 * }); 468 * 469 * When the callback to update `CountryStore` is registered, we save a reference 470 * to the returned token. Using this token with `waitFor()`, we can guarantee 471 * that `CountryStore` is updated before the callback that updates `CityStore` 472 * needs to query its data. 473 * 474 * CityStore.dispatchToken = flightDispatcher.register(function(payload) { 475 * if (payload.actionType === 'country-update') { 476 * // `CountryStore.country` may not be updated. 477 * flightDispatcher.waitFor([CountryStore.dispatchToken]); 478 * // `CountryStore.country` is now guaranteed to be updated. 479 * 480 * // Select the default city for the new country 481 * CityStore.city = getDefaultCityForCountry(CountryStore.country); 482 * } 483 * }); 484 * 485 * The usage of `waitFor()` can be chained, for example: 486 * 487 * FlightPriceStore.dispatchToken = 488 * flightDispatcher.register(function(payload) { 489 * switch (payload.actionType) { 490 * case 'country-update': 491 * flightDispatcher.waitFor([CityStore.dispatchToken]); 492 * FlightPriceStore.price = 493 * getFlightPriceStore(CountryStore.country, CityStore.city); 494 * break; 495 * 496 * case 'city-update': 497 * FlightPriceStore.price = 498 * FlightPriceStore(CountryStore.country, CityStore.city); 499 * break; 500 * } 501 * }); 502 * 503 * The `country-update` payload will be guaranteed to invoke the stores' 504 * registered callbacks in order: `CountryStore`, `CityStore`, then 505 * `FlightPriceStore`. 506 */ 507
508 function Dispatcher() { 509 this.$Dispatcher_callbacks = {}; 510 this.$Dispatcher_isPending = {}; 511 this.$Dispatcher_isHandled = {}; 512 this.$Dispatcher_isDispatching = false; 513 this.$Dispatcher_pendingPayload = null; 514 } 515 516 /** 517 * Registers a callback to be invoked with every dispatched payload. Returns 518 * a token that can be used with `waitFor()`. 519 * 520 * @param {function} callback 521 * @return {string} 522 */ 523 Dispatcher.prototype.register=function(callback) { 524 var id = _prefix + _lastID++; 525 this.$Dispatcher_callbacks[id] = callback; 526 return id; 527 }; 528 529 /** 530 * Removes a callback based on its token. 531 * 532 * @param {string} id 533 */ 534 Dispatcher.prototype.unregister=function(id) { 535 invariant( 536 this.$Dispatcher_callbacks[id], 537 'Dispatcher.unregister(...): `%s` does not map to a registered callback.', 538 id 539 ); 540 delete this.$Dispatcher_callbacks[id]; 541 }; 542 543 /** 544 * Waits for the callbacks specified to be invoked before continuing execution 545 * of the current callback. This method should only be used by a callback in 546 * response to a dispatched payload. 547 * 548 * @param {array<string>} ids 549 */ 550 Dispatcher.prototype.waitFor=function(ids) { 551 invariant( 552 this.$Dispatcher_isDispatching, 553 'Dispatcher.waitFor(...): Must be invoked while dispatching.' 554 ); 555 for (var ii = 0; ii < ids.length; ii++) { 556 var id = ids[ii]; 557 if (this.$Dispatcher_isPending[id]) { 558 invariant( 559 this.$Dispatcher_isHandled[id], 560 'Dispatcher.waitFor(...): Circular dependency detected while ' + 561 'waiting for `%s`.', 562 id 563 ); 564 continue; 565 } 566 invariant( 567 this.$Dispatcher_callbacks[id], 568 'Dispatcher.waitFor(...): `%s` does not map to a registered callback.', 569 id 570 ); 571 this.$Dispatcher_invokeCallback(id); 572 } 573 }; 574 575 /** 576 * Dispatches a payload to all registered callbacks. 577 * 578 * @param {object} payload 579 */ 580 Dispatcher.prototype.dispatch=function(payload) { 581 invariant( 582 !this.$Dispatcher_isDispatching, 583 'Dispatch.dispatch(...): Cannot dispatch in the middle of a dispatch.' 584 ); 585 this.$Dispatcher_startDispatching(payload); 586 try { 587 for (var id in this.$Dispatcher_callbacks) { 588 if (this.$Dispatcher_isPending[id]) { 589 continue; 590 } 591 this.$Dispatcher_invokeCallback(id); 592 } 593 } finally { 594 this.$Dispatcher_stopDispatching(); 595 } 596 }; 597 598 /** 599 * Is this Dispatcher currently dispatching. 600 * 601 * @return {boolean} 602 */ 603 Dispatcher.prototype.isDispatching=function() { 604 return this.$Dispatcher_isDispatching; 605 }; 606 607 /** 608 * Call the callback stored with the given id. Also do some internal 609 * bookkeeping. 610 * 611 * @param {string} id 612 * @internal 613 */ 614 Dispatcher.prototype.$Dispatcher_invokeCallback=function(id) { 615 this.$Dispatcher_isPending[id] = true; 616 this.$Dispatcher_callbacks[id](this.$Dispatcher_pendingPayload); 617 this.$Dispatcher_isHandled[id] = true; 618 }; 619 620 /** 621 * Set up bookkeeping needed when dispatching. 622 * 623 * @param {object} payload 624 * @internal 625 */ 626 Dispatcher.prototype.$Dispatcher_startDispatching=function(payload) { 627 for (var id in this.$Dispatcher_callbacks) { 628 this.$Dispatcher_isPending[id] = false; 629 this.$Dispatcher_isHandled[id] = false; 630 } 631 this.$Dispatcher_pendingPayload = payload; 632 this.$Dispatcher_isDispatching = true; 633 }; 634 635 /** 636 * Clear bookkeeping used for dispatching. 637 * 638 * @internal 639 */ 640 Dispatcher.prototype.$Dispatcher_stopDispatching=function() { 641 this.$Dispatcher_pendingPayload = null; 642 this.$Dispatcher_isDispatching = false; 643 }; 644 645 646module.exports = Dispatcher; 647 648},{"./invariant":5}],5:[function(require,module,exports){ 649/** 650 * Copyright (c) 2014, Facebook, Inc. 651 * All rights reserved. 652 * 653 * This source code is licensed under the BSD-style license found in the 654 * LICENSE file in the root directory of this source tree. An additional grant 655 * of patent rights can be found in the PATENTS file in the same directory. 656 * 657 * @providesModule invariant 658 */ 659 660"use strict"; 661 662/** 663 * Use invariant() to assert state which your program assumes to be true. 664 * 665 * Provide sprintf-style format (only %s is supported) and arguments 666 * to provide information about what broke and what you were 667 * expecting. 668 * 669 * The invariant message will be stripped in production, but the invariant 670 * will remain to ensure logic does not differ in production. 671 */ 672 673var invariant = function(condition, format, a, b, c, d, e, f) { 674 if (false) { 675 if (format === undefined) { 676 throw new Error('invariant requires an error message argument'); 677 } 678 } 679 680 if (!condition) { 681 var error; 682 if (format === undefined) { 683 error = new Error( 684 'Minified exception occurred; use the non-minified dev environment ' + 685 'for the full error message and additional helpful warnings.' 686 ); 687 } else { 688 var args = [a, b, c, d, e, f]; 689 var argIndex = 0; 690 error = new Error( 691 'Invariant Violation: ' + 692 format.replace(/%s/g, function() { return args[argIndex++]; }) 693 ); 694 } 695 696 error.framesToPop = 1; // we don't care about invariant's own frame 697 throw error; 698 } 699}; 700 701module.exports = invariant; 702 703},{}],6:[function(require,module,exports){ 704'use strict'; 705 706Object.defineProperty(exports, '__esModule', { 707 value: true 708}); 709 710var _createClass = (function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ('value' in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; })(); 711 712exports['default'] = makeAction; 713 714function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) newObj[key] = obj[key]; } } newObj['default'] = obj; return newObj; } } 715 716function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; } 717 718function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError('Cannot call a class as a function'); } } 719 720var _esSymbol = require('es-symbol'); 721 722var _esSymbol2 = _interopRequireDefault(_esSymbol); 723 724var _symbolsSymbols = require('../symbols/symbols'); 725 726var Sym = _interopRequireWildcard(_symbolsSymbols); 727 728var _utilsAltUtils = require('../utils/AltUtils'); 729 730var utils = _interopRequireWildcard(_utilsAltUtils); 731 732var AltAction = (function () {
733 function AltAction(alt, name, action, actions, actionDetails) { 734 _classCallCheck(this, AltAction); 735 736 this[Sym.ACTION_UID] = name; 737 this[Sym.ACTION_HANDLER] = action.bind(this); 738 this.actions = actions; 739 this.actionDetails = actionDetails; 740 this.alt = alt; 741 } 742 743 _createClass(AltAction, [{ 744 key: 'dispatch', 745 value: function dispatch(data) { 746 this.alt.dispatch(this[Sym.ACTION_UID], data, this.actionDetails); 747 } 748 }]); 749 750 return AltAction; 751})(); 752 753function makeAction(alt, namespace, name, implementation, obj) { 754 // make sure each Symbol is unique 755 var actionId = utils.uid(alt[Sym.ACTIONS_REGISTRY], '' + namespace + '.' + name); 756 alt[Sym.ACTIONS_REGISTRY][actionId] = 1; 757 var actionSymbol = _esSymbol2['default']['for']('alt/' + actionId); 758 759 var data = { 760 namespace: namespace, 761 name: name, 762 id: actionId, 763 symbol: actionSymbol 764 }; 765 766 // Wrap the action so we can provide a dispatch method 767 var newAction = new AltAction(alt, actionSymbol, implementation, obj, data); 768 769 // the action itself 770 var action = newAction[Sym.ACTION_HANDLER]; 771 action.defer = function () { 772 for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) { 773 args[_key] = arguments[_key]; 774 } 775 776 setTimeout(function () { 777 newAction[Sym.ACTION_HANDLER].apply(null, args); 778 }); 779 }; 780 action[Sym.ACTION_KEY] = actionSymbol; 781 action.data = data; 782 783 // ensure each reference is unique in the namespace 784 var container = alt.actions[namespace]; 785 var id = utils.uid(container, name); 786 container[id] = action; 787 788 return action; 789} 790 791module.exports = exports['default']; 792 793},{"../symbols/symbols":10,"../utils/AltUtils":11,"es-symbol":1}],7:[function(require,module,exports){ 794'use strict'; 795 796Object.defineProperty(exports, '__esModule', { 797 value: true 798}); 799 800var _createClass = (function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ('value' in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; })(); 801 802function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) newObj[key] = obj[key]; } } newObj['default'] = obj; return newObj; } } 803 804function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; } 805 806function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError('Cannot call a class as a function'); } } 807 808var _eventemitter3 = require('eventemitter3'); 809 810var _eventemitter32 = _interopRequireDefault(_eventemitter3); 811 812var _esSymbol = require('es-symbol'); 813 814var _esSymbol2 = _interopRequireDefault(_esSymbol); 815 816var _symbolsSymbols = require('../symbols/symbols'); 817 818var Sym = _interopRequireWildcard(_symbolsSymbols); 819 820var _utilsFunctions = require('../../utils/functions'); 821 822var fn = _interopRequireWildcard(_utilsFunctions); 823 824// event emitter instance 825var EE = (0, _esSymbol2['default'])(); 826 827var AltStore = (function () { 828 function AltStore(alt, model, state, StoreModel) { 829 var _this = this; 830 831 _classCallCheck(this, AltStore); 832 833 this[EE] = new _eventemitter32['default'](); 834 this[Sym.LIFECYCLE] = model[Sym.LIFECYCLE]; 835 this[Sym.STATE_CONTAINER] = state || model; 836 837 this.preventDefault = false;
838 this._storeName = model._storeName; 839 this.boundListeners = model[Sym.ALL_LISTENERS]; 840 this.StoreModel = StoreModel; 841 842 var output = model.output || function (x) { 843 return x; 844 }; 845 846 this.emitChange = function () { 847 _this[EE].emit('change', output.call(model, _this[Sym.STATE_CONTAINER])); 848 }; 849 850 var handleDispatch = function handleDispatch(f, payload) { 851 try { 852 return f(); 853 } catch (e) { 854 if (model[Sym.HANDLING_ERRORS]) { 855 _this[Sym.LIFECYCLE].emit('error', e, payload, _this[Sym.STATE_CONTAINER]); 856 return false; 857 } else { 858 throw e; 859 } 860 } 861 }; 862 863 fn.assign(this, model[Sym.PUBLIC_METHODS]); 864 865 // Register dispatcher 866 this.dispatchToken = alt.dispatcher.register(function (payload) { 867 _this.preventDefault = false; 868 _this[Sym.LIFECYCLE].emit('beforeEach', payload, _this[Sym.STATE_CONTAINER]); 869 870 var actionHandler = model[Sym.LISTENERS][payload.action] || model.otherwise; 871 872 if (actionHandler) { 873 var result = handleDispatch(function () { 874 return actionHandler.call(model, payload.data, payload.action); 875 }, payload); 876 877 if (result !== false && !_this.preventDefault) _this.emitChange(); 878 } 879 880 if (model.reduce) { 881 handleDispatch(function () { 882 model.setState(model.reduce(_this[Sym.STATE_CONTAINER], payload)); 883 }, payload); 884 885 if (!_this.preventDefault) _this.emitChange(); 886 } 887 888 _this[Sym.LIFECYCLE].emit('afterEach', payload, _this[Sym.STATE_CONTAINER]); 889 }); 890 891 this[Sym.LIFECYCLE].emit('init'); 892 } 893 894 _createClass(AltStore, [{ 895 key: 'getEventEmitter', 896 value: function getEventEmitter() { 897 return this[EE]; 898 } 899 }, { 900 key: 'listen', 901 value: function listen(cb) { 902 var _this2 = this; 903 904 this[EE].on('change', cb); 905 return function () { 906 return _this2.unlisten(cb); 907 }; 908 } 909 }, { 910 key: 'unlisten', 911 value: function unlisten(cb) { 912 if (!cb) throw new TypeError('Unlisten must receive a function'); 913 this[Sym.LIFECYCLE].emit('unlisten'); 914 this[EE].removeListener('change', cb); 915 } 916 }, { 917 key: 'getState', 918 value: function getState() { 919 return this.StoreModel.config.getState.call(this, this[Sym.STATE_CONTAINER]); 920 } 921 }]); 922 923 return AltStore; 924})(); 925 926exports['default'] = AltStore; 927module.exports = exports['default']; 928 929},{"../../utils/functions":13,"../symbols/symbols":10,"es-symbol":1,"eventemitter3":2}],8:[function(require,module,exports){ 930'use strict'; 931 932Object.defineProperty(exports, '__esModule', { 933 value: true 934}); 935 936function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) newObj[key] = obj[key]; } } newObj['default'] = obj; return newObj; } } 937 938function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; } 939 940var _esSymbol = require('es-symbol'); 941 942var _esSymbol2 = _interopRequireDefault(_esSymbol); 943 944var _symbolsSymbols = require('../symbols/symbols'); 945 946var Sym = _interopRequireWildcard(_symbolsSymbols); 947 948var _utilsFunctions = require('../../utils/functions'); 949 950var fn = _interopRequireWildcard(_utilsFunctions); 951 952var StoreMixin = { 953 waitFor: function waitFor() { 954 for (var _len = arguments.length, sources = Array(_len), _key = 0; _key < _len; _key++) { 955 sources[_key] = arguments[_key]; 956 } 957 958 if (!sources.length) { 959 throw new ReferenceError('Dispatch tokens not provided'); 960 } 961 962 var sourcesArray = sources; 963 if (sources.length === 1) { 964 sourcesArray = Array.isArray(sources[0]) ? sources[0] : sources; 965 } 966 967 var tokens = sourcesArray.map(function (source) { 968 return source.dispatchToken || source; 969 }); 970 971 this.dispatcher.waitFor(tokens); 972 }, 973 974 exportAsync: function exportAsync(asyncMethods) { 975 this.registerAsync(asyncMethods); 976 }, 977 978 registerAsync: function registerAsync(asyncDef) { 979 var _this = this; 980 981 var loadCounter = 0; 982 983 var asyncMethods = fn.isFunction(asyncDef) ? asyncDef(this.alt) : asyncDef; 984 985 var toExport = Object.keys(asyncMethods).reduce(function (publicMethods, methodName) { 986 var desc = asyncMethods[methodName]; 987 var spec = fn.isFunction(desc) ? desc(_this) : desc; 988
989 var validHandlers = ['success', 'error', 'loading']; 990 validHandlers.forEach(function (handler) { 991 if (spec[handler] && !spec[handler][Sym.ACTION_KEY]) { 992 throw new Error('' + handler + ' handler must be an action function'); 993 } 994 }); 995 996 publicMethods[methodName] = function () { 997 for (var _len2 = arguments.length, args = Array(_len2), _key2 = 0; _key2 < _len2; _key2++) { 998 args[_key2] = arguments[_key2]; 999 } 1000 1001 var state = _this.getInstance().getState(); 1002 var value = spec.local && spec.local.apply(spec, [state].concat(args)); 1003 var shouldFetch = spec.shouldFetch ? spec.shouldFetch.apply(spec, [state].concat(args)) : value == null; 1004 var intercept = spec.interceptResponse || function (x) { 1005 return x; 1006 }; 1007 1008 var makeActionHandler = function makeActionHandler(action, isError) { 1009 return function (x) { 1010 var fire = function fire() { 1011 loadCounter -= 1; 1012 action(intercept(x, action, args)); 1013 if (isError) throw x; 1014 }; 1015 return typeof window === 'undefined' ? function () { 1016 return fire(); 1017 } : fire(); 1018 }; 1019 }; 1020 1021 // if we don't have it in cache then fetch it 1022 if (shouldFetch) { 1023 loadCounter += 1; 1024 /* istanbul ignore else */ 1025 if (spec.loading) spec.loading(intercept(null, spec.loading, args
1025)); 1026 return spec.remote.apply(spec, [state].concat(args))['catch'](makeActionHandler(spec.error, 1)).then(makeActionHandler(spec.success)); 1027 } else { 1028 // otherwise emit the change now 1029 _this.emitChange(); 1030 } 1031 }; 1032 1033 return publicMethods; 1034 }, {}); 1035 1036 this.exportPublicMethods(toExport); 1037 this.exportPublicMethods({ 1038 isLoading: function isLoading() { 1039 return loadCounter > 0; 1040 } 1041 }); 1042 }, 1043 1044 exportPublicMethods: function exportPublicMethods(methods) { 1045 var _this2 = this; 1046 1047 fn.eachObject(function (methodName, value) { 1048 if (!fn.isFunction(value)) { 1049 throw new TypeError('exportPublicMethods expects a function'); 1050 } 1051 1052 _this2[Sym.PUBLIC_METHODS][methodName] = value; 1053 }, [methods]); 1054 }, 1055 1056 emitChange: function emitChange() { 1057 this.getInstance().emitChange(); 1058 }, 1059 1060 on: function on(lifecycleEvent, handler) { 1061 if (lifecycleEvent === 'error') { 1062 this[Sym.HANDLING_ERRORS] = true; 1063 } 1064 this[Sym.LIFECYCLE].on(lifecycleEvent, handler.bind(this)); 1065 }, 1066 1067 bindAction: function bindAction(symbol, handler) { 1068 if (!symbol) { 1069 throw new ReferenceError('Invalid action reference passed in'); 1070 } 1071 if (!fn.isFunction(handler)) { 1072 throw new TypeError('bindAction expects a function'); 1073 } 1074 1075 if (handler.length > 1) { 1076 throw new TypeError('Action handler in store ' + this._storeName + ' for ' + ('' + (symbol[Sym.ACTION_KEY] || symbol).toString() + ' was defined with ') + 'two parameters. Only a single parameter is passed through the ' + 'dispatcher, did you mean to pass in an Object instead?'); 1077 } 1078 1079 // You can pass in the constant or the function itself 1080 var key = symbol[Sym.ACTION_KEY] ? symbol[Sym.ACTION_KEY] : symbol; 1081 this[Sym.LISTENERS][key] = handler.bind(this); 1082 this[Sym.ALL_LISTENERS].push(_esSymbol2['default'].keyFor(key)); 1083 }, 1084 1085 bindActions: function bindActions(actions) { 1086 var _this3 = this; 1087 1088 fn.eachObject(function (action, symbol) { 1089 var matchFirstCharacter = /./; 1090 var assumedEventHandler = action.replace(matchFirstCharacter, function (x) { 1091 return 'on' + x[0].toUpperCase(); 1092 }); 1093 var handler = null; 1094 1095 if (_this3[action] && _this3[assumedEventHandler]) { 1096 // If you have both action and onAction 1097 throw new ReferenceError('You have multiple action handlers bound to an action: ' + ('' + action + ' and ' + assumedEventHandler)); 1098 } else if (_this3[action]) { 1099 // action 1100 handler = _this3[action]; 1101 } else if (_this3[assumedEventHandler]) { 1102 // onAction 1103 handler = _this3[assumedEventHandler]; 1104 } 1105 1106 if (handler) { 1107 _this3.bindAction(symbol, handler); 1108 } 1109 }, [actions]); 1110 }, 1111 1112 bindListeners: function bindListeners(obj) { 1113 var _this4 = this; 1114 1115 fn.eachObject(function (methodName, symbol) { 1116 var listener = _this4[methodName]; 1117 1118 if (!listener) { 1119 throw new ReferenceError('' + methodName + ' defined but does not exist in ' + _this4._storeName); 1120 } 1121 1122 if (Array.isArray(symbol)) { 1123 symbol.forEach(function (action) { 1124 _this4.bindAction(action, listener); 1125 }); 1126 } else { 1127 _this4.bindAction(symbol, listener); 1128 } 1129 }, [obj]); 1130 } 1131}; 1132 1133exports['default'] = StoreMixin; 1134module.exports = exports['default']; 1135 1136},{"../../utils/functions":13,"../symbols/symbols":10,"es-symbol":1}],9:[function(require,module,exports){ 1137'use strict'; 1138 1139Object.defineProperty(exports, '__esModule', { 1140 value: true 1141}); 1142var _bind = Function.prototype.bind; 1143 1144var _get = function get(_x, _x2, _x3) { var _again = true; _function: while (_again) { var object = _x, property = _x2, receiver = _x3; desc = parent = getter = undefined; _again = false; var desc = Object.getOwnPropertyDescriptor(object, property); if (desc === undefined) { var parent = Object.getPrototypeOf(object); if (parent === null) { return undefined; } else { _x = parent; _x2 = property; _x3 = receiver; _again = true; continue _function; } } else if ('value' in desc) { return desc.value; } else { var getter = desc.get; if (getter === undefined) { return undefined; } return getter.call(receiver); } } }; 1145 1146exports.createStoreConfig = createStoreConfig; 1147exports.transformStore = transformStore; 1148exports.createStoreFromObject = createStoreFromObject; 1149exports.createStoreFromClass = createStoreFromClass; 1150 1151function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) newObj[key] = obj[key]; } } newObj['default'] = obj; return newObj; } } 1152 1153function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; } 1154 1155function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError('Cannot call a class as a function'); } } 1156 1157function _inherits(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, { c
1157onstructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) subClass.__proto__ = superClass; } 1158 1159var _eventemitter3 = require('eventemitter3'); 1160 1161var _eventemitter32 = _interopRequireDefault(_eventemitter3); 1162 1163var _symbolsSymbols = require('../symbols/symbols'); 1164 1165var Sym = _interopRequireWildcard(_symbolsSymbols); 1166 1167var _utilsAltUtils = require('../utils/AltUtils'); 1168 1169var utils = _interopRequireWildcard(_utilsAltUtils); 1170 1171var _utilsFunctions = require('../../utils/functions'); 1172 1173var fn = _interopRequireWildcard(_utilsFunctions); 1174 1175var _AltStore = require('./AltStore'); 1176 1177var _AltStore2 = _interopRequireDefault(_AltStore); 1178 1179var _StoreMixin = require('./StoreMixin'); 1180 1181var _StoreMixin2 = _interopRequireDefault(_StoreMixin); 1182 1183function doSetState(store, storeInstance, state) { 1184 if (!state) { 1185 return; 1186 } 1187 1188 var config = storeInstance.StoreModel.config; 1189 1190 var nextState = fn.isFunction(state) ? state(storeInstance[Sym.STATE_CONTAINER]) : state; 1191 1192 storeInstance[Sym.STATE_CONTAINER] = config.setState.call(store, storeInstance[Sym.STATE_CONTAINER], nextState); 1193 1194 if (!store.alt.dispatcher.isDispatching()) { 1195 store.emitChange(); 1196 } 1197} 1198 1199function createPrototype(proto, alt, key, extras) { 1200 proto[Sym.ALL_LISTENERS] = []; 1201 proto[Sym.LIFECYCLE] = new _eventemitter32['default'](); 1202 proto[Sym.LISTENERS] = {}; 1203 proto[Sym.PUBLIC_METHODS] = {}; 1204 1205 return fn.assign(proto, _StoreMixin2['default'], { 1206 _storeName: key, 1207 alt: alt, 1208 dispatcher: alt.dispatcher, 1209 preventDefault: function preventDefault() { 1210 this.getInstance().preventDefault = true; 1211 } 1212 }, extras); 1213} 1214 1215function createStoreConfig(globalConfig, StoreModel) { 1216 StoreModel.config = fn.assign({ 1217 getState: function getState(state) { 1218 return fn.assign({}, state); 1219 }, 1220 setState: fn.assign 1221 }, globalConfig, StoreModel.config); 1222} 1223 1224function transformStore(transforms, StoreModel) { 1225 return transforms.reduce(function (Store, transform) { 1226 return transform(Store); 1227 }, StoreModel); 1228} 1229 1230function createStoreFromObject(alt, StoreModel, key) { 1231 var storeInstance = undefined; 1232 1233 var StoreProto = createPrototype({}, alt, key, fn.assign({ 1234 getInstance: function getInstance() { 1235 return storeInstance; 1236 }, 1237 setState: function setState(nextState) { 1238 doSetState(this, storeInstance, nextState); 1239 } 1240 }, StoreModel)); 1241 1242 // bind the store listeners 1243 /* istanbul ignore else */ 1244 if (StoreProto.bindListeners) { 1245 _StoreMixin2['default'].bindListeners.call(StoreProto, StoreProto.bindListeners); 1246 } 1247 /* istanbul ignore else */ 1248 if (StoreProto.observe) { 1249 _StoreMixin2['default'].bindListeners.call(StoreProto, StoreProto.observe(alt)); 1250 } 1251 1252 // bind the lifecycle events 1253 /* istanbul ignore else */ 1254 if (StoreProto.lifecycle) { 1255 fn.eachObject(function (eventName, event) { 1256 _StoreMixin2['default'].on.call(StoreProto, eventName, event); 1257 }, [StoreProto.lifecycle]); 1258 } 1259 1260 // create the instance and fn.assign the public methods to the instance 1261 storeInstance = fn.assign(new _AltStore2['default'](alt, StoreProto, StoreProto.state || {}, StoreModel), StoreProto.publicMethods, { displayName: key }); 1262 1263 return storeInstance; 1264} 1265 1266function createStoreFromClass(alt, StoreModel, key) { 1267 for (var _len = arguments.length, argsForClass = Array(_len > 3 ? _len - 3 : 0), _key = 3; _key < _len; _key++) { 1268 argsForClass[_key - 3] = arguments[_key]; 1269 } 1270 1271 var storeInstance = undefined; 1272 var config = StoreModel.config; 1273 1274 // Creating a class here so we don't overload the provided store's 1275 // prototype with the mixin behaviour and I'm extending from StoreModel 1276 // so we can inherit any extensions from the provided store. 1277 1278 var Store = (function (_StoreModel) { 1279 function Store() { 1280 for (var _len2 = arguments.length, args = Array(_len2), _key2 = 0; _key2 < _len2; _key2++) { 1281 args[_key2] = arguments[_key2]; 1282 } 1283 1284 _classCallCheck(this, Store); 1285 1286 _get(Object.getPrototypeOf(Store.prototype), 'constructor', this).apply(this, args); 1287 } 1288 1289 _inherits(Store, _StoreModel); 1290 1291 return Store; 1292 })(StoreModel); 1293 1294 createPrototype(Store.prototype, alt, key, { 1295 getInstance: function getInstance() { 1296 return storeInstance; 1297 }, 1298 setState: function setState(nextState) { 1299 doSetState(this, storeInstance, nextState); 1300 } 1301 }); 1302 1303 var store = new (_bind.apply(Store, [null].concat(argsForClass)))(); 1304 1305 if (config.bindListeners) store.bindListeners(config.bindListeners); 1306 if (config.datasource) store.registerAsync(config.datasource); 1307 1308 storeInstance = fn.assign(new _AltStore2['default'](alt, store, store[alt.config.stateKey] || store[config.stateKey] || null, StoreModel), utils.getInternalMethods(StoreModel), config.publicMethods, { displayName: key }); 1309 1310 return storeInstance; 1311} 1312 1313},{"../../utils/functions":13,"../symbols/symbols":10,"../utils/AltUtils":11,"./AltStore":7,"./StoreMixin":8,"eventemitter3":2}],10:[function(require,module,exports){ 1314'use strict'; 1315 1316Object.defineProperty(exports, '__esModule', { 1317 value: true 1318}); 1319 1320function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; } 1321 1322var _esSymbol = require('es-symbol'); 1323 1324var _esSymbol2 = _interopRequireDefault(_esSymbol); 1325 1326// action creator handler 1327var ACTION_HANDLER = (0, _esSymbol2['default'])(); 1328 1329exports.ACTION_HANDLER = ACTION_HANDLER; 1330// the action's uid symbol for listening 1331var ACTION_KEY = (0, _esSymbol2['default'])(); 1332 1333exports.ACTION_KEY = ACTION_KEY; 1334// per instance registry of actions 1335var ACTIONS_REGISTRY = (0, _esSymbol2['default'])(); 1336 1337exports.ACTIONS_REGISTRY = ACTIONS_REGISTRY; 1338// the action's name 1339var ACTION_UID = (0, _esSymbol2['default'])(); 1340 1341exports.ACTION_UID = ACTION_UID; 1342// store all of a store's listeners 1343var ALL_LISTENERS = (0, _esSymbol2['default'])(); 1344 1345exports.ALL_LISTENERS = ALL_LISTENERS; 1346// are we handling our own errors 1347var HANDLING_ERRORS = (0, _esSymbol2['default'])(); 1348 1349exports.HANDLING_ERRORS = HANDLING_ERRORS; 1350// initial snapshot 1351var INIT_SNAPSHOT = (0, _esSymbol2['default'])(); 1352 1353exports.INIT_SNAPSHOT = INIT_SNAPSHOT; 1354// last snapshot 1355var LAST_SNAPSHOT = (0, _esSymbol2['default'])(); 1356 1357exports.LAST_SNAPSHOT = LAST_SNAPSHOT; 1358// all lifecycle listeners 1359var LIFECYCLE = (0, _esSymbol2['default'])(); 1360 1361exports.LIFECYCLE = LIFECYCLE; 1362// store action listeners 1363var LISTENERS = (0, _esSymbol2['default'])(); 1364 1365exports.LISTENERS = LISTENERS; 1366// public methods 1367var PUBLIC_METHODS = (0, _esSymbol2['default'])(); 1368 1369exports.PUBLIC_METHODS = PUBLIC_METHODS; 1370// contains all state 1371var STATE_CONTAINER = (0, _esSymbol2['default'])(); 1372exports.STATE_CONTAINER = STATE_CONTAINER; 1373 1374},{"es-symbol":1}],11:[function(require,module,exports){ 1375'use strict'; 1376 1377Object.defineProperty(exports, '__esModule', { 1378 value: true 1379}); 1380exports.getInternalMethods = getInternalMethods; 1381exports.warn = warn; 1382exports.uid = uid; 1383exports.formatAsConstant = formatAsConstant; 1384exports.dispatchIdentity = dispatchIdentity; 1385/* istanbul ignore next */ 1386function NoopClass() {} 1387 1388var builtIns = Object.getOwnPropertyNames(NoopClass); 1389var builtInProto = Object.getOwnPropertyNames(NoopClass.prototype); 1390 1391function getInternalMethods(Obj, isProto) { 1392 var excluded = isProto ? builtInProto : builtIns; 1393 var obj = isProto ? Obj.prototype : Obj; 1394 return Object.getOwnPropertyNames(obj).reduce(function (value, m) { 1395 if (excluded.indexOf(m) !== -1) { 1396 return value; 1397 } 1398 1399 value[m] = obj[m]; 1400 return value; 1401 }, {}); 1402} 1403 1404function warn(msg) { 1405 /* istanbul ignore else */ 1406 if (typeof console !== 'undefined') { 1407 console.warn(new ReferenceError(msg)); 1408 } 1409} 1410 1411function uid(container, name) { 1412 var count = 0; 1413 var key = name; 1414 while (Object.hasOwnProperty.call(container, key)) { 1415 key = name + String(++count); 1416 } 1417 return key; 1418} 1419 1420function formatAsConstant(name) { 1421 return name.replace(/[a-z]([A-Z])/g, function (i) { 1422 return '' + i[0] + '_' + i[1].toLowerCase(); 1423 }).toUpperCase(); 1424} 1425 1426function dispatchIdentity(x) { 1427 for (var _len = arguments.length, a = Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) { 1428 a[_key - 1] = arguments[_key]; 1429 } 1430 1431 this.dispatch(a.length ? [x].concat(a) : x); 1432} 1433 1434},{}],12:[function(require,module,exports){ 1435'use strict'; 1436 1437Object.defineProperty(exports, '__esModule', { 1438 value: true 1439}); 1440exports.setAppState = setAppState; 1441exports.snapshot = snapshot; 1442exports.saveInitialSnapshot = saveInitialSnapshot; 1443exports.filterSnapshots = filterSnapshots; 1444 1445function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) newObj[key] = obj[key]; } } newObj['default'] = obj; return newObj; } } 1446 1447var _symbolsSymbols = require('../symbols/symbols'); 1448 1449var Sym = _interopRequireWildcard(_symbolsSymbols); 1450 1451var _utilsFunctions = require('../../utils/functions'); 1452 1453var fn = _interopRequireWildcard(_utilsFunctions); 1454 1455function setAppState(instance, data, onStore) { 1456 var obj = instance.deserialize(data); 1457 fn.eachObject(function (key, value) { 1458 var store = instance.stores[key]; 1459 if (store) { 1460 var config = store.StoreModel.config; 1461 1462 if (config.onDeserialize) { 1463 obj[key] = config.onDeserialize(value) || value; 1464 } 1465 fn.assign(store[Sym.STATE_CONTAINER], obj[key]); 1466 onStore(store); 1467 } 1468 }, [obj]); 1469} 1470 1471function snapshot(instance) { 1472 var storeNames = arguments[1] === undefined ? [] : arguments[1]; 1473 1474 var stores = storeNames.length ? storeNames : Object.keys(instance.stores); 1475 return stores.reduce(function (obj, storeHandle) { 1476 var storeName = storeHandle.displayName || storeHandle; 1477 var store = instance.stores[storeName]; 1478 var config = store.StoreModel.config; 1479 1480 store[Sym.LIFECYCLE].emit('snapshot'); 1481 var customSnapshot = config.onSerialize && config.onSerialize(store[Sym.STATE_CONTAINER]); 1482 obj[storeName] = customSnapshot ? customSnapshot : store.getState(); 1483 return obj; 1484 }, {}); 1485} 1486 1487function saveInitialSnapshot(instance, key) { 1488 var state = instance.deserialize(instance.serialize(instance.stores[key][Sym.STATE_CONTAINER])); 1489 instance[Sym.INIT_SNAPSHOT][key] = state; 1490 instance[Sym.LAST_SNAPSHOT][key] = state; 1491} 1492 1493function filterSnapshots(instance, state, stores) { 1494 return stores.reduce(function (obj, store) { 1495 var storeName = store.displayName || store; 1496 if (!state[storeName]) { 1497 throw new ReferenceError('' + storeName + ' is not a valid store'); 1498 } 1499 obj[storeName] = state[storeName]; 1500 return obj; 1501 }, {}); 1502} 1503 1504},{"../../utils/functions":13,"../symbols/symbols":10}],13:[function(require,module,exports){ 1505'use strict'; 1506 1507Object.defineProperty(exports, '__esModule', { 1508 value: true 1509}); 1510exports.eachObject = eachObject; 1511exports.assign = assign; 1512var isFunction = function isFunction(x) { 1513 return typeof x === 'function'; 1514}; 1515 1516exports.isFunction = isFunction; 1517 1518function eachObject(f, o) { 1519 o.forEach(function (from) {
1520 Object.keys(Object(from)).forEach(function (key) { 1521 f(key, from[key]); 1522 }); 1523 }); 1524} 1525 1526function assign(target) { 1527 for (var _len = arguments.length, source = Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) { 1528 source[_key - 1] = arguments[_key]; 1529 } 1530 1531 eachObject(function (key, value) { 1532 return target[key] = value; 1533 }, source); 1534 return target; 1535} 1536 1537},{}],14:[function(require,module,exports){ 1538/*global window*/ 1539'use strict'; 1540 1541Object.defineProperty(exports, '__esModule', { 1542 value: true 1543}); 1544var _bind = Function.prototype.bind; 1545 1546var _get = function get(_x3, _x4, _x5) { var _again = true; _function: while (_again) { var object = _x3, property = _x4, receiver = _x5; desc = parent = getter = undefined; _again = false; var desc = Object.getOwnPropertyDescriptor(object, property); if (desc === undefined) { var parent = Object.getPrototypeOf(object); if (parent === null) { return undefined; } else { _x3 = parent; _x4 = property; _x5 = receiver; _again = true; continue _function; } } else if ('value' in desc) { return desc.value; } else { var getter = desc.get; if (getter === undefined) { return undefined; } return getter.call(receiver); } } }; 1547 1548var _createClass = (function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ('value' in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; })(); 1549 1550function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; } 1551 1552function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) newObj[key] = obj[key]; } } newObj['default'] = obj; return newObj; } } 1553 1554function _inherits(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; } 1555 1556function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError('Cannot call a class as a function'); } } 1557 1558var _flux = require('flux'); 1559 1560var _utilsStateFunctions = require('./utils/StateFunctions'); 1561 1562var StateFunctions = _interopRequireWildcard(_utilsStateFunctions); 1563 1564var _symbolsSymbols = require('./symbols/symbols'); 1565 1566var Sym = _interopRequireWildcard(_symbolsSymbols); 1567 1568var _utilsFunctions = require('../utils/functions'); 1569 1570var fn = _interopRequireWildcard(_utilsFunctions); 1571 1572var _store = require('./store'); 1573 1574var store = _interopRequireWildcard(_store); 1575 1576var _utilsAltUtils = require('./utils/AltUtils'); 1577 1578var utils = _interopRequireWildcard(_utilsAltUtils); 1579 1580var _actions = require('./actions'); 1581 1582var _actions2 = _interopRequireDefault(_actions); 1583 1584var Alt = (function () { 1585 function Alt() { 1586 var config = arguments[0] === undefined ? {} : arguments[0]; 1587 1588 _classCallCheck(this, Alt); 1589 1590 this.config = config; 1591 this.serialize = config.serialize || JSON.stringify; 1592 this.deserialize = config.deserialize || JSON.parse; 1593 this.dispatcher = config.dispatcher || new _flux.Dispatcher(); 1594 this.batchingFunction = config.batchingFunction || function (callback) { 1595 return callback(); 1596 }; 1597 this.actions = { global: {} }; 1598 this.stores = {}; 1599 this.storeTransforms = config.storeTransforms || []; 1600 this[Sym.ACTIONS_REGISTRY] = {}; 1601 this[Sym.INIT_SNAPSHOT] = {}; 1602 this[Sym.LAST_SNAPSHOT] = {}; 1603 } 1604 1605 _createClass(Alt, [{ 1606 key: 'dispatch', 1607 value: function dispatch(action, data, details) { 1608 var _this = this; 1609 1610 this.batchingFunction(function () { 1611 return _this.dispatcher.dispatch({ action: action, data: data, details: details }); 1612 }); 1613 } 1614 }, { 1615 key: 'createUnsavedStore', 1616 value: function createUnsavedStore(StoreModel) { 1617 for (var _len = arguments.length, args = Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) { 1618 args[_key - 1] = arguments[_key]; 1619 } 1620 1621 var key = StoreModel.displayName || ''; 1622 store.createStoreConfig(this.config, StoreModel); 1623 var Store = store.transformStore(this.storeTransforms, StoreModel); 1624 1625 return fn.isFunction(Store) ? store.createStoreFromClass.apply(store, [this, Store, key].concat(args)) : store.createStoreFromObject(this, Store, key); 1626 } 1627 }, { 1628 key: 'createStore', 1629 value: function createStore(StoreModel, iden) { 1630 for (var _len2 = arguments.length, args = Array(_len2 > 2 ? _len2 - 2 : 0), _key2 = 2; _key2 < _len2; _key2++) { 1631 args[_key2 - 2] = arguments[_key2]; 1632 } 1633 1634 var key = iden || StoreModel.displayName || StoreModel.name || ''; 1635 store.createStoreConfig(this.config, StoreModel); 1636 var Store = store.transformStore(this.storeTransforms, StoreModel); 1637
1638 if (this.stores[key] || !key) { 1639 if (this.stores[key]) { 1640 utils.warn('A store named ' + key + ' already exists, double check your store ' + 'names or pass in your own custom identifier for each store'); 1641 } else { 1642 utils.warn('Store name was not specified'); 1643 } 1644 1645 key = utils.uid(this.stores, key); 1646 } 1647 1648 var storeInstance = fn.isFunction(Store) ? store.createStoreFromClass.apply(store, [this, Store, key].concat(args)) : store.createStoreFromObject(this, Store, key); 1649 1650 this.stores[key] = storeInstance; 1651 StateFunctions.saveInitialSnapshot(this, key); 1652 1653 return storeInstance; 1654 } 1655 }, { 1656 key: 'generateActions', 1657 value: function generateActions() { 1658 for (var _len3 = arguments.length, actionNames = Array(_len3), _key3 = 0; _key3 < _len3; _key3++) { 1659 actionNames[_key3] = arguments[_key3]; 1660 } 1661 1662 var actions = { name: 'global' }; 1663 return this.createActions(actionNames.reduce(function (obj, action) { 1664 obj[action] = utils.dispatchIdentity; 1665 return obj; 1666 }, actions)); 1667 } 1668 }, { 1669 key: 'createAction', 1670 value: function createAction(name, implementation, obj) { 1671 return (0, _actions2['default'])(this, 'global', name, implementation, obj); 1672 } 1673 }, { 1674 key: 'createActions', 1675 value: function createActions(ActionsClass) { 1676 for (var _len4 = arguments.length, argsForConstructor = Array(_len4 > 2 ? _len4 - 2 : 0), _key4 = 2; _key4 < _len4; _key4++) { 1677 argsForConstructor[_key4 - 2] = arguments[_key4]; 1678 } 1679 1680 var _this2 = this; 1681 1682 var exportObj = arguments[1] === undefined ? {} : arguments[1]; 1683 1684 var actions = {}; 1685 var key = utils.uid(this[Sym.ACTIONS_REGISTRY], ActionsClass.displayName || ActionsClass.name || 'Unknown'); 1686 1687 if (fn.isFunction(ActionsClass)) { 1688 (function () { 1689 fn.assign(actions, utils.getInternalMethods(ActionsClass, true)); 1690 1691 var ActionsGenerator = (function (_ActionsClass) { 1692 function ActionsGenerator() { 1693 for (var _len5 = arguments.length, args = Array(_len5), _key5 = 0; _key5 < _len5; _key5++) { 1694 args[_key5] = arguments[_key5]; 1695 } 1696 1697 _classCallCheck(this, ActionsGenerator); 1698 1699 _get(Object.getPrototypeOf(ActionsGenerator.prototype), 'constructor', this).apply(this, args); 1700 } 1701 1702 _inherits(ActionsGenerator, _ActionsClass); 1703 1704 _createClass(ActionsGenerator, [{ 1705 key: 'generateActions', 1706 value: function generateActions() { 1707 for (var _len6 = arguments.length, actionNames = Array(_len6), _key6 = 0; _key6 < _len6; _key6++) { 1708 actionNames[_key6] = arguments[_key6]; 1709 } 1710 1711 actionNames.forEach(function (actionName) { 1712 actions[actionName] = utils.dispatchIdentity; 1713 }); 1714 } 1715 }]); 1716 1717 return ActionsGenerator; 1718 })(ActionsClass); 1719 1720 fn.assign(actions, new (_bind.apply(ActionsGenerator, [null].concat(argsForConstructor)))()); 1721 })(); 1722 } else { 1723 fn.assign(actions, ActionsClass); 1724 } 1725 1726 this.actions[key] = this.actions[key] || {}; 1727 1728 fn.eachObject(function (actionName, action) { 1729 if (!fn.isFunction(action)) { 1730 return; 1731 } 1732 1733 // create the action 1734 exportObj[actionName] = (0, _actions2['default'])(_this2, key, actionName, action, exportObj); 1735 1736 // generate a constant 1737 var constant = utils.formatAsConstant(actionName); 1738 exportObj[constant] = exportObj[actionName][Sym.ACTION_KEY]; 1739 }, [actions]); 1740 return exportObj; 1741 } 1742 }, { 1743 key: 'takeSnapshot', 1744 value: function takeSnapshot() { 1745 for (var _len7 = arguments.length, storeNames = Array(_len7), _key7 = 0; _key7 < _len7; _key7++) { 1746 storeNames[_key7] = arguments[_key7]; 1747 } 1748 1749 var state = StateFunctions.snapshot(this, storeNames); 1750 fn.assign(this[Sym.LAST_SNAPSHOT], state); 1751 return this.serialize(state); 1752 } 1753 }, { 1754 key: 'rollback', 1755 value: function rollback() { 1756 StateFunctions.setAppState(this, this.serialize(this[Sym.LAST_SNAPSHOT]), function (storeInst) { 1757 storeInst[Sym.LIFECYCLE].emit('rollback'); 1758 storeInst.emitChange(); 1759 }); 1760 } 1761 }, { 1762 key: 'recycle', 1763 value: function recycle() { 1764 for (var _len8 = arguments.length, storeNames = Array(_len8), _key8 = 0; _key8 < _len8; _key8++) { 1765 storeNames[_key8] = arguments[_key8]; 1766 } 1767 1768 var initialSnapshot = storeNames.length ? StateFunctions.filterSnapshots(this, this[Sym.INIT_SNAPSHOT], storeNames) : this[Sym.INIT_SNAPSHOT]; 1769 1770 StateFunctions.setAppState(this, this.serialize(initialSnapshot), function (storeInst) { 1771 storeInst[Sym.LIFECYCLE].emit('init'); 1772 storeInst.emitChange(); 1773 }); 1774 } 1775 }, { 1776 key: 'flush', 1777 value: function flush() { 1778 var state = this.serialize(StateFunctions.snapshot(this)); 1779 this.recycle(); 1780 return state; 1781 } 1782 }, { 1783 key: 'bootstrap', 1784 value: function bootstrap(data) { 1785 StateFunctions.setAppState(this, data, function (storeInst) { 1786 storeInst[Sym.LIFECYCLE].emit('bootstrap'); 1787 storeInst.emitChange(); 1788 }); 1789 } 1790 }, { 1791 key: 'prepare', 1792 value: function prepare(storeInst, payload) { 1793 var data = {}; 1794 if (!storeInst.displayName) { 1795 throw new ReferenceError('Store provided does not have a name'); 1796 } 1797 data[storeInst.displayName] = payload; 1798 return this.serialize(data); 1799 } 1800 }, { 1801 key: 'addActions', 1802 1803 // Instance type methods for injecting alt into your application as context 1804 1805 value: function addActions(name, ActionsClass) { 1806 for (var _len9 = arguments.length, args = Array(_len9 > 2 ? _len9 - 2 : 0), _key9 = 2; _key9 < _len9; _key9++) { 1807 args[_key9 - 2] = arguments[_key9]; 1808 } 1809 1810 this.actions[name] = Array.isArray(ActionsClass) ? this.generateActions.apply(this, ActionsClass) : this.createActions.apply(this, [ActionsClass].concat(args)); 1811 } 1812 }, { 1813 key: 'addStore', 1814 value: function addStore(name, StoreModel) { 1815 for (var _len10 = arguments.length, args = Array(_len10 > 2 ? _len10 - 2 : 0), _key10 = 2; _key10 < _len10; _key10++) { 1816 args[_key10 - 2] = arguments[_key10]; 1817 } 1818 1819 this.createStore.apply(this, [StoreModel, name].concat(args)); 1820 } 1821 }, { 1822 key: 'getActions', 1823 value: function getActions(name) { 1824 return this.actions[name]; 1825 } 1826 }, { 1827 key: 'getStore', 1828 value: function getStore(name) { 1829 return this.stores[name]; 1830 } 1831 }], [{ 1832 key: 'debug', 1833 value: function debug(name, alt) { 1834 var key = 'alt.js.org'; 1835 if (typeof window !== 'undefined') { 1836 window[key] = window[key] || []; 1837 window[key].push({ name: name, alt: alt }); 1838 } 1839 return alt; 1840 } 1841 }]); 1842 1843 return Alt; 1844})(); 1845 1846exports['default'] = Alt; 1847module.exports = exports['default']; 1848 1849},{"../utils/functions":13,"./actions":6,"./store":9,"./symbols/symbols":10,"./utils/AltUtils":11,"./utils/StateFunctions":12,"flux":3}]},{},[14])(14) 1850});
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.