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 |
|
4 | var _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 |
|
6 | Object.defineProperty(exports, "__esModule", {
|
7 | value: true
|
8 | });
|
9 | exports.forwardDispatch = undefined;
|
10 | exports.start = start;
|
11 | exports.initializeComponent = initializeComponent;
|
12 |
|
13 | var _curry = require('ramda/src/curry');
|
14 |
|
15 | var _curry2 = _interopRequireDefault(_curry);
|
16 |
|
17 | var _redux = require('redux');
|
18 |
|
19 | var _reduxThunk = require('redux-thunk');
|
20 |
|
21 | var _reduxThunk2 = _interopRequireDefault(_reduxThunk);
|
22 |
|
23 | var _diff = require('virtual-dom/diff');
|
24 |
|
25 | var _diff2 = _interopRequireDefault(_diff);
|
26 |
|
27 | var _patch = require('virtual-dom/patch');
|
28 |
|
29 | var _patch2 = _interopRequireDefault(_patch);
|
30 |
|
31 | var _createElement = require('virtual-dom/create-element');
|
32 |
|
33 | var _createElement2 = _interopRequireDefault(_createElement);
|
34 |
|
35 | var _domDelegator = require('dom-delegator');
|
36 |
|
37 | var _domDelegator2 = _interopRequireDefault(_domDelegator);
|
38 |
|
39 | var _Map = require('./Map');
|
40 |
|
41 | var _Map2 = _interopRequireDefault(_Map);
|
42 |
|
43 | function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
44 |
|
45 | var delegator = (0, _domDelegator2.default)();
|
46 | var createStoreWithMiddleware = (0, _redux.applyMiddleware)(_reduxThunk2.default)(_redux.createStore);
|
47 |
|
48 |
|
49 |
|
50 |
|
51 |
|
52 |
|
53 |
|
54 |
|
55 | function 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 |
|
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 |
|
107 | function patchTree(rootNode, oldTree, newTree) {
|
108 | (0, _patch2.default)(rootNode, (0, _diff2.default)(oldTree, newTree));
|
109 |
|
110 | return newTree;
|
111 | }
|
112 |
|
113 |
|
114 | function 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 |
|
132 | function 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 |
|
140 |
|
141 |
|
142 |
|
143 | var forwardDispatch = exports.forwardDispatch = (0, _curry2.default)(function (action, dispatch, state) {
|
144 | return function (forwardAction) {
|
145 | if (typeof forwardAction === 'function') {
|
146 |
|
147 |
|
148 |
|
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 |
|
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 |
|
166 | var _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 |
|
168 | Object.defineProperty(exports, "__esModule", {
|
169 | value: true
|
170 | });
|
171 |
|
172 | var _assocPath = require('ramda/src/assocPath');
|
173 |
|
174 | var _assocPath2 = _interopRequireDefault(_assocPath);
|
175 |
|
176 | var _clone = require('./utils/clone');
|
177 |
|
178 | var _clone2 = _interopRequireDefault(_clone);
|
179 |
|
180 | var _path = require('ramda/src/path');
|
181 |
|
182 | var _path2 = _interopRequireDefault(_path);
|
183 |
|
184 | function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
185 |
|
186 | function _typeof(obj) { return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj; }
|
187 |
|
188 | function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
189 |
|
190 | var 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 |
|
250 | exports.default = Map;
|
251 | },{"./utils/clone":4,"ramda/src/assocPath":21,"ramda/src/path":31}],3:[function(require,module,exports){
|
252 | 'use strict';
|
253 |
|
254 | Object.defineProperty(exports, "__esModule", {
|
255 | value: true
|
256 | });
|
257 | exports.Map = exports.App = undefined;
|
258 |
|
259 | var _App = require('./App');
|
260 |
|
261 | var App = _interopRequireWildcard(_App);
|
262 |
|
263 | var _Map = require('./Map');
|
264 |
|
265 | var _Map2 = _interopRequireDefault(_Map);
|
266 |
|
267 | function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
268 |
|
269 | function _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 |
|
271 | exports.App = App;
|
272 | exports.Map = _Map2.default;
|
273 | },{"./App":1,"./Map":2}],4:[function(require,module,exports){
|
274 | 'use strict';
|
275 |
|
276 | Object.defineProperty(exports, "__esModule", {
|
277 | value: true
|
278 | });
|
279 | exports.default = clone;
|
280 |
|
281 | function _typeof(obj) { return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj; }
|
282 |
|
283 | function 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 |
|
306 |
|
307 | var process = module.exports = {};
|
308 | var queue = [];
|
309 | var draining = false;
|
310 | var currentQueue;
|
311 | var queueIndex = -1;
|
312 |
|
313 | function 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 |
|
325 | function 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 |
|
349 | process.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 |
|
363 | function Item(fun, array) {
|
364 | this.fun = fun;
|
365 | this.array = array;
|
366 | }
|
367 | Item.prototype.run = function () {
|
368 | this.fun.apply(null, this.array);
|
369 | };
|
370 | process.title = 'browser';
|
371 | process.browser = true;
|
372 | process.env = {};
|
373 | process.argv = [];
|
374 | process.version = '';
|
375 | process.versions = {};
|
376 |
|
377 | function noop() {}
|
378 |
|
379 | process.on = noop;
|
380 | process.addListener = noop;
|
381 | process.once = noop;
|
382 | process.off = noop;
|
383 | process.removeListener = noop;
|
384 | process.removeAllListeners = noop;
|
385 | process.emit = noop;
|
386 |
|
387 | process.binding = function (name) {
|
388 | throw new Error('process.binding is not supported');
|
389 | };
|
390 |
|
391 | process.cwd = function () { return '/' };
|
392 | process.chdir = function (dir) {
|
393 | throw new Error('process.chdir is not supported');
|
394 | };
|
395 | process.umask = function() { return 0; };
|
396 |
|
397 | },{}],7:[function(require,module,exports){
|
398 |
|
399 |
|
400 |
|
401 |
|
402 |
|
403 |
|
404 |
|
405 |
|
406 |
|
407 |
|
408 |
|
409 |
|
410 |
|
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++;
|
433 | return c - 1;
|
434 | },
|
435 |
|
436 | api = function cuid() {
|
437 |
|
438 |
|
439 | var letter = 'c',
|
440 |
|
441 |
|
442 |
|
443 |
|
444 | timestamp = (new Date().getTime()).toString(base),
|
445 |
|
446 |
|
447 | counter,
|
448 |
|
449 |
|
450 |
|
451 |
|
452 | fingerprint = api.fingerprint(),
|
453 |
|
454 |
|
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 |
|
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 |
|
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){
|
510 | var EvStore = require("ev-store")
|
511 |
|
512 | module.exports = addEvent
|
513 |
|
514 | function 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){
|
530 | var globalDocument = require("global/document")
|
531 | var EvStore = require("ev-store")
|
532 | var createStore = require("weakmap-shim/create-store")
|
533 |
|
534 | var addEvent = require("./add-event.js")
|
535 | var removeEvent = require("./remove-event.js")
|
536 | var ProxyEvent = require("./proxy-event.js")
|
537 |
|
538 | var HANDLER_STORE = createStore()
|
539 |
|
540 | module.exports = DOMDelegator
|
541 |
|
542 | function 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 |
|
555 | DOMDelegator.prototype.addEventListener = addEvent
|
556 | DOMDelegator.prototype.removeEventListener = removeEvent
|
557 |
|
558 | DOMDelegator.allocateHandle =
|
559 | function allocateHandle(func) {
|
560 | var handle = new Handle()
|
561 |
|
562 | HANDLER_STORE(handle).func = func;
|
563 |
|
564 | return handle
|
565 | }
|
566 |
|
567 | DOMDelegator.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 |
|
576 | DOMDelegator.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 |
|
586 | DOMDelegator.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 |
|
596 | DOMDelegator.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 |
|
616 | DOMDelegator.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 |
|
641 | function 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 |
|
660 | function 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 |
|
675 | function getListener(target, type) {
|
676 |
|
677 | if (target === null || typeof target === "undefined") {
|
678 | return null
|
679 | }
|
680 |
|
681 | var events = EvStore(target)
|
682 |
|
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 |
|
694 | function 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 |
|
709 | function Listener(target, handlers) {
|
710 | this.currentTarget = target
|
711 | this.handlers = handlers
|
712 | }
|
713 |
|
714 | function 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){
|
719 | var Individual = require("individual")
|
720 | var cuid = require("cuid")
|
721 | var globalDocument = require("global/document")
|
722 |
|
723 | var DOMDelegator = require("./dom-delegator.js")
|
724 |
|
725 | var versionKey = "13"
|
726 | var cacheKey = "__DOM_DELEGATOR_CACHE@" + versionKey
|
727 | var cacheTokenKey = "__DOM_DELEGATOR_CACHE_TOKEN@" + versionKey
|
728 | var delegatorCache = Individual(cacheKey, {
|
729 | delegators: {}
|
730 | })
|
731 | var 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 |
|
740 |
|
741 |
|
742 |
|
743 |
|
744 |
|
745 |
|
746 |
|
747 |
|
748 | module.exports = Delegator
|
749 |
|
750 | function 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 |
|
777 | Delegator.allocateHandle = DOMDelegator.allocateHandle;
|
778 | Delegator.transformHandle = DOMDelegator.transformHandle;
|
779 |
|
780 | },{"./dom-delegator.js":9,"cuid":7,"global/document":15,"individual":11}],11:[function(require,module,exports){
|
781 | (function (global){
|
782 | var root = typeof window !== 'undefined' ?
|
783 | window : typeof global !== 'undefined' ?
|
784 | global : {};
|
785 |
|
786 | module.exports = Individual
|
787 |
|
788 | function 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){
|
804 | var inherits = require("inherits")
|
805 |
|
806 | var ALL_PROPS = [
|
807 | "altKey", "bubbles", "cancelable", "ctrlKey",
|
808 | "eventPhase", "metaKey", "relatedTarget", "shiftKey",
|
809 | "target", "timeStamp", "type", "view", "which"
|
810 | ]
|
811 | var KEY_PROPS = ["char", "charCode", "key", "keyCode"]
|
812 | var MOUSE_PROPS = [
|
813 | "button", "buttons", "clientX", "clientY", "layerX",
|
814 | "layerY", "offsetX", "offsetY", "pageX", "pageY",
|
815 | "screenX", "screenY", "toElement"
|
816 | ]
|
817 |
|
818 | var rkeyEvent = /^key|input/
|
819 | var rmouseEvent = /^(?:mouse|pointer|contextmenu)|click/
|
820 |
|
821 | module.exports = ProxyEvent
|
822 |
|
823 | function 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 |
|
843 | ProxyEvent.prototype.preventDefault = function () {
|
844 | this._rawEvent.preventDefault()
|
845 | }
|
846 |
|
847 | ProxyEvent.prototype.startPropagation = function () {
|
848 | this._bubbles = true;
|
849 | }
|
850 |
|
851 | function 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 |
|
865 | inherits(MouseEvent, ProxyEvent)
|
866 |
|
867 | function 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 |
|
881 | inherits(KeyEvent, ProxyEvent)
|
882 |
|
883 | },{"inherits":18}],13:[function(require,module,exports){
|
884 | var EvStore = require("ev-store")
|
885 |
|
886 | module.exports = removeEvent
|
887 |
|
888 | function 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 |
|
907 | var OneVersionConstraint = require('individual/one-version');
|
908 |
|
909 | var MY_VERSION = '7';
|
910 | OneVersionConstraint('ev-store', MY_VERSION);
|
911 |
|
912 | var hashKey = '__EV_STORE_KEY@' + MY_VERSION;
|
913 |
|
914 | module.exports = EvStore;
|
915 |
|
916 | function 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){
|
928 | var topLevel = typeof global !== 'undefined' ? global :
|
929 | typeof window !== 'undefined' ? window : {}
|
930 | var minDoc = require('min-document');
|
931 |
|
932 | if (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 |
|
951 |
|
952 | var root = typeof window !== 'undefined' ?
|
953 | window : typeof global !== 'undefined' ?
|
954 | global : {};
|
955 |
|
956 | module.exports = Individual;
|
957 |
|
958 | function 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 |
|
973 | var Individual = require('./index.js');
|
974 |
|
975 | module.exports = OneVersion;
|
976 |
|
977 | function 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){
|
995 | if (typeof Object.create === 'function') {
|
996 |
|
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 |
|
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 |
|
1022 | module.exports = function isObject(x) {
|
1023 | return typeof x === "object" && x !== null;
|
1024 | };
|
1025 |
|
1026 | },{}],20:[function(require,module,exports){
|
1027 | var _curry3 = require('./internal/_curry3');
|
1028 |
|
1029 |
|
1030 |
|
1031 |
|
1032 |
|
1033 |
|
1034 |
|
1035 |
|
1036 |
|
1037 |
|
1038 |
|
1039 |
|
1040 |
|
1041 |
|
1042 |
|
1043 |
|
1044 |
|
1045 |
|
1046 |
|
1047 |
|
1048 |
|
1049 |
|
1050 | module.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){
|
1060 | var _curry3 = require('./internal/_curry3');
|
1061 | var _slice = require('./internal/_slice');
|
1062 | var assoc = require('./assoc');
|
1063 |
|
1064 |
|
1065 |
|
1066 |
|
1067 |
|
1068 |
|
1069 |
|
1070 |
|
1071 |
|
1072 |
|
1073 |
|
1074 |
|
1075 |
|
1076 |
|
1077 |
|
1078 |
|
1079 |
|
1080 |
|
1081 |
|
1082 |
|
1083 |
|
1084 |
|
1085 | module.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){
|
1097 | var _curry1 = require('./internal/_curry1');
|
1098 | var curryN = require('./curryN');
|
1099 |
|
1100 |
|
1101 |
|
1102 |
|
1103 |
|
1104 |
|
1105 |
|
1106 |
|
1107 |
|
1108 |
|
1109 |
|
1110 |
|
1111 |
|
1112 |
|
1113 |
|
1114 |
|
1115 |
|
1116 |
|
1117 |
|
1118 |
|
1119 |
|
1120 |
|
1121 |
|
1122 |
|
1123 |
|
1124 |
|
1125 |
|
1126 |
|
1127 |
|
1128 |
|
1129 |
|
1130 |
|
1131 |
|
1132 |
|
1133 |
|
1134 |
|
1135 |
|
1136 |
|
1137 |
|
1138 |
|
1139 |
|
1140 |
|
1141 |
|
1142 | module.exports = _curry1(function curry(fn) {
|
1143 | return curryN(fn.length, fn);
|
1144 | });
|
1145 |
|
1146 | },{"./curryN":23,"./internal/_curry1":25}],23:[function(require,module,exports){
|
1147 | var _arity = require('./internal/_arity');
|
1148 | var _curry1 = require('./internal/_curry1');
|
1149 | var _curry2 = require('./internal/_curry2');
|
1150 | var _curryN = require('./internal/_curryN');
|
1151 |
|
1152 |
|
1153 |
|
1154 |
|
1155 |
|
1156 |
|
1157 |
|
1158 |
|
1159 |
|
1160 |
|
1161 |
|
1162 |
|
1163 |
|
1164 |
|
1165 |
|
1166 |
|
1167 |
|
1168 |
|
1169 |
|
1170 |
|
1171 |
|
1172 |
|
1173 |
|
1174 |
|
1175 |
|
1176 |
|
1177 |
|
1178 |
|
1179 |
|
1180 |
|
1181 |
|
1182 |
|
1183 |
|
1184 |
|
1185 |
|
1186 |
|
1187 |
|
1188 |
|
1189 |
|
1190 |
|
1191 |
|
1192 |
|
1193 |
|
1194 |
|
1195 | module.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){
|
1203 | module.exports = function _arity(n, fn) {
|
1204 |
|
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){
|
1222 | var _isPlaceholder = require('./_isPlaceholder');
|
1223 |
|
1224 |
|
1225 |
|
1226 |
|
1227 |
|
1228 |
|
1229 |
|
1230 |
|
1231 |
|
1232 |
|
1233 | module.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){
|
1244 | var _curry1 = require('./_curry1');
|
1245 | var _isPlaceholder = require('./_isPlaceholder');
|
1246 |
|
1247 |
|
1248 |
|
1249 |
|
1250 |
|
1251 |
|
1252 |
|
1253 |
|
1254 |
|
1255 |
|
1256 | module.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){
|
1274 | var _curry1 = require('./_curry1');
|
1275 | var _curry2 = require('./_curry2');
|
1276 | var _isPlaceholder = require('./_isPlaceholder');
|
1277 |
|
1278 |
|
1279 |
|
1280 |
|
1281 |
|
1282 |
|
1283 |
|
1284 |
|
1285 |
|
1286 |
|
1287 | module.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){
|
1314 | var _arity = require('./_arity');
|
1315 | var _isPlaceholder = require('./_isPlaceholder');
|
1316 |
|
1317 |
|
1318 |
|
1319 |
|
1320 |
|
1321 |
|
1322 |
|
1323 |
|
1324 |
|
1325 |
|
1326 |
|
1327 |
|
1328 | module.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){
|
1356 | module.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 |
|
1365 |
|
1366 |
|
1367 |
|
1368 |
|
1369 |
|
1370 |
|
1371 |
|
1372 |
|
1373 |
|
1374 |
|
1375 |
|
1376 |
|
1377 |
|
1378 |
|
1379 |
|
1380 | module.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){
|
1397 | var _curry2 = require('./internal/_curry2');
|
1398 |
|
1399 |
|
1400 |
|
1401 |
|
1402 |
|
1403 |
|
1404 |
|
1405 |
|
1406 |
|
1407 |
|
1408 |
|
1409 |
|
1410 |
|
1411 |
|
1412 |
|
1413 |
|
1414 |
|
1415 |
|
1416 | module.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 |
|
1432 | function 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 |
|
1443 | module.exports = thunkMiddleware;
|
1444 | },{}],33:[function(require,module,exports){
|
1445 | 'use strict';
|
1446 |
|
1447 | exports.__esModule = true;
|
1448 | exports['default'] = createStore;
|
1449 |
|
1450 | function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }
|
1451 |
|
1452 | var _utilsIsPlainObject = require('./utils/isPlainObject');
|
1453 |
|
1454 | var _utilsIsPlainObject2 = _interopRequireDefault(_utilsIsPlainObject);
|
1455 |
|
1456 |
|
1457 |
|
1458 |
|
1459 |
|
1460 |
|
1461 |
|
1462 | var ActionTypes = {
|
1463 | INIT: '@@redux/INIT'
|
1464 | };
|
1465 |
|
1466 | exports.ActionTypes = ActionTypes;
|
1467 |
|
1468 |
|
1469 |
|
1470 |
|
1471 |
|
1472 |
|
1473 |
|
1474 |
|
1475 |
|
1476 |
|
1477 |
|
1478 |
|
1479 |
|
1480 |
|
1481 |
|
1482 |
|
1483 |
|
1484 |
|
1485 |
|
1486 |
|
1487 |
|
1488 | function 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 |
|
1500 |
|
1501 |
|
1502 |
|
1503 | function getState() {
|
1504 | return currentState;
|
1505 | }
|
1506 |
|
1507 | |
1508 |
|
1509 |
|
1510 |
|
1511 |
|
1512 |
|
1513 |
|
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 |
|
1532 |
|
1533 |
|
1534 |
|
1535 |
|
1536 |
|
1537 |
|
1538 |
|
1539 |
|
1540 |
|
1541 |
|
1542 |
|
1543 |
|
1544 |
|
1545 |
|
1546 |
|
1547 |
|
1548 |
|
1549 |
|
1550 |
|
1551 |
|
1552 |
|
1553 |
|
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 |
|
1583 |
|
1584 |
|
1585 |
|
1586 |
|
1587 |
|
1588 |
|
1589 |
|
1590 |
|
1591 | function replaceReducer(nextReducer) {
|
1592 | currentReducer = nextReducer;
|
1593 | dispatch({ type: ActionTypes.INIT });
|
1594 | }
|
1595 |
|
1596 |
|
1597 |
|
1598 |
|
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 |
|
1611 | exports.__esModule = true;
|
1612 |
|
1613 | function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }
|
1614 |
|
1615 | var _createStore = require('./createStore');
|
1616 |
|
1617 | var _createStore2 = _interopRequireDefault(_createStore);
|
1618 |
|
1619 | var _utilsCombineReducers = require('./utils/combineReducers');
|
1620 |
|
1621 | var _utilsCombineReducers2 = _interopRequireDefault(_utilsCombineReducers);
|
1622 |
|
1623 | var _utilsBindActionCreators = require('./utils/bindActionCreators');
|
1624 |
|
1625 | var _utilsBindActionCreators2 = _interopRequireDefault(_utilsBindActionCreators);
|
1626 |
|
1627 | var _utilsApplyMiddleware = require('./utils/applyMiddleware');
|
1628 |
|
1629 | var _utilsApplyMiddleware2 = _interopRequireDefault(_utilsApplyMiddleware);
|
1630 |
|
1631 | var _utilsCompose = require('./utils/compose');
|
1632 |
|
1633 | var _utilsCompose2 = _interopRequireDefault(_utilsCompose);
|
1634 |
|
1635 | exports.createStore = _createStore2['default'];
|
1636 | exports.combineReducers = _utilsCombineReducers2['default'];
|
1637 | exports.bindActionCreators = _utilsBindActionCreators2['default'];
|
1638 | exports.applyMiddleware = _utilsApplyMiddleware2['default'];
|
1639 | exports.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 |
|
1643 | exports.__esModule = true;
|
1644 |
|
1645 | var _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 |
|
1647 | exports['default'] = applyMiddleware;
|
1648 |
|
1649 | function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }
|
1650 |
|
1651 | var _compose = require('./compose');
|
1652 |
|
1653 | var _compose2 = _interopRequireDefault(_compose);
|
1654 |
|
1655 |
|
1656 |
|
1657 |
|
1658 |
|
1659 |
|
1660 |
|
1661 |
|
1662 |
|
1663 |
|
1664 |
|
1665 |
|
1666 |
|
1667 |
|
1668 |
|
1669 |
|
1670 |
|
1671 |
|
1672 | function 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 |
|
1701 | module.exports = exports['default'];
|
1702 | },{"./compose":38}],36:[function(require,module,exports){
|
1703 | 'use strict';
|
1704 |
|
1705 | exports.__esModule = true;
|
1706 | exports['default'] = bindActionCreators;
|
1707 |
|
1708 | function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }
|
1709 |
|
1710 | var _mapValues = require('./mapValues');
|
1711 |
|
1712 | var _mapValues2 = _interopRequireDefault(_mapValues);
|
1713 |
|
1714 | function bindActionCreator(actionCreator, dispatch) {
|
1715 | return function () {
|
1716 | return dispatch(actionCreator.apply(undefined, arguments));
|
1717 | };
|
1718 | }
|
1719 |
|
1720 |
|
1721 |
|
1722 |
|
1723 |
|
1724 |
|
1725 |
|
1726 |
|
1727 |
|
1728 |
|
1729 |
|
1730 |
|
1731 |
|
1732 |
|
1733 |
|
1734 |
|
1735 |
|
1736 |
|
1737 |
|
1738 |
|
1739 |
|
1740 |
|
1741 |
|
1742 | function 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 |
|
1756 | module.exports = exports['default'];
|
1757 | },{"./mapValues":40}],37:[function(require,module,exports){
|
1758 | (function (process){
|
1759 | 'use strict';
|
1760 |
|
1761 | exports.__esModule = true;
|
1762 | exports['default'] = combineReducers;
|
1763 |
|
1764 | function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }
|
1765 |
|
1766 | var _createStore = require('../createStore');
|
1767 |
|
1768 | var _isPlainObject = require('./isPlainObject');
|
1769 |
|
1770 | var _isPlainObject2 = _interopRequireDefault(_isPlainObject);
|
1771 |
|
1772 | var _mapValues = require('./mapValues');
|
1773 |
|
1774 | var _mapValues2 = _interopRequireDefault(_mapValues);
|
1775 |
|
1776 | var _pick = require('./pick');
|
1777 |
|
1778 | var _pick2 = _interopRequireDefault(_pick);
|
1779 |
|
1780 |
|
1781 |
|
1782 | function 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 |
|
1789 | function 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 |
|
1810 | function 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 |
|
1828 |
|
1829 |
|
1830 |
|
1831 |
|
1832 |
|
1833 |
|
1834 |
|
1835 |
|
1836 |
|
1837 |
|
1838 |
|
1839 |
|
1840 |
|
1841 |
|
1842 |
|
1843 | function 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 |
|
1889 | module.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 |
|
1895 |
|
1896 |
|
1897 |
|
1898 |
|
1899 |
|
1900 | "use strict";
|
1901 |
|
1902 | exports.__esModule = true;
|
1903 | exports["default"] = compose;
|
1904 |
|
1905 | function 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 |
|
1917 | module.exports = exports["default"];
|
1918 | },{}],39:[function(require,module,exports){
|
1919 | 'use strict';
|
1920 |
|
1921 | exports.__esModule = true;
|
1922 | exports['default'] = isPlainObject;
|
1923 | var fnToString = function fnToString(fn) {
|
1924 | return Function.prototype.toString.call(fn);
|
1925 | };
|
1926 | var objStringValue = fnToString(Object);
|
1927 |
|
1928 |
|
1929 |
|
1930 |
|
1931 |
|
1932 |
|
1933 | function 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 |
|
1949 | module.exports = exports['default'];
|
1950 | },{}],40:[function(require,module,exports){
|
1951 |
|
1952 |
|
1953 |
|
1954 |
|
1955 |
|
1956 |
|
1957 |
|
1958 | "use strict";
|
1959 |
|
1960 | exports.__esModule = true;
|
1961 | exports["default"] = mapValues;
|
1962 |
|
1963 | function 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 |
|
1970 | module.exports = exports["default"];
|
1971 | },{}],41:[function(require,module,exports){
|
1972 |
|
1973 |
|
1974 |
|
1975 |
|
1976 |
|
1977 |
|
1978 |
|
1979 | "use strict";
|
1980 |
|
1981 | exports.__esModule = true;
|
1982 | exports["default"] = pick;
|
1983 |
|
1984 | function 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 |
|
1993 | module.exports = exports["default"];
|
1994 | },{}],42:[function(require,module,exports){
|
1995 | var createElement = require("./vdom/create-element.js")
|
1996 |
|
1997 | module.exports = createElement
|
1998 |
|
1999 | },{"./vdom/create-element.js":46}],43:[function(require,module,exports){
|
2000 | var diff = require("./vtree/diff.js")
|
2001 |
|
2002 | module.exports = diff
|
2003 |
|
2004 | },{"./vtree/diff.js":60}],44:[function(require,module,exports){
|
2005 | var patch = require("./vdom/patch.js")
|
2006 |
|
2007 | module.exports = patch
|
2008 |
|
2009 | },{"./vdom/patch.js":49}],45:[function(require,module,exports){
|
2010 | var isObject = require("is-object")
|
2011 | var isHook = require("../vnode/is-vhook.js")
|
2012 |
|
2013 | module.exports = applyProperties
|
2014 |
|
2015 | function 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 |
|
2038 | function 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 |
|
2062 | function patchObject(node, props, previous, propName, propValue) {
|
2063 | var previousValue = previous ? previous[propName] : undefined
|
2064 |
|
2065 |
|
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 |
|
2098 | function 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){
|
2109 | var document = require("global/document")
|
2110 |
|
2111 | var applyProperties = require("./apply-properties")
|
2112 |
|
2113 | var isVNode = require("../vnode/is-vnode.js")
|
2114 | var isVText = require("../vnode/is-vtext.js")
|
2115 | var isWidget = require("../vnode/is-widget.js")
|
2116 | var handleThunk = require("../vnode/handle-thunk.js")
|
2117 |
|
2118 | module.exports = createElement
|
2119 |
|
2120 | function 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 |
|
2158 |
|
2159 |
|
2160 |
|
2161 |
|
2162 |
|
2163 | var noChild = {}
|
2164 |
|
2165 | module.exports = domIndex
|
2166 |
|
2167 | function 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 |
|
2176 | function 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 |
|
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 |
|
2211 | function 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 |
|
2239 | function ascending(a, b) {
|
2240 | return a > b ? 1 : -1
|
2241 | }
|
2242 |
|
2243 | },{}],48:[function(require,module,exports){
|
2244 | var applyProperties = require("./apply-properties")
|
2245 |
|
2246 | var isWidget = require("../vnode/is-widget.js")
|
2247 | var VPatch = require("../vnode/vpatch.js")
|
2248 |
|
2249 | var updateWidget = require("./update-widget")
|
2250 |
|
2251 | module.exports = applyPatch
|
2252 |
|
2253 | function 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 |
|
2283 | function 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 |
|
2295 | function 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 |
|
2305 | function 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 |
|
2323 | function 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 |
|
2346 | function 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 |
|
2357 | function destroyWidget(domNode, w) {
|
2358 | if (typeof w.destroy === "function" && isWidget(w)) {
|
2359 | w.destroy(domNode)
|
2360 | }
|
2361 | }
|
2362 |
|
2363 | function 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 |
|
2384 | domNode.insertBefore(node, insert.to >= length++ ? null : childNodes[insert.to])
|
2385 | }
|
2386 | }
|
2387 |
|
2388 | function 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){
|
2397 | var document = require("global/document")
|
2398 | var isArray = require("x-is-array")
|
2399 |
|
2400 | var render = require("./create-element")
|
2401 | var domIndex = require("./dom-index")
|
2402 | var patchOp = require("./patch-op")
|
2403 | module.exports = patch
|
2404 |
|
2405 | function 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 |
|
2415 | function 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 |
|
2440 | function 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 |
|
2466 | function 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){
|
2479 | var isWidget = require("../vnode/is-widget.js")
|
2480 |
|
2481 | module.exports = updateWidget
|
2482 |
|
2483 | function 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){
|
2496 | var isVNode = require("./is-vnode")
|
2497 | var isVText = require("./is-vtext")
|
2498 | var isWidget = require("./is-widget")
|
2499 | var isThunk = require("./is-thunk")
|
2500 |
|
2501 | module.exports = handleThunk
|
2502 |
|
2503 | function 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 |
|
2521 | function 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){
|
2538 | module.exports = isThunk
|
2539 |
|
2540 | function isThunk(t) {
|
2541 | return t && t.type === "Thunk"
|
2542 | }
|
2543 |
|
2544 | },{}],53:[function(require,module,exports){
|
2545 | module.exports = isHook
|
2546 |
|
2547 | function 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){
|
2554 | var version = require("./version")
|
2555 |
|
2556 | module.exports = isVirtualNode
|
2557 |
|
2558 | function isVirtualNode(x) {
|
2559 | return x && x.type === "VirtualNode" && x.version === version
|
2560 | }
|
2561 |
|
2562 | },{"./version":57}],55:[function(require,module,exports){
|
2563 | var version = require("./version")
|
2564 |
|
2565 | module.exports = isVirtualText
|
2566 |
|
2567 | function isVirtualText(x) {
|
2568 | return x && x.type === "VirtualText" && x.version === version
|
2569 | }
|
2570 |
|
2571 | },{"./version":57}],56:[function(require,module,exports){
|
2572 | module.exports = isWidget
|
2573 |
|
2574 | function isWidget(w) {
|
2575 | return w && w.type === "Widget"
|
2576 | }
|
2577 |
|
2578 | },{}],57:[function(require,module,exports){
|
2579 | module.exports = "2"
|
2580 |
|
2581 | },{}],58:[function(require,module,exports){
|
2582 | var version = require("./version")
|
2583 |
|
2584 | VirtualPatch.NONE = 0
|
2585 | VirtualPatch.VTEXT = 1
|
2586 | VirtualPatch.VNODE = 2
|
2587 | VirtualPatch.WIDGET = 3
|
2588 | VirtualPatch.PROPS = 4
|
2589 | VirtualPatch.ORDER = 5
|
2590 | VirtualPatch.INSERT = 6
|
2591 | VirtualPatch.REMOVE = 7
|
2592 | VirtualPatch.THUNK = 8
|
2593 |
|
2594 | module.exports = VirtualPatch
|
2595 |
|
2596 | function VirtualPatch(type, vNode, patch) {
|
2597 | this.type = Number(type)
|
2598 | this.vNode = vNode
|
2599 | this.patch = patch
|
2600 | }
|
2601 |
|
2602 | VirtualPatch.prototype.version = version
|
2603 | VirtualPatch.prototype.type = "VirtualPatch"
|
2604 |
|
2605 | },{"./version":57}],59:[function(require,module,exports){
|
2606 | var isObject = require("is-object")
|
2607 | var isHook = require("../vnode/is-vhook")
|
2608 |
|
2609 | module.exports = diffProps
|
2610 |
|
2611 | function 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 |
|
2655 | function 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){
|
2666 | var isArray = require("x-is-array")
|
2667 |
|
2668 | var VPatch = require("../vnode/vpatch")
|
2669 | var isVNode = require("../vnode/is-vnode")
|
2670 | var isVText = require("../vnode/is-vtext")
|
2671 | var isWidget = require("../vnode/is-widget")
|
2672 | var isThunk = require("../vnode/is-thunk")
|
2673 | var handleThunk = require("../vnode/handle-thunk")
|
2674 |
|
2675 | var diffProps = require("./diff-props")
|
2676 |
|
2677 | module.exports = diff
|
2678 |
|
2679 | function diff(a, b) {
|
2680 | var patch = { a: a }
|
2681 | walk(a, b, patch, 0)
|
2682 | return patch
|
2683 | }
|
2684 |
|
2685 | function 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 |
|
2698 |
|
2699 |
|
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 |
|
2749 | function 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 |
|
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 |
|
2780 | apply = appendPatch(apply, new VPatch(
|
2781 | VPatch.ORDER,
|
2782 | a,
|
2783 | orderedSet.moves
|
2784 | ))
|
2785 | }
|
2786 |
|
2787 | return apply
|
2788 | }
|
2789 |
|
2790 | function clearState(vNode, patch, index) {
|
2791 |
|
2792 | unhook(vNode, patch, index)
|
2793 | destroyWidgets(vNode, patch, index)
|
2794 | }
|
2795 |
|
2796 |
|
2797 |
|
2798 | function 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 |
|
2825 | function 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 |
|
2833 | function hasPatches(patch) {
|
2834 | for (var index in patch) {
|
2835 | if (index !== "a") {
|
2836 | return true
|
2837 | }
|
2838 | }
|
2839 |
|
2840 | return false
|
2841 | }
|
2842 |
|
2843 |
|
2844 | function 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 |
|
2876 | function undefinedKeys(obj) {
|
2877 | var result = {}
|
2878 |
|
2879 | for (var key in obj) {
|
2880 | result[key] = undefined
|
2881 | }
|
2882 |
|
2883 | return result
|
2884 | }
|
2885 |
|
2886 |
|
2887 | function reorder(aChildren, bChildren) {
|
2888 |
|
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 |
|
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 |
|
2913 | var newChildren = []
|
2914 |
|
2915 | var freeIndex = 0
|
2916 | var freeCount = bFree.length
|
2917 | var deletedItems = 0
|
2918 |
|
2919 |
|
2920 |
|
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 |
|
2928 | itemIndex = bKeys[aItem.key]
|
2929 | newChildren.push(bChildren[itemIndex])
|
2930 |
|
2931 | } else {
|
2932 |
|
2933 | itemIndex = i - deletedItems++
|
2934 | newChildren.push(null)
|
2935 | }
|
2936 | } else {
|
2937 |
|
2938 | if (freeIndex < freeCount) {
|
2939 | itemIndex = bFree[freeIndex++]
|
2940 | newChildren.push(bChildren[itemIndex])
|
2941 | } else {
|
2942 |
|
2943 |
|
2944 |
|
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 |
|
2956 |
|
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 |
|
2963 |
|
2964 |
|
2965 | newChildren.push(newItem)
|
2966 | }
|
2967 | } else if (j >= lastFreeIndex) {
|
2968 |
|
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 |
|
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 |
|
2991 | if (wantedItem.key) {
|
2992 | if (simulateItem && simulateItem.key) {
|
2993 |
|
2994 | if (bKeys[simulateItem.key] !== k + 1) {
|
2995 | removes.push(remove(simulate, simulateIndex, simulateItem.key))
|
2996 | simulateItem = simulate[simulateIndex]
|
2997 |
|
2998 | if (!simulateItem || simulateItem.key !== wantedItem.key) {
|
2999 | inserts.push({key: wantedItem.key, to: k})
|
3000 | }
|
3001 |
|
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 |
|
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 |
|
3027 | while(simulateIndex < simulate.length) {
|
3028 | simulateItem = simulate[simulateIndex]
|
3029 | removes.push(remove(simulate, simulateIndex, simulateItem && simulateItem.key))
|
3030 | }
|
3031 |
|
3032 |
|
3033 |
|
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 |
|
3050 | function remove(arr, index, key) {
|
3051 | arr.splice(index, 1)
|
3052 |
|
3053 | return {
|
3054 | from: index,
|
3055 | key: key
|
3056 | }
|
3057 | }
|
3058 |
|
3059 | function 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,
|
3076 | free: free
|
3077 | }
|
3078 | }
|
3079 |
|
3080 | function 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){
|
3095 | var hiddenStore = require('./hidden-store.js');
|
3096 |
|
3097 | module.exports = createStore;
|
3098 |
|
3099 | function 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){
|
3116 | module.exports = hiddenStore;
|
3117 |
|
3118 | function 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){
|
3134 | var nativeIsArray = Array.isArray
|
3135 | var toString = Object.prototype.toString
|
3136 |
|
3137 | module.exports = nativeIsArray || isArray
|
3138 |
|
3139 | function isArray(obj) {
|
3140 | return toString.call(obj) === "[object Array]"
|
3141 | }
|
3142 |
|
3143 | },{}]},{},[3])(3)
|
3144 | });
|
3145 |
|
3146 |
|
3147 |
|