UNPKG

92.7 kBJavaScriptView Raw
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.plait = 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 _slicedToArray = (function () { function sliceIterator(arr, i) { var _arr = []; var _n = true; var _d = false; var _e = undefined; try { for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"]) _i["return"](); } finally { if (_d) throw _e; } } return _arr; } return function (arr, i) { if (Array.isArray(arr)) { return arr; } else if (Symbol.iterator in Object(arr)) { return sliceIterator(arr, i); } else { throw new TypeError("Invalid attempt to destructure non-iterable instance"); } }; })();
5
6Object.defineProperty(exports, "__esModule", {
7 value: true
8});
9exports.forwardDispatch = undefined;
10exports.start = start;
11exports.initializeComponent = initializeComponent;
12
13var _curry = require('ramda/src/curry');
14
15var _curry2 = _interopRequireDefault(_curry);
16
17var _redux = require('redux');
18
19var _reduxThunk = require('redux-thunk');
20
21var _reduxThunk2 = _interopRequireDefault(_reduxThunk);
22
23var _diff = require('virtual-dom/diff');
24
25var _diff2 = _interopRequireDefault(_diff);
26
27var _patch = require('virtual-dom/patch');
28
29var _patch2 = _interopRequireDefault(_patch);
30
31var _createElement = require('virtual-dom/create-element');
32
33var _createElement2 = _interopRequireDefault(_createElement);
34
35var _domDelegator = require('dom-delegator');
36
37var _domDelegator2 = _interopRequireDefault(_domDelegator);
38
39var _Map = require('./Map');
40
41var _Map2 = _interopRequireDefault(_Map);
42
43function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
44
45var delegator = (0, _domDelegator2.default)();
46var createStoreWithMiddleware = (0, _redux.applyMiddleware)(_reduxThunk2.default)(_redux.createStore);
47
48// Component = {
49// init : _ -> Object
50// update : Map -> Action -> Map
51// view : Map -> (Action -> Action) -> VirtualNode
52// }
53
54// start :: Component -> Element
55function start(component) {
56 var init = component.init;
57 var update = component.update;
58 var view = component.view;
59
60 var _handleInit = handleInit(init);
61
62 var _handleInit2 = _slicedToArray(_handleInit, 2);
63
64 var initialState = _handleInit2[0];
65 var initialAction = _handleInit2[1];
66
67 // Initial call to update() will be @@redux/INIT so bogus dispatch() is okay
68
69 var dispatch = function dispatch(x) {
70 return x;
71 };
72
73 var store = createStoreWithMiddleware(function () {
74 var state = arguments.length <= 0 || arguments[0] === undefined ? initialState : arguments[0];
75 var action = arguments[1];
76
77 var newState = update(state, action, dispatch);
78
79 return typeof newState === 'undefined' ? state : newState;
80 });
81
82 dispatch = function (action) {
83 return function (event) {
84 if (event) {
85 action.event = event;
86 }
87
88 store.dispatch(action);
89 };
90 };
91
92 if (initialAction) {
93 store.dispatch(initialAction);
94 }
95
96 var tree = view(initialState, dispatch);
97 var rootNode = (0, _createElement2.default)(tree);
98
99 store.subscribe(function () {
100 tree = patchTree(rootNode, tree, view(store.getState(), dispatch));
101 });
102
103 return rootNode;
104}
105
106// patchTree :: Element -> VirtualNode -> VirtualNode -> VirtualNode
107function patchTree(rootNode, oldTree, newTree) {
108 (0, _patch2.default)(rootNode, (0, _diff2.default)(oldTree, newTree));
109
110 return newTree;
111}
112
113// initializeComponent :: Component -> Map
114function initializeComponent(_ref, dispatch) {
115 var init = _ref.init;
116
117 var _handleInit3 = handleInit(init);
118
119 var _handleInit4 = _slicedToArray(_handleInit3, 2);
120
121 var initialState = _handleInit4[0];
122 var initialAction = _handleInit4[1];
123
124 if (dispatch && initialAction) {
125 dispatch(initialState)(initialAction)();
126 }
127
128 return initialState;
129}
130
131// handleInit :: (_ -> Object) -> [Map, Maybe Action]
132function handleInit(init) {
133 var _res = init();
134 var res = Array.isArray(_res) ? _res : [_res];
135
136 return [new _Map2.default(res[0]), res[1]];
137}
138
139// Wrap a dispatcher, forwarding any actions onto the specified action by attaching
140// them to the __action property.
141//
142// Usually used by parent components to capture actions from child components.
143var forwardDispatch = exports.forwardDispatch = (0, _curry2.default)(function (action, dispatch, state) {
144 return function (forwardAction) {
145 if (typeof forwardAction === 'function') {
146 // In order to forward thunks, an intermediate thunk needs to be returned
147 // to gain access to the raw `action => <dispatch>` dispatcher rather than
148 // the application's wrapped `action => event => <dispatch>` dispatcher.
149 return dispatch(function (rawDispatch) {
150 var getState = function getState() {
151 return state;
152 };
153 var fwd = forwardDispatch(action, rawDispatch, state);
154
155 forwardAction(fwd, getState);
156 });
157 }
158
159 // Annotate and dispatch a simple action object
160 return dispatch(Object.assign({}, action, { __fwdAction: forwardAction }));
161 };
162});
163},{"./Map":2,"dom-delegator":10,"ramda/src/curry":22,"redux":34,"redux-thunk":32,"virtual-dom/create-element":42,"virtual-dom/diff":43,"virtual-dom/patch":44}],2:[function(require,module,exports){
164'use strict';
165
166var _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; }; })();
167
168Object.defineProperty(exports, "__esModule", {
169 value: true
170});
171
172var _assocPath = require('ramda/src/assocPath');
173
174var _assocPath2 = _interopRequireDefault(_assocPath);
175
176var _clone = require('./utils/clone');
177
178var _clone2 = _interopRequireDefault(_clone);
179
180var _path = require('ramda/src/path');
181
182var _path2 = _interopRequireDefault(_path);
183
184function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
185
186function _typeof(obj) { return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj; }
187
188function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
189
190var Map = (function () {
191 function Map(obj) {
192 _classCallCheck(this, Map);
193
194 if ((typeof obj === 'undefined' ? 'undefined' : _typeof(obj)) !== 'object') {
195 throw new TypeError(obj, 'is not an object');
196 }
197
198 this.obj = obj;
199 this['@@Plait/Map'] = 1;
200 }
201
202 _createClass(Map, [{
203 key: 'clone',
204 value: function clone() {
205 return new Map(this.toObject());
206 }
207 }, {
208 key: 'toObject',
209 value: function toObject() {
210 return (0, _clone2.default)(this.obj);
211 }
212 }, {
213 key: 'set',
214 value: function set(prop, val) {
215 var obj = this.toObject();
216
217 obj[prop] = val;
218
219 return new Map(obj);
220 }
221 }, {
222 key: 'get',
223 value: function get(prop) {
224 var obj = this.toObject();
225
226 return obj[prop];
227 }
228 }, {
229 key: 'update',
230 value: function update(prop, updater) {
231 return this.set(prop, updater(this.get(prop)));
232 }
233 }, {
234 key: 'setIn',
235 value: function setIn(propPath, val) {
236 var obj = (0, _assocPath2.default)(propPath, val, this.obj);
237
238 return new Map(obj);
239 }
240 }, {
241 key: 'getIn',
242 value: function getIn(propPath) {
243 return (0, _path2.default)(propPath, this.obj);
244 }
245 }]);
246
247 return Map;
248})();
249
250exports.default = Map;
251},{"./utils/clone":4,"ramda/src/assocPath":21,"ramda/src/path":31}],3:[function(require,module,exports){
252'use strict';
253
254Object.defineProperty(exports, "__esModule", {
255 value: true
256});
257exports.Map = exports.App = undefined;
258
259var _App = require('./App');
260
261var App = _interopRequireWildcard(_App);
262
263var _Map = require('./Map');
264
265var _Map2 = _interopRequireDefault(_Map);
266
267function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
268
269function _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; } }
270
271exports.App = App;
272exports.Map = _Map2.default;
273},{"./App":1,"./Map":2}],4:[function(require,module,exports){
274'use strict';
275
276Object.defineProperty(exports, "__esModule", {
277 value: true
278});
279exports.default = clone;
280
281function _typeof(obj) { return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj; }
282
283function clone(obj) {
284 var newObj = [];
285
286 for (var i in obj) {
287 var val = obj[i];
288
289 if ((typeof val === 'undefined' ? 'undefined' : _typeof(val)) === 'object') {
290 if (val.hasOwnProperty('@@Plait/Map')) {
291 newObj[i] = val.clone();
292 } else {
293 newObj[i] = clone(val);
294 }
295 } else {
296 newObj[i] = val;
297 }
298 }
299
300 return newObj;
301}
302},{}],5:[function(require,module,exports){
303
304},{}],6:[function(require,module,exports){
305// shim for using process in browser
306
307var process = module.exports = {};
308var queue = [];
309var draining = false;
310var currentQueue;
311var queueIndex = -1;
312
313function cleanUpNextTick() {
314 draining = false;
315 if (currentQueue.length) {
316 queue = currentQueue.concat(queue);
317 } else {
318 queueIndex = -1;
319 }
320 if (queue.length) {
321 drainQueue();
322 }
323}
324
325function drainQueue() {
326 if (draining) {
327 return;
328 }
329 var timeout = setTimeout(cleanUpNextTick);
330 draining = true;
331
332 var len = queue.length;
333 while(len) {
334 currentQueue = queue;
335 queue = [];
336 while (++queueIndex < len) {
337 if (currentQueue) {
338 currentQueue[queueIndex].run();
339 }
340 }
341 queueIndex = -1;
342 len = queue.length;
343 }
344 currentQueue = null;
345 draining = false;
346 clearTimeout(timeout);
347}
348
349process.nextTick = function (fun) {
350 var args = new Array(arguments.length - 1);
351 if (arguments.length > 1) {
352 for (var i = 1; i < arguments.length; i++) {
353 args[i - 1] = arguments[i];
354 }
355 }
356 queue.push(new Item(fun, args));
357 if (queue.length === 1 && !draining) {
358 setTimeout(drainQueue, 0);
359 }
360};
361
362// v8 likes predictible objects
363function Item(fun, array) {
364 this.fun = fun;
365 this.array = array;
366}
367Item.prototype.run = function () {
368 this.fun.apply(null, this.array);
369};
370process.title = 'browser';
371process.browser = true;
372process.env = {};
373process.argv = [];
374process.version = ''; // empty string to avoid regexp issues
375process.versions = {};
376
377function noop() {}
378
379process.on = noop;
380process.addListener = noop;
381process.once = noop;
382process.off = noop;
383process.removeListener = noop;
384process.removeAllListeners = noop;
385process.emit = noop;
386
387process.binding = function (name) {
388 throw new Error('process.binding is not supported');
389};
390
391process.cwd = function () { return '/' };
392process.chdir = function (dir) {
393 throw new Error('process.chdir is not supported');
394};
395process.umask = function() { return 0; };
396
397},{}],7:[function(require,module,exports){
398/**
399 * cuid.js
400 * Collision-resistant UID generator for browsers and node.
401 * Sequential for fast db lookups and recency sorting.
402 * Safe for element IDs and server-side lookups.
403 *
404 * Extracted from CLCTR
405 *
406 * Copyright (c) Eric Elliott 2012
407 * MIT License
408 */
409
410/*global window, navigator, document, require, process, module */
411(function (app) {
412 'use strict';
413 var namespace = 'cuid',
414 c = 0,
415 blockSize = 4,
416 base = 36,
417 discreteValues = Math.pow(base, blockSize),
418
419 pad = function pad(num, size) {
420 var s = "000000000" + num;
421 return s.substr(s.length-size);
422 },
423
424 randomBlock = function randomBlock() {
425 return pad((Math.random() *
426 discreteValues << 0)
427 .toString(base), blockSize);
428 },
429
430 safeCounter = function () {
431 c = (c < discreteValues) ? c : 0;
432 c++; // this is not subliminal
433 return c - 1;
434 },
435
436 api = function cuid() {
437 // Starting with a lowercase letter makes
438 // it HTML element ID friendly.
439 var letter = 'c', // hard-coded allows for sequential access
440
441 // timestamp
442 // warning: this exposes the exact date and time
443 // that the uid was created.
444 timestamp = (new Date().getTime()).toString(base),
445
446 // Prevent same-machine collisions.
447 counter,
448
449 // A few chars to generate distinct ids for different
450 // clients (so different computers are far less
451 // likely to generate the same id)
452 fingerprint = api.fingerprint(),
453
454 // Grab some more chars from Math.random()
455 random = randomBlock() + randomBlock();
456
457 counter = pad(safeCounter().toString(base), blockSize);
458
459 return (letter + timestamp + counter + fingerprint + random);
460 };
461
462 api.slug = function slug() {
463 var date = new Date().getTime().toString(36),
464 counter,
465 print = api.fingerprint().slice(0,1) +
466 api.fingerprint().slice(-1),
467 random = randomBlock().slice(-2);
468
469 counter = safeCounter().toString(36).slice(-4);
470
471 return date.slice(-2) +
472 counter + print + random;
473 };
474
475 api.globalCount = function globalCount() {
476 // We want to cache the results of this
477 var cache = (function calc() {
478 var i,
479 count = 0;
480
481 for (i in window) {
482 count++;
483 }
484
485 return count;
486 }());
487
488 api.globalCount = function () { return cache; };
489 return cache;
490 };
491
492 api.fingerprint = function browserPrint() {
493 return pad((navigator.mimeTypes.length +
494 navigator.userAgent.length).toString(36) +
495 api.globalCount().toString(36), 4);
496 };
497
498 // don't change anything from here down.
499 if (app.register) {
500 app.register(namespace, api);
501 } else if (typeof module !== 'undefined') {
502 module.exports = api;
503 } else {
504 app[namespace] = api;
505 }
506
507}(this.applitude || this));
508
509},{}],8:[function(require,module,exports){
510var EvStore = require("ev-store")
511
512module.exports = addEvent
513
514function addEvent(target, type, handler) {
515 var events = EvStore(target)
516 var event = events[type]
517
518 if (!event) {
519 events[type] = handler
520 } else if (Array.isArray(event)) {
521 if (event.indexOf(handler) === -1) {
522 event.push(handler)
523 }
524 } else if (event !== handler) {
525 events[type] = [event, handler]
526 }
527}
528
529},{"ev-store":14}],9:[function(require,module,exports){
530var globalDocument = require("global/document")
531var EvStore = require("ev-store")
532var createStore = require("weakmap-shim/create-store")
533
534var addEvent = require("./add-event.js")
535var removeEvent = require("./remove-event.js")
536var ProxyEvent = require("./proxy-event.js")
537
538var HANDLER_STORE = createStore()
539
540module.exports = DOMDelegator
541
542function DOMDelegator(document) {
543 if (!(this instanceof DOMDelegator)) {
544 return new DOMDelegator(document);
545 }
546
547 document = document || globalDocument
548
549 this.target = document.documentElement
550 this.events = {}
551 this.rawEventListeners = {}
552 this.globalListeners = {}
553}
554
555DOMDelegator.prototype.addEventListener = addEvent
556DOMDelegator.prototype.removeEventListener = removeEvent
557
558DOMDelegator.allocateHandle =
559 function allocateHandle(func) {
560 var handle = new Handle()
561
562 HANDLER_STORE(handle).func = func;
563
564 return handle
565 }
566
567DOMDelegator.transformHandle =
568 function transformHandle(handle, broadcast) {
569 var func = HANDLER_STORE(handle).func
570
571 return this.allocateHandle(function (ev) {
572 broadcast(ev, func);
573 })
574 }
575
576DOMDelegator.prototype.addGlobalEventListener =
577 function addGlobalEventListener(eventName, fn) {
578 var listeners = this.globalListeners[eventName] || [];
579 if (listeners.indexOf(fn) === -1) {
580 listeners.push(fn)
581 }
582
583 this.globalListeners[eventName] = listeners;
584 }
585
586DOMDelegator.prototype.removeGlobalEventListener =
587 function removeGlobalEventListener(eventName, fn) {
588 var listeners = this.globalListeners[eventName] || [];
589
590 var index = listeners.indexOf(fn)
591 if (index !== -1) {
592 listeners.splice(index, 1)
593 }
594 }
595
596DOMDelegator.prototype.listenTo = function listenTo(eventName) {
597 if (!(eventName in this.events)) {
598 this.events[eventName] = 0;
599 }
600
601 this.events[eventName]++;
602
603 if (this.events[eventName] !== 1) {
604 return
605 }
606
607 var listener = this.rawEventListeners[eventName]
608 if (!listener) {
609 listener = this.rawEventListeners[eventName] =
610 createHandler(eventName, this)
611 }
612
613 this.target.addEventListener(eventName, listener, true)
614}
615
616DOMDelegator.prototype.unlistenTo = function unlistenTo(eventName) {
617 if (!(eventName in this.events)) {
618 this.events[eventName] = 0;
619 }
620
621 if (this.events[eventName] === 0) {
622 throw new Error("already unlistened to event.");
623 }
624
625 this.events[eventName]--;
626
627 if (this.events[eventName] !== 0) {
628 return
629 }
630
631 var listener = this.rawEventListeners[eventName]
632
633 if (!listener) {
634 throw new Error("dom-delegator#unlistenTo: cannot " +
635 "unlisten to " + eventName)
636 }
637
638 this.target.removeEventListener(eventName, listener, true)
639}
640
641function createHandler(eventName, delegator) {
642 var globalListeners = delegator.globalListeners;
643 var delegatorTarget = delegator.target;
644
645 return handler
646
647 function handler(ev) {
648 var globalHandlers = globalListeners[eventName] || []
649
650 if (globalHandlers.length > 0) {
651 var globalEvent = new ProxyEvent(ev);
652 globalEvent.currentTarget = delegatorTarget;
653 callListeners(globalHandlers, globalEvent)
654 }
655
656 findAndInvokeListeners(ev.target, ev, eventName)
657 }
658}
659
660function findAndInvokeListeners(elem, ev, eventName) {
661 var listener = getListener(elem, eventName)
662
663 if (listener && listener.handlers.length > 0) {
664 var listenerEvent = new ProxyEvent(ev);
665 listenerEvent.currentTarget = listener.currentTarget
666 callListeners(listener.handlers, listenerEvent)
667
668 if (listenerEvent._bubbles) {
669 var nextTarget = listener.currentTarget.parentNode
670 findAndInvokeListeners(nextTarget, ev, eventName)
671 }
672 }
673}
674
675function getListener(target, type) {
676 // terminate recursion if parent is `null`
677 if (target === null || typeof target === "undefined") {
678 return null
679 }
680
681 var events = EvStore(target)
682 // fetch list of handler fns for this event
683 var handler = events[type]
684 var allHandler = events.event
685
686 if (!handler && !allHandler) {
687 return getListener(target.parentNode, type)
688 }
689
690 var handlers = [].concat(handler || [], allHandler || [])
691 return new Listener(target, handlers)
692}
693
694function callListeners(handlers, ev) {
695 handlers.forEach(function (handler) {
696 if (typeof handler === "function") {
697 handler(ev)
698 } else if (typeof handler.handleEvent === "function") {
699 handler.handleEvent(ev)
700 } else if (handler.type === "dom-delegator-handle") {
701 HANDLER_STORE(handler).func(ev)
702 } else {
703 throw new Error("dom-delegator: unknown handler " +
704 "found: " + JSON.stringify(handlers));
705 }
706 })
707}
708
709function Listener(target, handlers) {
710 this.currentTarget = target
711 this.handlers = handlers
712}
713
714function Handle() {
715 this.type = "dom-delegator-handle"
716}
717
718},{"./add-event.js":8,"./proxy-event.js":12,"./remove-event.js":13,"ev-store":14,"global/document":15,"weakmap-shim/create-store":61}],10:[function(require,module,exports){
719var Individual = require("individual")
720var cuid = require("cuid")
721var globalDocument = require("global/document")
722
723var DOMDelegator = require("./dom-delegator.js")
724
725var versionKey = "13"
726var cacheKey = "__DOM_DELEGATOR_CACHE@" + versionKey
727var cacheTokenKey = "__DOM_DELEGATOR_CACHE_TOKEN@" + versionKey
728var delegatorCache = Individual(cacheKey, {
729 delegators: {}
730})
731var commonEvents = [
732 "blur", "change", "click", "contextmenu", "dblclick",
733 "error","focus", "focusin", "focusout", "input", "keydown",
734 "keypress", "keyup", "load", "mousedown", "mouseup",
735 "resize", "select", "submit", "touchcancel",
736 "touchend", "touchstart", "unload"
737]
738
739/* Delegator is a thin wrapper around a singleton `DOMDelegator`
740 instance.
741
742 Only one DOMDelegator should exist because we do not want
743 duplicate event listeners bound to the DOM.
744
745 `Delegator` will also `listenTo()` all events unless
746 every caller opts out of it
747*/
748module.exports = Delegator
749
750function Delegator(opts) {
751 opts = opts || {}
752 var document = opts.document || globalDocument
753
754 var cacheKey = document[cacheTokenKey]
755
756 if (!cacheKey) {
757 cacheKey =
758 document[cacheTokenKey] = cuid()
759 }
760
761 var delegator = delegatorCache.delegators[cacheKey]
762
763 if (!delegator) {
764 delegator = delegatorCache.delegators[cacheKey] =
765 new DOMDelegator(document)
766 }
767
768 if (opts.defaultEvents !== false) {
769 for (var i = 0; i < commonEvents.length; i++) {
770 delegator.listenTo(commonEvents[i])
771 }
772 }
773
774 return delegator
775}
776
777Delegator.allocateHandle = DOMDelegator.allocateHandle;
778Delegator.transformHandle = DOMDelegator.transformHandle;
779
780},{"./dom-delegator.js":9,"cuid":7,"global/document":15,"individual":11}],11:[function(require,module,exports){
781(function (global){
782var root = typeof window !== 'undefined' ?
783 window : typeof global !== 'undefined' ?
784 global : {};
785
786module.exports = Individual
787
788function Individual(key, value) {
789 if (root[key]) {
790 return root[key]
791 }
792
793 Object.defineProperty(root, key, {
794 value: value
795 , configurable: true
796 })
797
798 return value
799}
800
801}).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
802
803},{}],12:[function(require,module,exports){
804var inherits = require("inherits")
805
806var ALL_PROPS = [
807 "altKey", "bubbles", "cancelable", "ctrlKey",
808 "eventPhase", "metaKey", "relatedTarget", "shiftKey",
809 "target", "timeStamp", "type", "view", "which"
810]
811var KEY_PROPS = ["char", "charCode", "key", "keyCode"]
812var MOUSE_PROPS = [
813 "button", "buttons", "clientX", "clientY", "layerX",
814 "layerY", "offsetX", "offsetY", "pageX", "pageY",
815 "screenX", "screenY", "toElement"
816]
817
818var rkeyEvent = /^key|input/
819var rmouseEvent = /^(?:mouse|pointer|contextmenu)|click/
820
821module.exports = ProxyEvent
822
823function ProxyEvent(ev) {
824 if (!(this instanceof ProxyEvent)) {
825 return new ProxyEvent(ev)
826 }
827
828 if (rkeyEvent.test(ev.type)) {
829 return new KeyEvent(ev)
830 } else if (rmouseEvent.test(ev.type)) {
831 return new MouseEvent(ev)
832 }
833
834 for (var i = 0; i < ALL_PROPS.length; i++) {
835 var propKey = ALL_PROPS[i]
836 this[propKey] = ev[propKey]
837 }
838
839 this._rawEvent = ev
840 this._bubbles = false;
841}
842
843ProxyEvent.prototype.preventDefault = function () {
844 this._rawEvent.preventDefault()
845}
846
847ProxyEvent.prototype.startPropagation = function () {
848 this._bubbles = true;
849}
850
851function MouseEvent(ev) {
852 for (var i = 0; i < ALL_PROPS.length; i++) {
853 var propKey = ALL_PROPS[i]
854 this[propKey] = ev[propKey]
855 }
856
857 for (var j = 0; j < MOUSE_PROPS.length; j++) {
858 var mousePropKey = MOUSE_PROPS[j]
859 this[mousePropKey] = ev[mousePropKey]
860 }
861
862 this._rawEvent = ev
863}
864
865inherits(MouseEvent, ProxyEvent)
866
867function KeyEvent(ev) {
868 for (var i = 0; i < ALL_PROPS.length; i++) {
869 var propKey = ALL_PROPS[i]
870 this[propKey] = ev[propKey]
871 }
872
873 for (var j = 0; j < KEY_PROPS.length; j++) {
874 var keyPropKey = KEY_PROPS[j]
875 this[keyPropKey] = ev[keyPropKey]
876 }
877
878 this._rawEvent = ev
879}
880
881inherits(KeyEvent, ProxyEvent)
882
883},{"inherits":18}],13:[function(require,module,exports){
884var EvStore = require("ev-store")
885
886module.exports = removeEvent
887
888function removeEvent(target, type, handler) {
889 var events = EvStore(target)
890 var event = events[type]
891
892 if (!event) {
893 return
894 } else if (Array.isArray(event)) {
895 var index = event.indexOf(handler)
896 if (index !== -1) {
897 event.splice(index, 1)
898 }
899 } else if (event === handler) {
900 events[type] = null
901 }
902}
903
904},{"ev-store":14}],14:[function(require,module,exports){
905'use strict';
906
907var OneVersionConstraint = require('individual/one-version');
908
909var MY_VERSION = '7';
910OneVersionConstraint('ev-store', MY_VERSION);
911
912var hashKey = '__EV_STORE_KEY@' + MY_VERSION;
913
914module.exports = EvStore;
915
916function EvStore(elem) {
917 var hash = elem[hashKey];
918
919 if (!hash) {
920 hash = elem[hashKey] = {};
921 }
922
923 return hash;
924}
925
926},{"individual/one-version":17}],15:[function(require,module,exports){
927(function (global){
928var topLevel = typeof global !== 'undefined' ? global :
929 typeof window !== 'undefined' ? window : {}
930var minDoc = require('min-document');
931
932if (typeof document !== 'undefined') {
933 module.exports = document;
934} else {
935 var doccy = topLevel['__GLOBAL_DOCUMENT_CACHE@4'];
936
937 if (!doccy) {
938 doccy = topLevel['__GLOBAL_DOCUMENT_CACHE@4'] = minDoc;
939 }
940
941 module.exports = doccy;
942}
943
944}).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
945
946},{"min-document":5}],16:[function(require,module,exports){
947(function (global){
948'use strict';
949
950/*global window, global*/
951
952var root = typeof window !== 'undefined' ?
953 window : typeof global !== 'undefined' ?
954 global : {};
955
956module.exports = Individual;
957
958function Individual(key, value) {
959 if (key in root) {
960 return root[key];
961 }
962
963 root[key] = value;
964
965 return value;
966}
967
968}).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
969
970},{}],17:[function(require,module,exports){
971'use strict';
972
973var Individual = require('./index.js');
974
975module.exports = OneVersion;
976
977function OneVersion(moduleName, version, defaultValue) {
978 var key = '__INDIVIDUAL_ONE_VERSION_' + moduleName;
979 var enforceKey = key + '_ENFORCE_SINGLETON';
980
981 var versionValue = Individual(enforceKey, version);
982
983 if (versionValue !== version) {
984 throw new Error('Can only have one copy of ' +
985 moduleName + '.\n' +
986 'You already have version ' + versionValue +
987 ' installed.\n' +
988 'This means you cannot install version ' + version);
989 }
990
991 return Individual(key, defaultValue);
992}
993
994},{"./index.js":16}],18:[function(require,module,exports){
995if (typeof Object.create === 'function') {
996 // implementation from standard node.js 'util' module
997 module.exports = function inherits(ctor, superCtor) {
998 ctor.super_ = superCtor
999 ctor.prototype = Object.create(superCtor.prototype, {
1000 constructor: {
1001 value: ctor,
1002 enumerable: false,
1003 writable: true,
1004 configurable: true
1005 }
1006 });
1007 };
1008} else {
1009 // old school shim for old browsers
1010 module.exports = function inherits(ctor, superCtor) {
1011 ctor.super_ = superCtor
1012 var TempCtor = function () {}
1013 TempCtor.prototype = superCtor.prototype
1014 ctor.prototype = new TempCtor()
1015 ctor.prototype.constructor = ctor
1016 }
1017}
1018
1019},{}],19:[function(require,module,exports){
1020"use strict";
1021
1022module.exports = function isObject(x) {
1023 return typeof x === "object" && x !== null;
1024};
1025
1026},{}],20:[function(require,module,exports){
1027var _curry3 = require('./internal/_curry3');
1028
1029
1030/**
1031 * Makes a shallow clone of an object, setting or overriding the specified
1032 * property with the given value. Note that this copies and flattens prototype
1033 * properties onto the new object as well. All non-primitive properties are
1034 * copied by reference.
1035 *
1036 * @func
1037 * @memberOf R
1038 * @since v0.8.0
1039 * @category Object
1040 * @sig String -> a -> {k: v} -> {k: v}
1041 * @param {String} prop the property name to set
1042 * @param {*} val the new value
1043 * @param {Object} obj the object to clone
1044 * @return {Object} a new object similar to the original except for the specified property.
1045 * @see R.dissoc
1046 * @example
1047 *
1048 * R.assoc('c', 3, {a: 1, b: 2}); //=> {a: 1, b: 2, c: 3}
1049 */
1050module.exports = _curry3(function assoc(prop, val, obj) {
1051 var result = {};
1052 for (var p in obj) {
1053 result[p] = obj[p];
1054 }
1055 result[prop] = val;
1056 return result;
1057});
1058
1059},{"./internal/_curry3":27}],21:[function(require,module,exports){
1060var _curry3 = require('./internal/_curry3');
1061var _slice = require('./internal/_slice');
1062var assoc = require('./assoc');
1063
1064
1065/**
1066 * Makes a shallow clone of an object, setting or overriding the nodes required
1067 * to create the given path, and placing the specific value at the tail end of
1068 * that path. Note that this copies and flattens prototype properties onto the
1069 * new object as well. All non-primitive properties are copied by reference.
1070 *
1071 * @func
1072 * @memberOf R
1073 * @since v0.8.0
1074 * @category Object
1075 * @sig [String] -> a -> {k: v} -> {k: v}
1076 * @param {Array} path the path to set
1077 * @param {*} val the new value
1078 * @param {Object} obj the object to clone
1079 * @return {Object} a new object similar to the original except along the specified path.
1080 * @see R.dissocPath
1081 * @example
1082 *
1083 * R.assocPath(['a', 'b', 'c'], 42, {a: {b: {c: 0}}}); //=> {a: {b: {c: 42}}}
1084 */
1085module.exports = _curry3(function assocPath(path, val, obj) {
1086 switch (path.length) {
1087 case 0:
1088 return val;
1089 case 1:
1090 return assoc(path[0], val, obj);
1091 default:
1092 return assoc(path[0], assocPath(_slice(path, 1), val, Object(obj[path[0]])), obj);
1093 }
1094});
1095
1096},{"./assoc":20,"./internal/_curry3":27,"./internal/_slice":30}],22:[function(require,module,exports){
1097var _curry1 = require('./internal/_curry1');
1098var curryN = require('./curryN');
1099
1100
1101/**
1102 * Returns a curried equivalent of the provided function. The curried function
1103 * has two unusual capabilities. First, its arguments needn't be provided one
1104 * at a time. If `f` is a ternary function and `g` is `R.curry(f)`, the
1105 * following are equivalent:
1106 *
1107 * - `g(1)(2)(3)`
1108 * - `g(1)(2, 3)`
1109 * - `g(1, 2)(3)`
1110 * - `g(1, 2, 3)`
1111 *
1112 * Secondly, the special placeholder value `R.__` may be used to specify
1113 * "gaps", allowing partial application of any combination of arguments,
1114 * regardless of their positions. If `g` is as above and `_` is `R.__`, the
1115 * following are equivalent:
1116 *
1117 * - `g(1, 2, 3)`
1118 * - `g(_, 2, 3)(1)`
1119 * - `g(_, _, 3)(1)(2)`
1120 * - `g(_, _, 3)(1, 2)`
1121 * - `g(_, 2)(1)(3)`
1122 * - `g(_, 2)(1, 3)`
1123 * - `g(_, 2)(_, 3)(1)`
1124 *
1125 * @func
1126 * @memberOf R
1127 * @since v0.1.0
1128 * @category Function
1129 * @sig (* -> a) -> (* -> a)
1130 * @param {Function} fn The function to curry.
1131 * @return {Function} A new, curried function.
1132 * @see R.curryN
1133 * @example
1134 *
1135 * var addFourNumbers = (a, b, c, d) => a + b + c + d;
1136 *
1137 * var curriedAddFourNumbers = R.curry(addFourNumbers);
1138 * var f = curriedAddFourNumbers(1, 2);
1139 * var g = f(3);
1140 * g(4); //=> 10
1141 */
1142module.exports = _curry1(function curry(fn) {
1143 return curryN(fn.length, fn);
1144});
1145
1146},{"./curryN":23,"./internal/_curry1":25}],23:[function(require,module,exports){
1147var _arity = require('./internal/_arity');
1148var _curry1 = require('./internal/_curry1');
1149var _curry2 = require('./internal/_curry2');
1150var _curryN = require('./internal/_curryN');
1151
1152
1153/**
1154 * Returns a curried equivalent of the provided function, with the specified
1155 * arity. The curried function has two unusual capabilities. First, its
1156 * arguments needn't be provided one at a time. If `g` is `R.curryN(3, f)`, the
1157 * following are equivalent:
1158 *
1159 * - `g(1)(2)(3)`
1160 * - `g(1)(2, 3)`
1161 * - `g(1, 2)(3)`
1162 * - `g(1, 2, 3)`
1163 *
1164 * Secondly, the special placeholder value `R.__` may be used to specify
1165 * "gaps", allowing partial application of any combination of arguments,
1166 * regardless of their positions. If `g` is as above and `_` is `R.__`, the
1167 * following are equivalent:
1168 *
1169 * - `g(1, 2, 3)`
1170 * - `g(_, 2, 3)(1)`
1171 * - `g(_, _, 3)(1)(2)`
1172 * - `g(_, _, 3)(1, 2)`
1173 * - `g(_, 2)(1)(3)`
1174 * - `g(_, 2)(1, 3)`
1175 * - `g(_, 2)(_, 3)(1)`
1176 *
1177 * @func
1178 * @memberOf R
1179 * @since v0.5.0
1180 * @category Function
1181 * @sig Number -> (* -> a) -> (* -> a)
1182 * @param {Number} length The arity for the returned function.
1183 * @param {Function} fn The function to curry.
1184 * @return {Function} A new, curried function.
1185 * @see R.curry
1186 * @example
1187 *
1188 * var sumArgs = (...args) => R.sum(args);
1189 *
1190 * var curriedAddFourNumbers = R.curryN(4, sumArgs);
1191 * var f = curriedAddFourNumbers(1, 2);
1192 * var g = f(3);
1193 * g(4); //=> 10
1194 */
1195module.exports = _curry2(function curryN(length, fn) {
1196 if (length === 1) {
1197 return _curry1(fn);
1198 }
1199 return _arity(length, _curryN(length, [], fn));
1200});
1201
1202},{"./internal/_arity":24,"./internal/_curry1":25,"./internal/_curry2":26,"./internal/_curryN":28}],24:[function(require,module,exports){
1203module.exports = function _arity(n, fn) {
1204 /* eslint-disable no-unused-vars */
1205 switch (n) {
1206 case 0: return function() { return fn.apply(this, arguments); };
1207 case 1: return function(a0) { return fn.apply(this, arguments); };
1208 case 2: return function(a0, a1) { return fn.apply(this, arguments); };
1209 case 3: return function(a0, a1, a2) { return fn.apply(this, arguments); };
1210 case 4: return function(a0, a1, a2, a3) { return fn.apply(this, arguments); };
1211 case 5: return function(a0, a1, a2, a3, a4) { return fn.apply(this, arguments); };
1212 case 6: return function(a0, a1, a2, a3, a4, a5) { return fn.apply(this, arguments); };
1213 case 7: return function(a0, a1, a2, a3, a4, a5, a6) { return fn.apply(this, arguments); };
1214 case 8: return function(a0, a1, a2, a3, a4, a5, a6, a7) { return fn.apply(this, arguments); };
1215 case 9: return function(a0, a1, a2, a3, a4, a5, a6, a7, a8) { return fn.apply(this, arguments); };
1216 case 10: return function(a0, a1, a2, a3, a4, a5, a6, a7, a8, a9) { return fn.apply(this, arguments); };
1217 default: throw new Error('First argument to _arity must be a non-negative integer no greater than ten');
1218 }
1219};
1220
1221},{}],25:[function(require,module,exports){
1222var _isPlaceholder = require('./_isPlaceholder');
1223
1224
1225/**
1226 * Optimized internal one-arity curry function.
1227 *
1228 * @private
1229 * @category Function
1230 * @param {Function} fn The function to curry.
1231 * @return {Function} The curried function.
1232 */
1233module.exports = function _curry1(fn) {
1234 return function f1(a) {
1235 if (arguments.length === 0 || _isPlaceholder(a)) {
1236 return f1;
1237 } else {
1238 return fn.apply(this, arguments);
1239 }
1240 };
1241};
1242
1243},{"./_isPlaceholder":29}],26:[function(require,module,exports){
1244var _curry1 = require('./_curry1');
1245var _isPlaceholder = require('./_isPlaceholder');
1246
1247
1248/**
1249 * Optimized internal two-arity curry function.
1250 *
1251 * @private
1252 * @category Function
1253 * @param {Function} fn The function to curry.
1254 * @return {Function} The curried function.
1255 */
1256module.exports = function _curry2(fn) {
1257 return function f2(a, b) {
1258 switch (arguments.length) {
1259 case 0:
1260 return f2;
1261 case 1:
1262 return _isPlaceholder(a) ? f2
1263 : _curry1(function(_b) { return fn(a, _b); });
1264 default:
1265 return _isPlaceholder(a) && _isPlaceholder(b) ? f2
1266 : _isPlaceholder(a) ? _curry1(function(_a) { return fn(_a, b); })
1267 : _isPlaceholder(b) ? _curry1(function(_b) { return fn(a, _b); })
1268 : fn(a, b);
1269 }
1270 };
1271};
1272
1273},{"./_curry1":25,"./_isPlaceholder":29}],27:[function(require,module,exports){
1274var _curry1 = require('./_curry1');
1275var _curry2 = require('./_curry2');
1276var _isPlaceholder = require('./_isPlaceholder');
1277
1278
1279/**
1280 * Optimized internal three-arity curry function.
1281 *
1282 * @private
1283 * @category Function
1284 * @param {Function} fn The function to curry.
1285 * @return {Function} The curried function.
1286 */
1287module.exports = function _curry3(fn) {
1288 return function f3(a, b, c) {
1289 switch (arguments.length) {
1290 case 0:
1291 return f3;
1292 case 1:
1293 return _isPlaceholder(a) ? f3
1294 : _curry2(function(_b, _c) { return fn(a, _b, _c); });
1295 case 2:
1296 return _isPlaceholder(a) && _isPlaceholder(b) ? f3
1297 : _isPlaceholder(a) ? _curry2(function(_a, _c) { return fn(_a, b, _c); })
1298 : _isPlaceholder(b) ? _curry2(function(_b, _c) { return fn(a, _b, _c); })
1299 : _curry1(function(_c) { return fn(a, b, _c); });
1300 default:
1301 return _isPlaceholder(a) && _isPlaceholder(b) && _isPlaceholder(c) ? f3
1302 : _isPlaceholder(a) && _isPlaceholder(b) ? _curry2(function(_a, _b) { return fn(_a, _b, c); })
1303 : _isPlaceholder(a) && _isPlaceholder(c) ? _curry2(function(_a, _c) { return fn(_a, b, _c); })
1304 : _isPlaceholder(b) && _isPlaceholder(c) ? _curry2(function(_b, _c) { return fn(a, _b, _c); })
1305 : _isPlaceholder(a) ? _curry1(function(_a) { return fn(_a, b, c); })
1306 : _isPlaceholder(b) ? _curry1(function(_b) { return fn(a, _b, c); })
1307 : _isPlaceholder(c) ? _curry1(function(_c) { return fn(a, b, _c); })
1308 : fn(a, b, c);
1309 }
1310 };
1311};
1312
1313},{"./_curry1":25,"./_curry2":26,"./_isPlaceholder":29}],28:[function(require,module,exports){
1314var _arity = require('./_arity');
1315var _isPlaceholder = require('./_isPlaceholder');
1316
1317
1318/**
1319 * Internal curryN function.
1320 *
1321 * @private
1322 * @category Function
1323 * @param {Number} length The arity of the curried function.
1324 * @param {Array} received An array of arguments received thus far.
1325 * @param {Function} fn The function to curry.
1326 * @return {Function} The curried function.
1327 */
1328module.exports = function _curryN(length, received, fn) {
1329 return function() {
1330 var combined = [];
1331 var argsIdx = 0;
1332 var left = length;
1333 var combinedIdx = 0;
1334 while (combinedIdx < received.length || argsIdx < arguments.length) {
1335 var result;
1336 if (combinedIdx < received.length &&
1337 (!_isPlaceholder(received[combinedIdx]) ||
1338 argsIdx >= arguments.length)) {
1339 result = received[combinedIdx];
1340 } else {
1341 result = arguments[argsIdx];
1342 argsIdx += 1;
1343 }
1344 combined[combinedIdx] = result;
1345 if (!_isPlaceholder(result)) {
1346 left -= 1;
1347 }
1348 combinedIdx += 1;
1349 }
1350 return left <= 0 ? fn.apply(this, combined)
1351 : _arity(left, _curryN(length, combined, fn));
1352 };
1353};
1354
1355},{"./_arity":24,"./_isPlaceholder":29}],29:[function(require,module,exports){
1356module.exports = function _isPlaceholder(a) {
1357 return a != null &&
1358 typeof a === 'object' &&
1359 a['@@functional/placeholder'] === true;
1360};
1361
1362},{}],30:[function(require,module,exports){
1363/**
1364 * An optimized, private array `slice` implementation.
1365 *
1366 * @private
1367 * @param {Arguments|Array} args The array or arguments object to consider.
1368 * @param {Number} [from=0] The array index to slice from, inclusive.
1369 * @param {Number} [to=args.length] The array index to slice to, exclusive.
1370 * @return {Array} A new, sliced array.
1371 * @example
1372 *
1373 * _slice([1, 2, 3, 4, 5], 1, 3); //=> [2, 3]
1374 *
1375 * var firstThreeArgs = function(a, b, c, d) {
1376 * return _slice(arguments, 0, 3);
1377 * };
1378 * firstThreeArgs(1, 2, 3, 4); //=> [1, 2, 3]
1379 */
1380module.exports = function _slice(args, from, to) {
1381 switch (arguments.length) {
1382 case 1: return _slice(args, 0, args.length);
1383 case 2: return _slice(args, from, args.length);
1384 default:
1385 var list = [];
1386 var idx = 0;
1387 var len = Math.max(0, Math.min(args.length, to) - from);
1388 while (idx < len) {
1389 list[idx] = args[from + idx];
1390 idx += 1;
1391 }
1392 return list;
1393 }
1394};
1395
1396},{}],31:[function(require,module,exports){
1397var _curry2 = require('./internal/_curry2');
1398
1399
1400/**
1401 * Retrieve the value at a given path.
1402 *
1403 * @func
1404 * @memberOf R
1405 * @since v0.2.0
1406 * @category Object
1407 * @sig [String] -> {k: v} -> v | Undefined
1408 * @param {Array} path The path to use.
1409 * @param {Object} obj The object to retrieve the nested property from.
1410 * @return {*} The data at `path`.
1411 * @example
1412 *
1413 * R.path(['a', 'b'], {a: {b: 2}}); //=> 2
1414 * R.path(['a', 'b'], {c: {b: 2}}); //=> undefined
1415 */
1416module.exports = _curry2(function path(paths, obj) {
1417 var val = obj;
1418 var idx = 0;
1419 while (idx < paths.length) {
1420 if (val == null) {
1421 return;
1422 }
1423 val = val[paths[idx]];
1424 idx += 1;
1425 }
1426 return val;
1427});
1428
1429},{"./internal/_curry2":26}],32:[function(require,module,exports){
1430'use strict';
1431
1432function thunkMiddleware(_ref) {
1433 var dispatch = _ref.dispatch;
1434 var getState = _ref.getState;
1435
1436 return function (next) {
1437 return function (action) {
1438 return typeof action === 'function' ? action(dispatch, getState) : next(action);
1439 };
1440 };
1441}
1442
1443module.exports = thunkMiddleware;
1444},{}],33:[function(require,module,exports){
1445'use strict';
1446
1447exports.__esModule = true;
1448exports['default'] = createStore;
1449
1450function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }
1451
1452var _utilsIsPlainObject = require('./utils/isPlainObject');
1453
1454var _utilsIsPlainObject2 = _interopRequireDefault(_utilsIsPlainObject);
1455
1456/**
1457 * These are private action types reserved by Redux.
1458 * For any unknown actions, you must return the current state.
1459 * If the current state is undefined, you must return the initial state.
1460 * Do not reference these action types directly in your code.
1461 */
1462var ActionTypes = {
1463 INIT: '@@redux/INIT'
1464};
1465
1466exports.ActionTypes = ActionTypes;
1467/**
1468 * Creates a Redux store that holds the state tree.
1469 * The only way to change the data in the store is to call `dispatch()` on it.
1470 *
1471 * There should only be a single store in your app. To specify how different
1472 * parts of the state tree respond to actions, you may combine several reducers
1473 * into a single reducer function by using `combineReducers`.
1474 *
1475 * @param {Function} reducer A function that returns the next state tree, given
1476 * the current state tree and the action to handle.
1477 *
1478 * @param {any} [initialState] The initial state. You may optionally specify it
1479 * to hydrate the state from the server in universal apps, or to restore a
1480 * previously serialized user session.
1481 * If you use `combineReducers` to produce the root reducer function, this must be
1482 * an object with the same shape as `combineReducers` keys.
1483 *
1484 * @returns {Store} A Redux store that lets you read the state, dispatch actions
1485 * and subscribe to changes.
1486 */
1487
1488function createStore(reducer, initialState) {
1489 if (typeof reducer !== 'function') {
1490 throw new Error('Expected the reducer to be a function.');
1491 }
1492
1493 var currentReducer = reducer;
1494 var currentState = initialState;
1495 var listeners = [];
1496 var isDispatching = false;
1497
1498 /**
1499 * Reads the state tree managed by the store.
1500 *
1501 * @returns {any} The current state tree of your application.
1502 */
1503 function getState() {
1504 return currentState;
1505 }
1506
1507 /**
1508 * Adds a change listener. It will be called any time an action is dispatched,
1509 * and some part of the state tree may potentially have changed. You may then
1510 * call `getState()` to read the current state tree inside the callback.
1511 *
1512 * @param {Function} listener A callback to be invoked on every dispatch.
1513 * @returns {Function} A function to remove this change listener.
1514 */
1515 function subscribe(listener) {
1516 listeners.push(listener);
1517 var isSubscribed = true;
1518
1519 return function unsubscribe() {
1520 if (!isSubscribed) {
1521 return;
1522 }
1523
1524 isSubscribed = false;
1525 var index = listeners.indexOf(listener);
1526 listeners.splice(index, 1);
1527 };
1528 }
1529
1530 /**
1531 * Dispatches an action. It is the only way to trigger a state change.
1532 *
1533 * The `reducer` function, used to create the store, will be called with the
1534 * current state tree and the given `action`. Its return value will
1535 * be considered the **next** state of the tree, and the change listeners
1536 * will be notified.
1537 *
1538 * The base implementation only supports plain object actions. If you want to
1539 * dispatch a Promise, an Observable, a thunk, or something else, you need to
1540 * wrap your store creating function into the corresponding middleware. For
1541 * example, see the documentation for the `redux-thunk` package. Even the
1542 * middleware will eventually dispatch plain object actions using this method.
1543 *
1544 * @param {Object} action A plain object representing “what changed”. It is
1545 * a good idea to keep actions serializable so you can record and replay user
1546 * sessions, or use the time travelling `redux-devtools`. An action must have
1547 * a `type` property which may not be `undefined`. It is a good idea to use
1548 * string constants for action types.
1549 *
1550 * @returns {Object} For convenience, the same action object you dispatched.
1551 *
1552 * Note that, if you use a custom middleware, it may wrap `dispatch()` to
1553 * return something else (for example, a Promise you can await).
1554 */
1555 function dispatch(action) {
1556 if (!_utilsIsPlainObject2['default'](action)) {
1557 throw new Error('Actions must be plain objects. ' + 'Use custom middleware for async actions.');
1558 }
1559
1560 if (typeof action.type === 'undefined') {
1561 throw new Error('Actions may not have an undefined "type" property. ' + 'Have you misspelled a constant?');
1562 }
1563
1564 if (isDispatching) {
1565 throw new Error('Reducers may not dispatch actions.');
1566 }
1567
1568 try {
1569 isDispatching = true;
1570 currentState = currentReducer(currentState, action);
1571 } finally {
1572 isDispatching = false;
1573 }
1574
1575 listeners.slice().forEach(function (listener) {
1576 return listener();
1577 });
1578 return action;
1579 }
1580
1581 /**
1582 * Replaces the reducer currently used by the store to calculate the state.
1583 *
1584 * You might need this if your app implements code splitting and you want to
1585 * load some of the reducers dynamically. You might also need this if you
1586 * implement a hot reloading mechanism for Redux.
1587 *
1588 * @param {Function} nextReducer The reducer for the store to use instead.
1589 * @returns {void}
1590 */
1591 function replaceReducer(nextReducer) {
1592 currentReducer = nextReducer;
1593 dispatch({ type: ActionTypes.INIT });
1594 }
1595
1596 // When a store is created, an "INIT" action is dispatched so that every
1597 // reducer returns their initial state. This effectively populates
1598 // the initial state tree.
1599 dispatch({ type: ActionTypes.INIT });
1600
1601 return {
1602 dispatch: dispatch,
1603 subscribe: subscribe,
1604 getState: getState,
1605 replaceReducer: replaceReducer
1606 };
1607}
1608},{"./utils/isPlainObject":39}],34:[function(require,module,exports){
1609'use strict';
1610
1611exports.__esModule = true;
1612
1613function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }
1614
1615var _createStore = require('./createStore');
1616
1617var _createStore2 = _interopRequireDefault(_createStore);
1618
1619var _utilsCombineReducers = require('./utils/combineReducers');
1620
1621var _utilsCombineReducers2 = _interopRequireDefault(_utilsCombineReducers);
1622
1623var _utilsBindActionCreators = require('./utils/bindActionCreators');
1624
1625var _utilsBindActionCreators2 = _interopRequireDefault(_utilsBindActionCreators);
1626
1627var _utilsApplyMiddleware = require('./utils/applyMiddleware');
1628
1629var _utilsApplyMiddleware2 = _interopRequireDefault(_utilsApplyMiddleware);
1630
1631var _utilsCompose = require('./utils/compose');
1632
1633var _utilsCompose2 = _interopRequireDefault(_utilsCompose);
1634
1635exports.createStore = _createStore2['default'];
1636exports.combineReducers = _utilsCombineReducers2['default'];
1637exports.bindActionCreators = _utilsBindActionCreators2['default'];
1638exports.applyMiddleware = _utilsApplyMiddleware2['default'];
1639exports.compose = _utilsCompose2['default'];
1640},{"./createStore":33,"./utils/applyMiddleware":35,"./utils/bindActionCreators":36,"./utils/combineReducers":37,"./utils/compose":38}],35:[function(require,module,exports){
1641'use strict';
1642
1643exports.__esModule = true;
1644
1645var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; };
1646
1647exports['default'] = applyMiddleware;
1648
1649function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }
1650
1651var _compose = require('./compose');
1652
1653var _compose2 = _interopRequireDefault(_compose);
1654
1655/**
1656 * Creates a store enhancer that applies middleware to the dispatch method
1657 * of the Redux store. This is handy for a variety of tasks, such as expressing
1658 * asynchronous actions in a concise manner, or logging every action payload.
1659 *
1660 * See `redux-thunk` package as an example of the Redux middleware.
1661 *
1662 * Because middleware is potentially asynchronous, this should be the first
1663 * store enhancer in the composition chain.
1664 *
1665 * Note that each middleware will be given the `dispatch` and `getState` functions
1666 * as named arguments.
1667 *
1668 * @param {...Function} middlewares The middleware chain to be applied.
1669 * @returns {Function} A store enhancer applying the middleware.
1670 */
1671
1672function applyMiddleware() {
1673 for (var _len = arguments.length, middlewares = Array(_len), _key = 0; _key < _len; _key++) {
1674 middlewares[_key] = arguments[_key];
1675 }
1676
1677 return function (next) {
1678 return function (reducer, initialState) {
1679 var store = next(reducer, initialState);
1680 var _dispatch = store.dispatch;
1681 var chain = [];
1682
1683 var middlewareAPI = {
1684 getState: store.getState,
1685 dispatch: function dispatch(action) {
1686 return _dispatch(action);
1687 }
1688 };
1689 chain = middlewares.map(function (middleware) {
1690 return middleware(middlewareAPI);
1691 });
1692 _dispatch = _compose2['default'].apply(undefined, chain)(store.dispatch);
1693
1694 return _extends({}, store, {
1695 dispatch: _dispatch
1696 });
1697 };
1698 };
1699}
1700
1701module.exports = exports['default'];
1702},{"./compose":38}],36:[function(require,module,exports){
1703'use strict';
1704
1705exports.__esModule = true;
1706exports['default'] = bindActionCreators;
1707
1708function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }
1709
1710var _mapValues = require('./mapValues');
1711
1712var _mapValues2 = _interopRequireDefault(_mapValues);
1713
1714function bindActionCreator(actionCreator, dispatch) {
1715 return function () {
1716 return dispatch(actionCreator.apply(undefined, arguments));
1717 };
1718}
1719
1720/**
1721 * Turns an object whose values are action creators, into an object with the
1722 * same keys, but with every function wrapped into a `dispatch` call so they
1723 * may be invoked directly. This is just a convenience method, as you can call
1724 * `store.dispatch(MyActionCreators.doSomething())` yourself just fine.
1725 *
1726 * For convenience, you can also pass a single function as the first argument,
1727 * and get a function in return.
1728 *
1729 * @param {Function|Object} actionCreators An object whose values are action
1730 * creator functions. One handy way to obtain it is to use ES6 `import * as`
1731 * syntax. You may also pass a single function.
1732 *
1733 * @param {Function} dispatch The `dispatch` function available on your Redux
1734 * store.
1735 *
1736 * @returns {Function|Object} The object mimicking the original object, but with
1737 * every action creator wrapped into the `dispatch` call. If you passed a
1738 * function as `actionCreators`, the return value will also be a single
1739 * function.
1740 */
1741
1742function bindActionCreators(actionCreators, dispatch) {
1743 if (typeof actionCreators === 'function') {
1744 return bindActionCreator(actionCreators, dispatch);
1745 }
1746
1747 if (typeof actionCreators !== 'object' || actionCreators === null || actionCreators === undefined) {
1748 throw new Error('bindActionCreators expected an object or a function, instead received ' + (actionCreators === null ? 'null' : typeof actionCreators) + '. ' + 'Did you write "import ActionCreators from" instead of "import * as ActionCreators from"?');
1749 }
1750
1751 return _mapValues2['default'](actionCreators, function (actionCreator) {
1752 return bindActionCreator(actionCreator, dispatch);
1753 });
1754}
1755
1756module.exports = exports['default'];
1757},{"./mapValues":40}],37:[function(require,module,exports){
1758(function (process){
1759'use strict';
1760
1761exports.__esModule = true;
1762exports['default'] = combineReducers;
1763
1764function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }
1765
1766var _createStore = require('../createStore');
1767
1768var _isPlainObject = require('./isPlainObject');
1769
1770var _isPlainObject2 = _interopRequireDefault(_isPlainObject);
1771
1772var _mapValues = require('./mapValues');
1773
1774var _mapValues2 = _interopRequireDefault(_mapValues);
1775
1776var _pick = require('./pick');
1777
1778var _pick2 = _interopRequireDefault(_pick);
1779
1780/* eslint-disable no-console */
1781
1782function getUndefinedStateErrorMessage(key, action) {
1783 var actionType = action && action.type;
1784 var actionName = actionType && '"' + actionType.toString() + '"' || 'an action';
1785
1786 return 'Reducer "' + key + '" returned undefined handling ' + actionName + '. ' + 'To ignore an action, you must explicitly return the previous state.';
1787}
1788
1789function getUnexpectedStateKeyWarningMessage(inputState, outputState, action) {
1790 var reducerKeys = Object.keys(outputState);
1791 var argumentName = action && action.type === _createStore.ActionTypes.INIT ? 'initialState argument passed to createStore' : 'previous state received by the reducer';
1792
1793 if (reducerKeys.length === 0) {
1794 return 'Store does not have a valid reducer. Make sure the argument passed ' + 'to combineReducers is an object whose values are reducers.';
1795 }
1796
1797 if (!_isPlainObject2['default'](inputState)) {
1798 return 'The ' + argumentName + ' has unexpected type of "' + ({}).toString.call(inputState).match(/\s([a-z|A-Z]+)/)[1] + '". Expected argument to be an object with the following ' + ('keys: "' + reducerKeys.join('", "') + '"');
1799 }
1800
1801 var unexpectedKeys = Object.keys(inputState).filter(function (key) {
1802 return reducerKeys.indexOf(key) < 0;
1803 });
1804
1805 if (unexpectedKeys.length > 0) {
1806 return 'Unexpected ' + (unexpectedKeys.length > 1 ? 'keys' : 'key') + ' ' + ('"' + unexpectedKeys.join('", "') + '" found in ' + argumentName + '. ') + 'Expected to find one of the known reducer keys instead: ' + ('"' + reducerKeys.join('", "') + '". Unexpected keys will be ignored.');
1807 }
1808}
1809
1810function assertReducerSanity(reducers) {
1811 Object.keys(reducers).forEach(function (key) {
1812 var reducer = reducers[key];
1813 var initialState = reducer(undefined, { type: _createStore.ActionTypes.INIT });
1814
1815 if (typeof initialState === 'undefined') {
1816 throw new Error('Reducer "' + key + '" returned undefined during initialization. ' + 'If the state passed to the reducer is undefined, you must ' + 'explicitly return the initial state. The initial state may ' + 'not be undefined.');
1817 }
1818
1819 var type = '@@redux/PROBE_UNKNOWN_ACTION_' + Math.random().toString(36).substring(7).split('').join('.');
1820 if (typeof reducer(undefined, { type: type }) === 'undefined') {
1821 throw new Error('Reducer "' + key + '" returned undefined when probed with a random type. ' + ('Don\'t try to handle ' + _createStore.ActionTypes.INIT + ' or other actions in "redux/*" ') + 'namespace. They are considered private. Instead, you must return the ' + 'current state for any unknown actions, unless it is undefined, ' + 'in which case you must return the initial state, regardless of the ' + 'action type. The initial state may not be undefined.');
1822 }
1823 });
1824}
1825
1826/**
1827 * Turns an object whose values are different reducer functions, into a single
1828 * reducer function. It will call every child reducer, and gather their results
1829 * into a single state object, whose keys correspond to the keys of the passed
1830 * reducer functions.
1831 *
1832 * @param {Object} reducers An object whose values correspond to different
1833 * reducer functions that need to be combined into one. One handy way to obtain
1834 * it is to use ES6 `import * as reducers` syntax. The reducers may never return
1835 * undefined for any action. Instead, they should return their initial state
1836 * if the state passed to them was undefined, and the current state for any
1837 * unrecognized action.
1838 *
1839 * @returns {Function} A reducer function that invokes every reducer inside the
1840 * passed object, and builds a state object with the same shape.
1841 */
1842
1843function combineReducers(reducers) {
1844 var finalReducers = _pick2['default'](reducers, function (val) {
1845 return typeof val === 'function';
1846 });
1847 var sanityError;
1848
1849 try {
1850 assertReducerSanity(finalReducers);
1851 } catch (e) {
1852 sanityError = e;
1853 }
1854
1855 var defaultState = _mapValues2['default'](finalReducers, function () {
1856 return undefined;
1857 });
1858
1859 return function combination(state, action) {
1860 if (state === undefined) state = defaultState;
1861
1862 if (sanityError) {
1863 throw sanityError;
1864 }
1865
1866 var hasChanged = false;
1867 var finalState = _mapValues2['default'](finalReducers, function (reducer, key) {
1868 var previousStateForKey = state[key];
1869 var nextStateForKey = reducer(previousStateForKey, action);
1870 if (typeof nextStateForKey === 'undefined') {
1871 var errorMessage = getUndefinedStateErrorMessage(key, action);
1872 throw new Error(errorMessage);
1873 }
1874 hasChanged = hasChanged || nextStateForKey !== previousStateForKey;
1875 return nextStateForKey;
1876 });
1877
1878 if (process.env.NODE_ENV !== 'production') {
1879 var warningMessage = getUnexpectedStateKeyWarningMessage(state, finalState, action);
1880 if (warningMessage) {
1881 console.error(warningMessage);
1882 }
1883 }
1884
1885 return hasChanged ? finalState : state;
1886 };
1887}
1888
1889module.exports = exports['default'];
1890}).call(this,require('_process'))
1891
1892},{"../createStore":33,"./isPlainObject":39,"./mapValues":40,"./pick":41,"_process":6}],38:[function(require,module,exports){
1893/**
1894 * Composes single-argument functions from right to left.
1895 *
1896 * @param {...Function} funcs The functions to compose.
1897 * @returns {Function} A function obtained by composing functions from right to
1898 * left. For example, compose(f, g, h) is identical to arg => f(g(h(arg))).
1899 */
1900"use strict";
1901
1902exports.__esModule = true;
1903exports["default"] = compose;
1904
1905function compose() {
1906 for (var _len = arguments.length, funcs = Array(_len), _key = 0; _key < _len; _key++) {
1907 funcs[_key] = arguments[_key];
1908 }
1909
1910 return function (arg) {
1911 return funcs.reduceRight(function (composed, f) {
1912 return f(composed);
1913 }, arg);
1914 };
1915}
1916
1917module.exports = exports["default"];
1918},{}],39:[function(require,module,exports){
1919'use strict';
1920
1921exports.__esModule = true;
1922exports['default'] = isPlainObject;
1923var fnToString = function fnToString(fn) {
1924 return Function.prototype.toString.call(fn);
1925};
1926var objStringValue = fnToString(Object);
1927
1928/**
1929 * @param {any} obj The object to inspect.
1930 * @returns {boolean} True if the argument appears to be a plain object.
1931 */
1932
1933function isPlainObject(obj) {
1934 if (!obj || typeof obj !== 'object') {
1935 return false;
1936 }
1937
1938 var proto = typeof obj.constructor === 'function' ? Object.getPrototypeOf(obj) : Object.prototype;
1939
1940 if (proto === null) {
1941 return true;
1942 }
1943
1944 var constructor = proto.constructor;
1945
1946 return typeof constructor === 'function' && constructor instanceof constructor && fnToString(constructor) === objStringValue;
1947}
1948
1949module.exports = exports['default'];
1950},{}],40:[function(require,module,exports){
1951/**
1952 * Applies a function to every key-value pair inside an object.
1953 *
1954 * @param {Object} obj The source object.
1955 * @param {Function} fn The mapper function that receives the value and the key.
1956 * @returns {Object} A new object that contains the mapped values for the keys.
1957 */
1958"use strict";
1959
1960exports.__esModule = true;
1961exports["default"] = mapValues;
1962
1963function mapValues(obj, fn) {
1964 return Object.keys(obj).reduce(function (result, key) {
1965 result[key] = fn(obj[key], key);
1966 return result;
1967 }, {});
1968}
1969
1970module.exports = exports["default"];
1971},{}],41:[function(require,module,exports){
1972/**
1973 * Picks key-value pairs from an object where values satisfy a predicate.
1974 *
1975 * @param {Object} obj The object to pick from.
1976 * @param {Function} fn The predicate the values must satisfy to be copied.
1977 * @returns {Object} The object with the values that satisfied the predicate.
1978 */
1979"use strict";
1980
1981exports.__esModule = true;
1982exports["default"] = pick;
1983
1984function pick(obj, fn) {
1985 return Object.keys(obj).reduce(function (result, key) {
1986 if (fn(obj[key])) {
1987 result[key] = obj[key];
1988 }
1989 return result;
1990 }, {});
1991}
1992
1993module.exports = exports["default"];
1994},{}],42:[function(require,module,exports){
1995var createElement = require("./vdom/create-element.js")
1996
1997module.exports = createElement
1998
1999},{"./vdom/create-element.js":46}],43:[function(require,module,exports){
2000var diff = require("./vtree/diff.js")
2001
2002module.exports = diff
2003
2004},{"./vtree/diff.js":60}],44:[function(require,module,exports){
2005var patch = require("./vdom/patch.js")
2006
2007module.exports = patch
2008
2009},{"./vdom/patch.js":49}],45:[function(require,module,exports){
2010var isObject = require("is-object")
2011var isHook = require("../vnode/is-vhook.js")
2012
2013module.exports = applyProperties
2014
2015function applyProperties(node, props, previous) {
2016 for (var propName in props) {
2017 var propValue = props[propName]
2018
2019 if (propValue === undefined) {
2020 removeProperty(node, propName, propValue, previous);
2021 } else if (isHook(propValue)) {
2022 removeProperty(node, propName, propValue, previous)
2023 if (propValue.hook) {
2024 propValue.hook(node,
2025 propName,
2026 previous ? previous[propName] : undefined)
2027 }
2028 } else {
2029 if (isObject(propValue)) {
2030 patchObject(node, props, previous, propName, propValue);
2031 } else {
2032 node[propName] = propValue
2033 }
2034 }
2035 }
2036}
2037
2038function removeProperty(node, propName, propValue, previous) {
2039 if (previous) {
2040 var previousValue = previous[propName]
2041
2042 if (!isHook(previousValue)) {
2043 if (propName === "attributes") {
2044 for (var attrName in previousValue) {
2045 node.removeAttribute(attrName)
2046 }
2047 } else if (propName === "style") {
2048 for (var i in previousValue) {
2049 node.style[i] = ""
2050 }
2051 } else if (typeof previousValue === "string") {
2052 node[propName] = ""
2053 } else {
2054 node[propName] = null
2055 }
2056 } else if (previousValue.unhook) {
2057 previousValue.unhook(node, propName, propValue)
2058 }
2059 }
2060}
2061
2062function patchObject(node, props, previous, propName, propValue) {
2063 var previousValue = previous ? previous[propName] : undefined
2064
2065 // Set attributes
2066 if (propName === "attributes") {
2067 for (var attrName in propValue) {
2068 var attrValue = propValue[attrName]
2069
2070 if (attrValue === undefined) {
2071 node.removeAttribute(attrName)
2072 } else {
2073 node.setAttribute(attrName, attrValue)
2074 }
2075 }
2076
2077 return
2078 }
2079
2080 if(previousValue && isObject(previousValue) &&
2081 getPrototype(previousValue) !== getPrototype(propValue)) {
2082 node[propName] = propValue
2083 return
2084 }
2085
2086 if (!isObject(node[propName])) {
2087 node[propName] = {}
2088 }
2089
2090 var replacer = propName === "style" ? "" : undefined
2091
2092 for (var k in propValue) {
2093 var value = propValue[k]
2094 node[propName][k] = (value === undefined) ? replacer : value
2095 }
2096}
2097
2098function getPrototype(value) {
2099 if (Object.getPrototypeOf) {
2100 return Object.getPrototypeOf(value)
2101 } else if (value.__proto__) {
2102 return value.__proto__
2103 } else if (value.constructor) {
2104 return value.constructor.prototype
2105 }
2106}
2107
2108},{"../vnode/is-vhook.js":53,"is-object":19}],46:[function(require,module,exports){
2109var document = require("global/document")
2110
2111var applyProperties = require("./apply-properties")
2112
2113var isVNode = require("../vnode/is-vnode.js")
2114var isVText = require("../vnode/is-vtext.js")
2115var isWidget = require("../vnode/is-widget.js")
2116var handleThunk = require("../vnode/handle-thunk.js")
2117
2118module.exports = createElement
2119
2120function createElement(vnode, opts) {
2121 var doc = opts ? opts.document || document : document
2122 var warn = opts ? opts.warn : null
2123
2124 vnode = handleThunk(vnode).a
2125
2126 if (isWidget(vnode)) {
2127 return vnode.init()
2128 } else if (isVText(vnode)) {
2129 return doc.createTextNode(vnode.text)
2130 } else if (!isVNode(vnode)) {
2131 if (warn) {
2132 warn("Item is not a valid virtual dom node", vnode)
2133 }
2134 return null
2135 }
2136
2137 var node = (vnode.namespace === null) ?
2138 doc.createElement(vnode.tagName) :
2139 doc.createElementNS(vnode.namespace, vnode.tagName)
2140
2141 var props = vnode.properties
2142 applyProperties(node, props)
2143
2144 var children = vnode.children
2145
2146 for (var i = 0; i < children.length; i++) {
2147 var childNode = createElement(children[i], opts)
2148 if (childNode) {
2149 node.appendChild(childNode)
2150 }
2151 }
2152
2153 return node
2154}
2155
2156},{"../vnode/handle-thunk.js":51,"../vnode/is-vnode.js":54,"../vnode/is-vtext.js":55,"../vnode/is-widget.js":56,"./apply-properties":45,"global/document":15}],47:[function(require,module,exports){
2157// Maps a virtual DOM tree onto a real DOM tree in an efficient manner.
2158// We don't want to read all of the DOM nodes in the tree so we use
2159// the in-order tree indexing to eliminate recursion down certain branches.
2160// We only recurse into a DOM node if we know that it contains a child of
2161// interest.
2162
2163var noChild = {}
2164
2165module.exports = domIndex
2166
2167function domIndex(rootNode, tree, indices, nodes) {
2168 if (!indices || indices.length === 0) {
2169 return {}
2170 } else {
2171 indices.sort(ascending)
2172 return recurse(rootNode, tree, indices, nodes, 0)
2173 }
2174}
2175
2176function recurse(rootNode, tree, indices, nodes, rootIndex) {
2177 nodes = nodes || {}
2178
2179
2180 if (rootNode) {
2181 if (indexInRange(indices, rootIndex, rootIndex)) {
2182 nodes[rootIndex] = rootNode
2183 }
2184
2185 var vChildren = tree.children
2186
2187 if (vChildren) {
2188
2189 var childNodes = rootNode.childNodes
2190
2191 for (var i = 0; i < tree.children.length; i++) {
2192 rootIndex += 1
2193
2194 var vChild = vChildren[i] || noChild
2195 var nextIndex = rootIndex + (vChild.count || 0)
2196
2197 // skip recursion down the tree if there are no nodes down here
2198 if (indexInRange(indices, rootIndex, nextIndex)) {
2199 recurse(childNodes[i], vChild, indices, nodes, rootIndex)
2200 }
2201
2202 rootIndex = nextIndex
2203 }
2204 }
2205 }
2206
2207 return nodes
2208}
2209
2210// Binary search for an index in the interval [left, right]
2211function indexInRange(indices, left, right) {
2212 if (indices.length === 0) {
2213 return false
2214 }
2215
2216 var minIndex = 0
2217 var maxIndex = indices.length - 1
2218 var currentIndex
2219 var currentItem
2220
2221 while (minIndex <= maxIndex) {
2222 currentIndex = ((maxIndex + minIndex) / 2) >> 0
2223 currentItem = indices[currentIndex]
2224
2225 if (minIndex === maxIndex) {
2226 return currentItem >= left && currentItem <= right
2227 } else if (currentItem < left) {
2228 minIndex = currentIndex + 1
2229 } else if (currentItem > right) {
2230 maxIndex = currentIndex - 1
2231 } else {
2232 return true
2233 }
2234 }
2235
2236 return false;
2237}
2238
2239function ascending(a, b) {
2240 return a > b ? 1 : -1
2241}
2242
2243},{}],48:[function(require,module,exports){
2244var applyProperties = require("./apply-properties")
2245
2246var isWidget = require("../vnode/is-widget.js")
2247var VPatch = require("../vnode/vpatch.js")
2248
2249var updateWidget = require("./update-widget")
2250
2251module.exports = applyPatch
2252
2253function applyPatch(vpatch, domNode, renderOptions) {
2254 var type = vpatch.type
2255 var vNode = vpatch.vNode
2256 var patch = vpatch.patch
2257
2258 switch (type) {
2259 case VPatch.REMOVE:
2260 return removeNode(domNode, vNode)
2261 case VPatch.INSERT:
2262 return insertNode(domNode, patch, renderOptions)
2263 case VPatch.VTEXT:
2264 return stringPatch(domNode, vNode, patch, renderOptions)
2265 case VPatch.WIDGET:
2266 return widgetPatch(domNode, vNode, patch, renderOptions)
2267 case VPatch.VNODE:
2268 return vNodePatch(domNode, vNode, patch, renderOptions)
2269 case VPatch.ORDER:
2270 reorderChildren(domNode, patch)
2271 return domNode
2272 case VPatch.PROPS:
2273 applyProperties(domNode, patch, vNode.properties)
2274 return domNode
2275 case VPatch.THUNK:
2276 return replaceRoot(domNode,
2277 renderOptions.patch(domNode, patch, renderOptions))
2278 default:
2279 return domNode
2280 }
2281}
2282
2283function removeNode(domNode, vNode) {
2284 var parentNode = domNode.parentNode
2285
2286 if (parentNode) {
2287 parentNode.removeChild(domNode)
2288 }
2289
2290 destroyWidget(domNode, vNode);
2291
2292 return null
2293}
2294
2295function insertNode(parentNode, vNode, renderOptions) {
2296 var newNode = renderOptions.render(vNode, renderOptions)
2297
2298 if (parentNode) {
2299 parentNode.appendChild(newNode)
2300 }
2301
2302 return parentNode
2303}
2304
2305function stringPatch(domNode, leftVNode, vText, renderOptions) {
2306 var newNode
2307
2308 if (domNode.nodeType === 3) {
2309 domNode.replaceData(0, domNode.length, vText.text)
2310 newNode = domNode
2311 } else {
2312 var parentNode = domNode.parentNode
2313 newNode = renderOptions.render(vText, renderOptions)
2314
2315 if (parentNode && newNode !== domNode) {
2316 parentNode.replaceChild(newNode, domNode)
2317 }
2318 }
2319
2320 return newNode
2321}
2322
2323function widgetPatch(domNode, leftVNode, widget, renderOptions) {
2324 var updating = updateWidget(leftVNode, widget)
2325 var newNode
2326
2327 if (updating) {
2328 newNode = widget.update(leftVNode, domNode) || domNode
2329 } else {
2330 newNode = renderOptions.render(widget, renderOptions)
2331 }
2332
2333 var parentNode = domNode.parentNode
2334
2335 if (parentNode && newNode !== domNode) {
2336 parentNode.replaceChild(newNode, domNode)
2337 }
2338
2339 if (!updating) {
2340 destroyWidget(domNode, leftVNode)
2341 }
2342
2343 return newNode
2344}
2345
2346function vNodePatch(domNode, leftVNode, vNode, renderOptions) {
2347 var parentNode = domNode.parentNode
2348 var newNode = renderOptions.render(vNode, renderOptions)
2349
2350 if (parentNode && newNode !== domNode) {
2351 parentNode.replaceChild(newNode, domNode)
2352 }
2353
2354 return newNode
2355}
2356
2357function destroyWidget(domNode, w) {
2358 if (typeof w.destroy === "function" && isWidget(w)) {
2359 w.destroy(domNode)
2360 }
2361}
2362
2363function reorderChildren(domNode, moves) {
2364 var childNodes = domNode.childNodes
2365 var keyMap = {}
2366 var node
2367 var remove
2368 var insert
2369
2370 for (var i = 0; i < moves.removes.length; i++) {
2371 remove = moves.removes[i]
2372 node = childNodes[remove.from]
2373 if (remove.key) {
2374 keyMap[remove.key] = node
2375 }
2376 domNode.removeChild(node)
2377 }
2378
2379 var length = childNodes.length
2380 for (var j = 0; j < moves.inserts.length; j++) {
2381 insert = moves.inserts[j]
2382 node = keyMap[insert.key]
2383 // this is the weirdest bug i've ever seen in webkit
2384 domNode.insertBefore(node, insert.to >= length++ ? null : childNodes[insert.to])
2385 }
2386}
2387
2388function replaceRoot(oldRoot, newRoot) {
2389 if (oldRoot && newRoot && oldRoot !== newRoot && oldRoot.parentNode) {
2390 oldRoot.parentNode.replaceChild(newRoot, oldRoot)
2391 }
2392
2393 return newRoot;
2394}
2395
2396},{"../vnode/is-widget.js":56,"../vnode/vpatch.js":58,"./apply-properties":45,"./update-widget":50}],49:[function(require,module,exports){
2397var document = require("global/document")
2398var isArray = require("x-is-array")
2399
2400var render = require("./create-element")
2401var domIndex = require("./dom-index")
2402var patchOp = require("./patch-op")
2403module.exports = patch
2404
2405function patch(rootNode, patches, renderOptions) {
2406 renderOptions = renderOptions || {}
2407 renderOptions.patch = renderOptions.patch && renderOptions.patch !== patch
2408 ? renderOptions.patch
2409 : patchRecursive
2410 renderOptions.render = renderOptions.render || render
2411
2412 return renderOptions.patch(rootNode, patches, renderOptions)
2413}
2414
2415function patchRecursive(rootNode, patches, renderOptions) {
2416 var indices = patchIndices(patches)
2417
2418 if (indices.length === 0) {
2419 return rootNode
2420 }
2421
2422 var index = domIndex(rootNode, patches.a, indices)
2423 var ownerDocument = rootNode.ownerDocument
2424
2425 if (!renderOptions.document && ownerDocument !== document) {
2426 renderOptions.document = ownerDocument
2427 }
2428
2429 for (var i = 0; i < indices.length; i++) {
2430 var nodeIndex = indices[i]
2431 rootNode = applyPatch(rootNode,
2432 index[nodeIndex],
2433 patches[nodeIndex],
2434 renderOptions)
2435 }
2436
2437 return rootNode
2438}
2439
2440function applyPatch(rootNode, domNode, patchList, renderOptions) {
2441 if (!domNode) {
2442 return rootNode
2443 }
2444
2445 var newNode
2446
2447 if (isArray(patchList)) {
2448 for (var i = 0; i < patchList.length; i++) {
2449 newNode = patchOp(patchList[i], domNode, renderOptions)
2450
2451 if (domNode === rootNode) {
2452 rootNode = newNode
2453 }
2454 }
2455 } else {
2456 newNode = patchOp(patchList, domNode, renderOptions)
2457
2458 if (domNode === rootNode) {
2459 rootNode = newNode
2460 }
2461 }
2462
2463 return rootNode
2464}
2465
2466function patchIndices(patches) {
2467 var indices = []
2468
2469 for (var key in patches) {
2470 if (key !== "a") {
2471 indices.push(Number(key))
2472 }
2473 }
2474
2475 return indices
2476}
2477
2478},{"./create-element":46,"./dom-index":47,"./patch-op":48,"global/document":15,"x-is-array":63}],50:[function(require,module,exports){
2479var isWidget = require("../vnode/is-widget.js")
2480
2481module.exports = updateWidget
2482
2483function updateWidget(a, b) {
2484 if (isWidget(a) && isWidget(b)) {
2485 if ("name" in a && "name" in b) {
2486 return a.id === b.id
2487 } else {
2488 return a.init === b.init
2489 }
2490 }
2491
2492 return false
2493}
2494
2495},{"../vnode/is-widget.js":56}],51:[function(require,module,exports){
2496var isVNode = require("./is-vnode")
2497var isVText = require("./is-vtext")
2498var isWidget = require("./is-widget")
2499var isThunk = require("./is-thunk")
2500
2501module.exports = handleThunk
2502
2503function handleThunk(a, b) {
2504 var renderedA = a
2505 var renderedB = b
2506
2507 if (isThunk(b)) {
2508 renderedB = renderThunk(b, a)
2509 }
2510
2511 if (isThunk(a)) {
2512 renderedA = renderThunk(a, null)
2513 }
2514
2515 return {
2516 a: renderedA,
2517 b: renderedB
2518 }
2519}
2520
2521function renderThunk(thunk, previous) {
2522 var renderedThunk = thunk.vnode
2523
2524 if (!renderedThunk) {
2525 renderedThunk = thunk.vnode = thunk.render(previous)
2526 }
2527
2528 if (!(isVNode(renderedThunk) ||
2529 isVText(renderedThunk) ||
2530 isWidget(renderedThunk))) {
2531 throw new Error("thunk did not return a valid node");
2532 }
2533
2534 return renderedThunk
2535}
2536
2537},{"./is-thunk":52,"./is-vnode":54,"./is-vtext":55,"./is-widget":56}],52:[function(require,module,exports){
2538module.exports = isThunk
2539
2540function isThunk(t) {
2541 return t && t.type === "Thunk"
2542}
2543
2544},{}],53:[function(require,module,exports){
2545module.exports = isHook
2546
2547function isHook(hook) {
2548 return hook &&
2549 (typeof hook.hook === "function" && !hook.hasOwnProperty("hook") ||
2550 typeof hook.unhook === "function" && !hook.hasOwnProperty("unhook"))
2551}
2552
2553},{}],54:[function(require,module,exports){
2554var version = require("./version")
2555
2556module.exports = isVirtualNode
2557
2558function isVirtualNode(x) {
2559 return x && x.type === "VirtualNode" && x.version === version
2560}
2561
2562},{"./version":57}],55:[function(require,module,exports){
2563var version = require("./version")
2564
2565module.exports = isVirtualText
2566
2567function isVirtualText(x) {
2568 return x && x.type === "VirtualText" && x.version === version
2569}
2570
2571},{"./version":57}],56:[function(require,module,exports){
2572module.exports = isWidget
2573
2574function isWidget(w) {
2575 return w && w.type === "Widget"
2576}
2577
2578},{}],57:[function(require,module,exports){
2579module.exports = "2"
2580
2581},{}],58:[function(require,module,exports){
2582var version = require("./version")
2583
2584VirtualPatch.NONE = 0
2585VirtualPatch.VTEXT = 1
2586VirtualPatch.VNODE = 2
2587VirtualPatch.WIDGET = 3
2588VirtualPatch.PROPS = 4
2589VirtualPatch.ORDER = 5
2590VirtualPatch.INSERT = 6
2591VirtualPatch.REMOVE = 7
2592VirtualPatch.THUNK = 8
2593
2594module.exports = VirtualPatch
2595
2596function VirtualPatch(type, vNode, patch) {
2597 this.type = Number(type)
2598 this.vNode = vNode
2599 this.patch = patch
2600}
2601
2602VirtualPatch.prototype.version = version
2603VirtualPatch.prototype.type = "VirtualPatch"
2604
2605},{"./version":57}],59:[function(require,module,exports){
2606var isObject = require("is-object")
2607var isHook = require("../vnode/is-vhook")
2608
2609module.exports = diffProps
2610
2611function diffProps(a, b) {
2612 var diff
2613
2614 for (var aKey in a) {
2615 if (!(aKey in b)) {
2616 diff = diff || {}
2617 diff[aKey] = undefined
2618 }
2619
2620 var aValue = a[aKey]
2621 var bValue = b[aKey]
2622
2623 if (aValue === bValue) {
2624 continue
2625 } else if (isObject(aValue) && isObject(bValue)) {
2626 if (getPrototype(bValue) !== getPrototype(aValue)) {
2627 diff = diff || {}
2628 diff[aKey] = bValue
2629 } else if (isHook(bValue)) {
2630 diff = diff || {}
2631 diff[aKey] = bValue
2632 } else {
2633 var objectDiff = diffProps(aValue, bValue)
2634 if (objectDiff) {
2635 diff = diff || {}
2636 diff[aKey] = objectDiff
2637 }
2638 }
2639 } else {
2640 diff = diff || {}
2641 diff[aKey] = bValue
2642 }
2643 }
2644
2645 for (var bKey in b) {
2646 if (!(bKey in a)) {
2647 diff = diff || {}
2648 diff[bKey] = b[bKey]
2649 }
2650 }
2651
2652 return diff
2653}
2654
2655function getPrototype(value) {
2656 if (Object.getPrototypeOf) {
2657 return Object.getPrototypeOf(value)
2658 } else if (value.__proto__) {
2659 return value.__proto__
2660 } else if (value.constructor) {
2661 return value.constructor.prototype
2662 }
2663}
2664
2665},{"../vnode/is-vhook":53,"is-object":19}],60:[function(require,module,exports){
2666var isArray = require("x-is-array")
2667
2668var VPatch = require("../vnode/vpatch")
2669var isVNode = require("../vnode/is-vnode")
2670var isVText = require("../vnode/is-vtext")
2671var isWidget = require("../vnode/is-widget")
2672var isThunk = require("../vnode/is-thunk")
2673var handleThunk = require("../vnode/handle-thunk")
2674
2675var diffProps = require("./diff-props")
2676
2677module.exports = diff
2678
2679function diff(a, b) {
2680 var patch = { a: a }
2681 walk(a, b, patch, 0)
2682 return patch
2683}
2684
2685function walk(a, b, patch, index) {
2686 if (a === b) {
2687 return
2688 }
2689
2690 var apply = patch[index]
2691 var applyClear = false
2692
2693 if (isThunk(a) || isThunk(b)) {
2694 thunks(a, b, patch, index)
2695 } else if (b == null) {
2696
2697 // If a is a widget we will add a remove patch for it
2698 // Otherwise any child widgets/hooks must be destroyed.
2699 // This prevents adding two remove patches for a widget.
2700 if (!isWidget(a)) {
2701 clearState(a, patch, index)
2702 apply = patch[index]
2703 }
2704
2705 apply = appendPatch(apply, new VPatch(VPatch.REMOVE, a, b))
2706 } else if (isVNode(b)) {
2707 if (isVNode(a)) {
2708 if (a.tagName === b.tagName &&
2709 a.namespace === b.namespace &&
2710 a.key === b.key) {
2711 var propsPatch = diffProps(a.properties, b.properties)
2712 if (propsPatch) {
2713 apply = appendPatch(apply,
2714 new VPatch(VPatch.PROPS, a, propsPatch))
2715 }
2716 apply = diffChildren(a, b, patch, apply, index)
2717 } else {
2718 apply = appendPatch(apply, new VPatch(VPatch.VNODE, a, b))
2719 applyClear = true
2720 }
2721 } else {
2722 apply = appendPatch(apply, new VPatch(VPatch.VNODE, a, b))
2723 applyClear = true
2724 }
2725 } else if (isVText(b)) {
2726 if (!isVText(a)) {
2727 apply = appendPatch(apply, new VPatch(VPatch.VTEXT, a, b))
2728 applyClear = true
2729 } else if (a.text !== b.text) {
2730 apply = appendPatch(apply, new VPatch(VPatch.VTEXT, a, b))
2731 }
2732 } else if (isWidget(b)) {
2733 if (!isWidget(a)) {
2734 applyClear = true
2735 }
2736
2737 apply = appendPatch(apply, new VPatch(VPatch.WIDGET, a, b))
2738 }
2739
2740 if (apply) {
2741 patch[index] = apply
2742 }
2743
2744 if (applyClear) {
2745 clearState(a, patch, index)
2746 }
2747}
2748
2749function diffChildren(a, b, patch, apply, index) {
2750 var aChildren = a.children
2751 var orderedSet = reorder(aChildren, b.children)
2752 var bChildren = orderedSet.children
2753
2754 var aLen = aChildren.length
2755 var bLen = bChildren.length
2756 var len = aLen > bLen ? aLen : bLen
2757
2758 for (var i = 0; i < len; i++) {
2759 var leftNode = aChildren[i]
2760 var rightNode = bChildren[i]
2761 index += 1
2762
2763 if (!leftNode) {
2764 if (rightNode) {
2765 // Excess nodes in b need to be added
2766 apply = appendPatch(apply,
2767 new VPatch(VPatch.INSERT, null, rightNode))
2768 }
2769 } else {
2770 walk(leftNode, rightNode, patch, index)
2771 }
2772
2773 if (isVNode(leftNode) && leftNode.count) {
2774 index += leftNode.count
2775 }
2776 }
2777
2778 if (orderedSet.moves) {
2779 // Reorder nodes last
2780 apply = appendPatch(apply, new VPatch(
2781 VPatch.ORDER,
2782 a,
2783 orderedSet.moves
2784 ))
2785 }
2786
2787 return apply
2788}
2789
2790function clearState(vNode, patch, index) {
2791 // TODO: Make this a single walk, not two
2792 unhook(vNode, patch, index)
2793 destroyWidgets(vNode, patch, index)
2794}
2795
2796// Patch records for all destroyed widgets must be added because we need
2797// a DOM node reference for the destroy function
2798function destroyWidgets(vNode, patch, index) {
2799 if (isWidget(vNode)) {
2800 if (typeof vNode.destroy === "function") {
2801 patch[index] = appendPatch(
2802 patch[index],
2803 new VPatch(VPatch.REMOVE, vNode, null)
2804 )
2805 }
2806 } else if (isVNode(vNode) && (vNode.hasWidgets || vNode.hasThunks)) {
2807 var children = vNode.children
2808 var len = children.length
2809 for (var i = 0; i < len; i++) {
2810 var child = children[i]
2811 index += 1
2812
2813 destroyWidgets(child, patch, index)
2814
2815 if (isVNode(child) && child.count) {
2816 index += child.count
2817 }
2818 }
2819 } else if (isThunk(vNode)) {
2820 thunks(vNode, null, patch, index)
2821 }
2822}
2823
2824// Create a sub-patch for thunks
2825function thunks(a, b, patch, index) {
2826 var nodes = handleThunk(a, b)
2827 var thunkPatch = diff(nodes.a, nodes.b)
2828 if (hasPatches(thunkPatch)) {
2829 patch[index] = new VPatch(VPatch.THUNK, null, thunkPatch)
2830 }
2831}
2832
2833function hasPatches(patch) {
2834 for (var index in patch) {
2835 if (index !== "a") {
2836 return true
2837 }
2838 }
2839
2840 return false
2841}
2842
2843// Execute hooks when two nodes are identical
2844function unhook(vNode, patch, index) {
2845 if (isVNode(vNode)) {
2846 if (vNode.hooks) {
2847 patch[index] = appendPatch(
2848 patch[index],
2849 new VPatch(
2850 VPatch.PROPS,
2851 vNode,
2852 undefinedKeys(vNode.hooks)
2853 )
2854 )
2855 }
2856
2857 if (vNode.descendantHooks || vNode.hasThunks) {
2858 var children = vNode.children
2859 var len = children.length
2860 for (var i = 0; i < len; i++) {
2861 var child = children[i]
2862 index += 1
2863
2864 unhook(child, patch, index)
2865
2866 if (isVNode(child) && child.count) {
2867 index += child.count
2868 }
2869 }
2870 }
2871 } else if (isThunk(vNode)) {
2872 thunks(vNode, null, patch, index)
2873 }
2874}
2875
2876function undefinedKeys(obj) {
2877 var result = {}
2878
2879 for (var key in obj) {
2880 result[key] = undefined
2881 }
2882
2883 return result
2884}
2885
2886// List diff, naive left to right reordering
2887function reorder(aChildren, bChildren) {
2888 // O(M) time, O(M) memory
2889 var bChildIndex = keyIndex(bChildren)
2890 var bKeys = bChildIndex.keys
2891 var bFree = bChildIndex.free
2892
2893 if (bFree.length === bChildren.length) {
2894 return {
2895 children: bChildren,
2896 moves: null
2897 }
2898 }
2899
2900 // O(N) time, O(N) memory
2901 var aChildIndex = keyIndex(aChildren)
2902 var aKeys = aChildIndex.keys
2903 var aFree = aChildIndex.free
2904
2905 if (aFree.length === aChildren.length) {
2906 return {
2907 children: bChildren,
2908 moves: null
2909 }
2910 }
2911
2912 // O(MAX(N, M)) memory
2913 var newChildren = []
2914
2915 var freeIndex = 0
2916 var freeCount = bFree.length
2917 var deletedItems = 0
2918
2919 // Iterate through a and match a node in b
2920 // O(N) time,
2921 for (var i = 0 ; i < aChildren.length; i++) {
2922 var aItem = aChildren[i]
2923 var itemIndex
2924
2925 if (aItem.key) {
2926 if (bKeys.hasOwnProperty(aItem.key)) {
2927 // Match up the old keys
2928 itemIndex = bKeys[aItem.key]
2929 newChildren.push(bChildren[itemIndex])
2930
2931 } else {
2932 // Remove old keyed items
2933 itemIndex = i - deletedItems++
2934 newChildren.push(null)
2935 }
2936 } else {
2937 // Match the item in a with the next free item in b
2938 if (freeIndex < freeCount) {
2939 itemIndex = bFree[freeIndex++]
2940 newChildren.push(bChildren[itemIndex])
2941 } else {
2942 // There are no free items in b to match with
2943 // the free items in a, so the extra free nodes
2944 // are deleted.
2945 itemIndex = i - deletedItems++
2946 newChildren.push(null)
2947 }
2948 }
2949 }
2950
2951 var lastFreeIndex = freeIndex >= bFree.length ?
2952 bChildren.length :
2953 bFree[freeIndex]
2954
2955 // Iterate through b and append any new keys
2956 // O(M) time
2957 for (var j = 0; j < bChildren.length; j++) {
2958 var newItem = bChildren[j]
2959
2960 if (newItem.key) {
2961 if (!aKeys.hasOwnProperty(newItem.key)) {
2962 // Add any new keyed items
2963 // We are adding new items to the end and then sorting them
2964 // in place. In future we should insert new items in place.
2965 newChildren.push(newItem)
2966 }
2967 } else if (j >= lastFreeIndex) {
2968 // Add any leftover non-keyed items
2969 newChildren.push(newItem)
2970 }
2971 }
2972
2973 var simulate = newChildren.slice()
2974 var simulateIndex = 0
2975 var removes = []
2976 var inserts = []
2977 var simulateItem
2978
2979 for (var k = 0; k < bChildren.length;) {
2980 var wantedItem = bChildren[k]
2981 simulateItem = simulate[simulateIndex]
2982
2983 // remove items
2984 while (simulateItem === null && simulate.length) {
2985 removes.push(remove(simulate, simulateIndex, null))
2986 simulateItem = simulate[simulateIndex]
2987 }
2988
2989 if (!simulateItem || simulateItem.key !== wantedItem.key) {
2990 // if we need a key in this position...
2991 if (wantedItem.key) {
2992 if (simulateItem && simulateItem.key) {
2993 // if an insert doesn't put this key in place, it needs to move
2994 if (bKeys[simulateItem.key] !== k + 1) {
2995 removes.push(remove(simulate, simulateIndex, simulateItem.key))
2996 simulateItem = simulate[simulateIndex]
2997 // if the remove didn't put the wanted item in place, we need to insert it
2998 if (!simulateItem || simulateItem.key !== wantedItem.key) {
2999 inserts.push({key: wantedItem.key, to: k})
3000 }
3001 // items are matching, so skip ahead
3002 else {
3003 simulateIndex++
3004 }
3005 }
3006 else {
3007 inserts.push({key: wantedItem.key, to: k})
3008 }
3009 }
3010 else {
3011 inserts.push({key: wantedItem.key, to: k})
3012 }
3013 k++
3014 }
3015 // a key in simulate has no matching wanted key, remove it
3016 else if (simulateItem && simulateItem.key) {
3017 removes.push(remove(simulate, simulateIndex, simulateItem.key))
3018 }
3019 }
3020 else {
3021 simulateIndex++
3022 k++
3023 }
3024 }
3025
3026 // remove all the remaining nodes from simulate
3027 while(simulateIndex < simulate.length) {
3028 simulateItem = simulate[simulateIndex]
3029 removes.push(remove(simulate, simulateIndex, simulateItem && simulateItem.key))
3030 }
3031
3032 // If the only moves we have are deletes then we can just
3033 // let the delete patch remove these items.
3034 if (removes.length === deletedItems && !inserts.length) {
3035 return {
3036 children: newChildren,
3037 moves: null
3038 }
3039 }
3040
3041 return {
3042 children: newChildren,
3043 moves: {
3044 removes: removes,
3045 inserts: inserts
3046 }
3047 }
3048}
3049
3050function remove(arr, index, key) {
3051 arr.splice(index, 1)
3052
3053 return {
3054 from: index,
3055 key: key
3056 }
3057}
3058
3059function keyIndex(children) {
3060 var keys = {}
3061 var free = []
3062 var length = children.length
3063
3064 for (var i = 0; i < length; i++) {
3065 var child = children[i]
3066
3067 if (child.key) {
3068 keys[child.key] = i
3069 } else {
3070 free.push(i)
3071 }
3072 }
3073
3074 return {
3075 keys: keys, // A hash of key name to index
3076 free: free // An array of unkeyed item indices
3077 }
3078}
3079
3080function appendPatch(apply, patch) {
3081 if (apply) {
3082 if (isArray(apply)) {
3083 apply.push(patch)
3084 } else {
3085 apply = [apply, patch]
3086 }
3087
3088 return apply
3089 } else {
3090 return patch
3091 }
3092}
3093
3094},{"../vnode/handle-thunk":51,"../vnode/is-thunk":52,"../vnode/is-vnode":54,"../vnode/is-vtext":55,"../vnode/is-widget":56,"../vnode/vpatch":58,"./diff-props":59,"x-is-array":63}],61:[function(require,module,exports){
3095var hiddenStore = require('./hidden-store.js');
3096
3097module.exports = createStore;
3098
3099function createStore() {
3100 var key = {};
3101
3102 return function (obj) {
3103 if ((typeof obj !== 'object' || obj === null) &&
3104 typeof obj !== 'function'
3105 ) {
3106 throw new Error('Weakmap-shim: Key must be object')
3107 }
3108
3109 var store = obj.valueOf(key);
3110 return store && store.identity === key ?
3111 store : hiddenStore(obj, key);
3112 };
3113}
3114
3115},{"./hidden-store.js":62}],62:[function(require,module,exports){
3116module.exports = hiddenStore;
3117
3118function hiddenStore(obj, key) {
3119 var store = { identity: key };
3120 var valueOf = obj.valueOf;
3121
3122 Object.defineProperty(obj, "valueOf", {
3123 value: function (value) {
3124 return value !== key ?
3125 valueOf.apply(this, arguments) : store;
3126 },
3127 writable: true
3128 });
3129
3130 return store;
3131}
3132
3133},{}],63:[function(require,module,exports){
3134var nativeIsArray = Array.isArray
3135var toString = Object.prototype.toString
3136
3137module.exports = nativeIsArray || isArray
3138
3139function isArray(obj) {
3140 return toString.call(obj) === "[object Array]"
3141}
3142
3143},{}]},{},[3])(3)
3144});
3145
3146
3147//# sourceMappingURL=plait.js.map