UNPKG

29.2 kBJavaScriptView Raw
1(function webpackUniversalModuleDefinition(root, factory) {
2 if(typeof exports === 'object' && typeof module === 'object')
3 module.exports = factory();
4 else if(typeof define === 'function' && define.amd)
5 define([], factory);
6 else if(typeof exports === 'object')
7 exports["reduxLogger"] = factory();
8 else
9 root["reduxLogger"] = factory();
10})(this, function() {
11return /******/ (function(modules) { // webpackBootstrap
12/******/ // The module cache
13/******/ var installedModules = {};
14
15/******/ // The require function
16/******/ function __webpack_require__(moduleId) {
17
18/******/ // Check if module is in cache
19/******/ if(installedModules[moduleId])
20/******/ return installedModules[moduleId].exports;
21
22/******/ // Create a new module (and put it into the cache)
23/******/ var module = installedModules[moduleId] = {
24/******/ exports: {},
25/******/ id: moduleId,
26/******/ loaded: false
27/******/ };
28
29/******/ // Execute the module function
30/******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);
31
32/******/ // Flag the module as loaded
33/******/ module.loaded = true;
34
35/******/ // Return the exports of the module
36/******/ return module.exports;
37/******/ }
38
39
40/******/ // expose the modules object (__webpack_modules__)
41/******/ __webpack_require__.m = modules;
42
43/******/ // expose the module cache
44/******/ __webpack_require__.c = installedModules;
45
46/******/ // __webpack_public_path__
47/******/ __webpack_require__.p = "";
48
49/******/ // Load entry module and return exports
50/******/ return __webpack_require__(0);
51/******/ })
52/************************************************************************/
53/******/ ([
54/* 0 */
55/***/ function(module, exports, __webpack_require__) {
56
57 __webpack_require__(2);
58 module.exports = __webpack_require__(2);
59
60
61/***/ },
62/* 1 */
63/***/ function(module, exports) {
64
65 "use strict";
66
67 Object.defineProperty(exports, "__esModule", {
68 value: true
69 });
70 var repeat = exports.repeat = function repeat(str, times) {
71 return new Array(times + 1).join(str);
72 };
73
74 var pad = exports.pad = function pad(num, maxLength) {
75 return repeat("0", maxLength - num.toString().length) + num;
76 };
77
78 var formatTime = exports.formatTime = function formatTime(time) {
79 return pad(time.getHours(), 2) + ":" + pad(time.getMinutes(), 2) + ":" + pad(time.getSeconds(), 2) + "." + pad(time.getMilliseconds(), 3);
80 };
81
82 // Use performance API if it's available in order to get better precision
83 var timer = exports.timer = typeof performance !== "undefined" && performance !== null && typeof performance.now === "function" ? performance : Date;
84
85/***/ },
86/* 2 */
87/***/ function(module, exports, __webpack_require__) {
88
89 'use strict';
90
91 Object.defineProperty(exports, "__esModule", {
92 value: true
93 });
94 exports.logger = exports.createLogger = exports.defaults = undefined;
95
96 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; };
97
98 var _core = __webpack_require__(3);
99
100 var _helpers = __webpack_require__(1);
101
102 var _defaults = __webpack_require__(4);
103
104 var _defaults2 = _interopRequireDefault(_defaults);
105
106 function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
107
108 /**
109 * Creates logger with following options
110 *
111 * @namespace
112 * @param {object} options - options for logger
113 * @param {string | function | object} options.level - console[level]
114 * @param {boolean} options.duration - print duration of each action?
115 * @param {boolean} options.timestamp - print timestamp with each action?
116 * @param {object} options.colors - custom colors
117 * @param {object} options.logger - implementation of the `console` API
118 * @param {boolean} options.logErrors - should errors in action execution be caught, logged, and re-thrown?
119 * @param {boolean} options.collapsed - is group collapsed?
120 * @param {boolean} options.predicate - condition which resolves logger behavior
121 * @param {function} options.stateTransformer - transform state before print
122 * @param {function} options.actionTransformer - transform action before print
123 * @param {function} options.errorTransformer - transform error before print
124 *
125 * @returns {function} logger middleware
126 */
127 function createLogger() {
128 var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
129
130 var loggerOptions = _extends({}, _defaults2.default, options);
131
132 var logger = loggerOptions.logger,
133 stateTransformer = loggerOptions.stateTransformer,
134 errorTransformer = loggerOptions.errorTransformer,
135 predicate = loggerOptions.predicate,
136 logErrors = loggerOptions.logErrors,
137 diffPredicate = loggerOptions.diffPredicate;
138
139 // Return if 'console' object is not defined
140
141 if (typeof logger === 'undefined') {
142 return function () {
143 return function (next) {
144 return function (action) {
145 return next(action);
146 };
147 };
148 };
149 }
150
151 // Detect if 'createLogger' was passed directly to 'applyMiddleware'.
152 if (options.getState && options.dispatch) {
153 // eslint-disable-next-line no-console
154 console.error('[redux-logger] redux-logger not installed. Make sure to pass logger instance as middleware:\n// Logger with default options\nimport { logger } from \'redux-logger\'\nconst store = createStore(\n reducer,\n applyMiddleware(logger)\n)\n// Or you can create your own logger with custom options http://bit.ly/redux-logger-options\nimport createLogger from \'redux-logger\'\nconst logger = createLogger({\n // ...options\n});\nconst store = createStore(\n reducer,\n applyMiddleware(logger)\n)\n');
155
156 return function () {
157 return function (next) {
158 return function (action) {
159 return next(action);
160 };
161 };
162 };
163 }
164
165 var logBuffer = [];
166
167 return function (_ref) {
168 var getState = _ref.getState;
169 return function (next) {
170 return function (action) {
171 // Exit early if predicate function returns 'false'
172 if (typeof predicate === 'function' && !predicate(getState, action)) {
173 return next(action);
174 }
175
176 var logEntry = {};
177
178 logBuffer.push(logEntry);
179
180 logEntry.started = _helpers.timer.now();
181 logEntry.startedTime = new Date();
182 logEntry.prevState = stateTransformer(getState());
183 logEntry.action = action;
184
185 var returnedValue = void 0;
186 if (logErrors) {
187 try {
188 returnedValue = next(action);
189 } catch (e) {
190 logEntry.error = errorTransformer(e);
191 }
192 } else {
193 returnedValue = next(action);
194 }
195
196 logEntry.took = _helpers.timer.now() - logEntry.started;
197 logEntry.nextState = stateTransformer(getState());
198
199 var diff = loggerOptions.diff && typeof diffPredicate === 'function' ? diffPredicate(getState, action) : loggerOptions.diff;
200
201 (0, _core.printBuffer)(logBuffer, _extends({}, loggerOptions, { diff: diff }));
202 logBuffer.length = 0;
203
204 if (logEntry.error) throw logEntry.error;
205 return returnedValue;
206 };
207 };
208 };
209 }
210
211 var defaultLogger = function defaultLogger() {
212 var _ref2 = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {},
213 dispatch = _ref2.dispatch,
214 getState = _ref2.getState;
215
216 if (typeof dispatch === 'function' || typeof getState === 'function') {
217 return createLogger()({ dispatch: dispatch, getState: getState });
218 } else {
219 // eslint-disable-next-line no-console
220 console.error('\n[redux-logger v3] BREAKING CHANGE\n[redux-logger v3] Since 3.0.0 redux-logger exports by default logger with default settings.\n[redux-logger v3] Change\n[redux-logger v3] import createLogger from \'redux-logger\'\n[redux-logger v3] to\n[redux-logger v3] import { createLogger } from \'redux-logger\'\n');
221 }
222 };
223
224 exports.defaults = _defaults2.default;
225 exports.createLogger = createLogger;
226 exports.logger = defaultLogger;
227 exports.default = defaultLogger;
228
229/***/ },
230/* 3 */
231/***/ function(module, exports, __webpack_require__) {
232
233 'use strict';
234
235 Object.defineProperty(exports, "__esModule", {
236 value: true
237 });
238
239 var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; };
240
241 exports.printBuffer = printBuffer;
242
243 var _helpers = __webpack_require__(1);
244
245 var _diff = __webpack_require__(5);
246
247 var _diff2 = _interopRequireDefault(_diff);
248
249 function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
250
251 function _toConsumableArray(arr) { if (Array.isArray(arr)) { for (var i = 0, arr2 = Array(arr.length); i < arr.length; i++) { arr2[i] = arr[i]; } return arr2; } else { return Array.from(arr); } }
252
253 /**
254 * Get log level string based on supplied params
255 *
256 * @param {string | function | object} level - console[level]
257 * @param {object} action - selected action
258 * @param {array} payload - selected payload
259 * @param {string} type - log entry type
260 *
261 * @returns {string} level
262 */
263 function getLogLevel(level, action, payload, type) {
264 switch (typeof level === 'undefined' ? 'undefined' : _typeof(level)) {
265 case 'object':
266 return typeof level[type] === 'function' ? level[type].apply(level, _toConsumableArray(payload)) : level[type];
267 case 'function':
268 return level(action);
269 default:
270 return level;
271 }
272 }
273
274 function defaultTitleFormatter(options) {
275 var timestamp = options.timestamp,
276 duration = options.duration;
277
278
279 return function (action, time, took) {
280 var parts = ['action'];
281
282 parts.push('%c' + String(action.type));
283 if (timestamp) parts.push('%c@ ' + time);
284 if (duration) parts.push('%c(in ' + took.toFixed(2) + ' ms)');
285
286 return parts.join(' ');
287 };
288 }
289
290 function printBuffer(buffer, options) {
291 var logger = options.logger,
292 actionTransformer = options.actionTransformer,
293 _options$titleFormatt = options.titleFormatter,
294 titleFormatter = _options$titleFormatt === undefined ? defaultTitleFormatter(options) : _options$titleFormatt,
295 collapsed = options.collapsed,
296 colors = options.colors,
297 level = options.level,
298 diff = options.diff;
299
300
301 buffer.forEach(function (logEntry, key) {
302 var started = logEntry.started,
303 startedTime = logEntry.startedTime,
304 action = logEntry.action,
305 prevState = logEntry.prevState,
306 error = logEntry.error;
307 var took = logEntry.took,
308 nextState = logEntry.nextState;
309
310 var nextEntry = buffer[key + 1];
311
312 if (nextEntry) {
313 nextState = nextEntry.prevState;
314 took = nextEntry.started - started;
315 }
316
317 // Message
318 var formattedAction = actionTransformer(action);
319 var isCollapsed = typeof collapsed === 'function' ? collapsed(function () {
320 return nextState;
321 }, action, logEntry) : collapsed;
322
323 var formattedTime = (0, _helpers.formatTime)(startedTime);
324 var titleCSS = colors.title ? 'color: ' + colors.title(formattedAction) + ';' : '';
325 var headerCSS = ['color: gray; font-weight: lighter;'];
326 headerCSS.push(titleCSS);
327 if (options.timestamp) headerCSS.push('color: gray; font-weight: lighter;');
328 if (options.duration) headerCSS.push('color: gray; font-weight: lighter;');
329 var title = titleFormatter(formattedAction, formattedTime, took);
330
331 // Render
332 try {
333 if (isCollapsed) {
334 if (colors.title) logger.groupCollapsed.apply(logger, ['%c ' + title].concat(headerCSS));else logger.groupCollapsed(title);
335 } else {
336 if (colors.title) logger.group.apply(logger, ['%c ' + title].concat(headerCSS));else logger.group(title);
337 }
338 } catch (e) {
339 logger.log(title);
340 }
341
342 var prevStateLevel = getLogLevel(level, formattedAction, [prevState], 'prevState');
343 var actionLevel = getLogLevel(level, formattedAction, [formattedAction], 'action');
344 var errorLevel = getLogLevel(level, formattedAction, [error, prevState], 'error');
345 var nextStateLevel = getLogLevel(level, formattedAction, [nextState], 'nextState');
346
347 if (prevStateLevel) {
348 if (colors.prevState) logger[prevStateLevel]('%c prev state', 'color: ' + colors.prevState(prevState) + '; font-weight: bold', prevState);else logger[prevStateLevel]('prev state', prevState);
349 }
350
351 if (actionLevel) {
352 if (colors.action) logger[actionLevel]('%c action ', 'color: ' + colors.action(formattedAction) + '; font-weight: bold', formattedAction);else logger[actionLevel]('action ', formattedAction);
353 }
354
355 if (error && errorLevel) {
356 if (colors.error) logger[errorLevel]('%c error ', 'color: ' + colors.error(error, prevState) + '; font-weight: bold;', error);else logger[errorLevel]('error ', error);
357 }
358
359 if (nextStateLevel) {
360 if (colors.nextState) logger[nextStateLevel]('%c next state', 'color: ' + colors.nextState(nextState) + '; font-weight: bold', nextState);else logger[nextStateLevel]('next state', nextState);
361 }
362
363 if (diff) {
364 (0, _diff2.default)(prevState, nextState, logger, isCollapsed);
365 }
366
367 try {
368 logger.groupEnd();
369 } catch (e) {
370 logger.log('\u2014\u2014 log end \u2014\u2014');
371 }
372 });
373 }
374
375/***/ },
376/* 4 */
377/***/ function(module, exports) {
378
379 "use strict";
380
381 Object.defineProperty(exports, "__esModule", {
382 value: true
383 });
384 exports.default = {
385 level: "log",
386 logger: console,
387 logErrors: true,
388 collapsed: undefined,
389 predicate: undefined,
390 duration: false,
391 timestamp: true,
392 stateTransformer: function stateTransformer(state) {
393 return state;
394 },
395 actionTransformer: function actionTransformer(action) {
396 return action;
397 },
398 errorTransformer: function errorTransformer(error) {
399 return error;
400 },
401 colors: {
402 title: function title() {
403 return "inherit";
404 },
405 prevState: function prevState() {
406 return "#9E9E9E";
407 },
408 action: function action() {
409 return "#03A9F4";
410 },
411 nextState: function nextState() {
412 return "#4CAF50";
413 },
414 error: function error() {
415 return "#F20404";
416 }
417 },
418 diff: false,
419 diffPredicate: undefined,
420
421 // Deprecated options
422 transformer: undefined
423 };
424 module.exports = exports["default"];
425
426/***/ },
427/* 5 */
428/***/ function(module, exports, __webpack_require__) {
429
430 'use strict';
431
432 Object.defineProperty(exports, "__esModule", {
433 value: true
434 });
435 exports.default = diffLogger;
436
437 var _deepDiff = __webpack_require__(6);
438
439 var _deepDiff2 = _interopRequireDefault(_deepDiff);
440
441 function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
442
443 function _toConsumableArray(arr) { if (Array.isArray(arr)) { for (var i = 0, arr2 = Array(arr.length); i < arr.length; i++) { arr2[i] = arr[i]; } return arr2; } else { return Array.from(arr); } }
444
445 // https://github.com/flitbit/diff#differences
446 var dictionary = {
447 'E': {
448 color: '#2196F3',
449 text: 'CHANGED:'
450 },
451 'N': {
452 color: '#4CAF50',
453 text: 'ADDED:'
454 },
455 'D': {
456 color: '#F44336',
457 text: 'DELETED:'
458 },
459 'A': {
460 color: '#2196F3',
461 text: 'ARRAY:'
462 }
463 };
464
465 function style(kind) {
466 return 'color: ' + dictionary[kind].color + '; font-weight: bold';
467 }
468
469 function render(diff) {
470 var kind = diff.kind,
471 path = diff.path,
472 lhs = diff.lhs,
473 rhs = diff.rhs,
474 index = diff.index,
475 item = diff.item;
476
477
478 switch (kind) {
479 case 'E':
480 return [path.join('.'), lhs, '\u2192', rhs];
481 case 'N':
482 return [path.join('.'), rhs];
483 case 'D':
484 return [path.join('.')];
485 case 'A':
486 return [path.join('.') + '[' + index + ']', item];
487 default:
488 return [];
489 }
490 }
491
492 function diffLogger(prevState, newState, logger, isCollapsed) {
493 var diff = (0, _deepDiff2.default)(prevState, newState);
494
495 try {
496 if (isCollapsed) {
497 logger.groupCollapsed('diff');
498 } else {
499 logger.group('diff');
500 }
501 } catch (e) {
502 logger.log('diff');
503 }
504
505 if (diff) {
506 diff.forEach(function (elem) {
507 var kind = elem.kind;
508
509 var output = render(elem);
510
511 logger.log.apply(logger, ['%c ' + dictionary[kind].text, style(kind)].concat(_toConsumableArray(output)));
512 });
513 } else {
514 logger.log('\u2014\u2014 no diff \u2014\u2014');
515 }
516
517 try {
518 logger.groupEnd();
519 } catch (e) {
520 logger.log('\u2014\u2014 diff end \u2014\u2014 ');
521 }
522 }
523 module.exports = exports['default'];
524
525/***/ },
526/* 6 */
527/***/ function(module, exports, __webpack_require__) {
528
529 var __WEBPACK_AMD_DEFINE_ARRAY__, __WEBPACK_AMD_DEFINE_RESULT__;/* WEBPACK VAR INJECTION */(function(global) {/*!
530 * deep-diff.
531 * Licensed under the MIT License.
532 */
533 ;(function(root, factory) {
534 'use strict';
535 if (true) {
536 // AMD. Register as an anonymous module.
537 !(__WEBPACK_AMD_DEFINE_ARRAY__ = [], __WEBPACK_AMD_DEFINE_RESULT__ = function() {
538 return factory();
539 }.apply(exports, __WEBPACK_AMD_DEFINE_ARRAY__), __WEBPACK_AMD_DEFINE_RESULT__ !== undefined && (module.exports = __WEBPACK_AMD_DEFINE_RESULT__));
540 } else if (typeof exports === 'object') {
541 // Node. Does not work with strict CommonJS, but
542 // only CommonJS-like environments that support module.exports,
543 // like Node.
544 module.exports = factory();
545 } else {
546 // Browser globals (root is window)
547 root.DeepDiff = factory();
548 }
549 }(this, function(undefined) {
550 'use strict';
551
552 var $scope, conflict, conflictResolution = [];
553 if (typeof global === 'object' && global) {
554 $scope = global;
555 } else if (typeof window !== 'undefined') {
556 $scope = window;
557 } else {
558 $scope = {};
559 }
560 conflict = $scope.DeepDiff;
561 if (conflict) {
562 conflictResolution.push(
563 function() {
564 if ('undefined' !== typeof conflict && $scope.DeepDiff === accumulateDiff) {
565 $scope.DeepDiff = conflict;
566 conflict = undefined;
567 }
568 });
569 }
570
571 // nodejs compatible on server side and in the browser.
572 function inherits(ctor, superCtor) {
573 ctor.super_ = superCtor;
574 ctor.prototype = Object.create(superCtor.prototype, {
575 constructor: {
576 value: ctor,
577 enumerable: false,
578 writable: true,
579 configurable: true
580 }
581 });
582 }
583
584 function Diff(kind, path) {
585 Object.defineProperty(this, 'kind', {
586 value: kind,
587 enumerable: true
588 });
589 if (path && path.length) {
590 Object.defineProperty(this, 'path', {
591 value: path,
592 enumerable: true
593 });
594 }
595 }
596
597 function DiffEdit(path, origin, value) {
598 DiffEdit.super_.call(this, 'E', path);
599 Object.defineProperty(this, 'lhs', {
600 value: origin,
601 enumerable: true
602 });
603 Object.defineProperty(this, 'rhs', {
604 value: value,
605 enumerable: true
606 });
607 }
608 inherits(DiffEdit, Diff);
609
610 function DiffNew(path, value) {
611 DiffNew.super_.call(this, 'N', path);
612 Object.defineProperty(this, 'rhs', {
613 value: value,
614 enumerable: true
615 });
616 }
617 inherits(DiffNew, Diff);
618
619 function DiffDeleted(path, value) {
620 DiffDeleted.super_.call(this, 'D', path);
621 Object.defineProperty(this, 'lhs', {
622 value: value,
623 enumerable: true
624 });
625 }
626 inherits(DiffDeleted, Diff);
627
628 function DiffArray(path, index, item) {
629 DiffArray.super_.call(this, 'A', path);
630 Object.defineProperty(this, 'index', {
631 value: index,
632 enumerable: true
633 });
634 Object.defineProperty(this, 'item', {
635 value: item,
636 enumerable: true
637 });
638 }
639 inherits(DiffArray, Diff);
640
641 function arrayRemove(arr, from, to) {
642 var rest = arr.slice((to || from) + 1 || arr.length);
643 arr.length = from < 0 ? arr.length + from : from;
644 arr.push.apply(arr, rest);
645 return arr;
646 }
647
648 function realTypeOf(subject) {
649 var type = typeof subject;
650 if (type !== 'object') {
651 return type;
652 }
653
654 if (subject === Math) {
655 return 'math';
656 } else if (subject === null) {
657 return 'null';
658 } else if (Array.isArray(subject)) {
659 return 'array';
660 } else if (Object.prototype.toString.call(subject) === '[object Date]') {
661 return 'date';
662 } else if (typeof subject.toString !== 'undefined' && /^\/.*\//.test(subject.toString())) {
663 return 'regexp';
664 }
665 return 'object';
666 }
667
668 function deepDiff(lhs, rhs, changes, prefilter, path, key, stack) {
669 path = path || [];
670 var currentPath = path.slice(0);
671 if (typeof key !== 'undefined') {
672 if (prefilter) {
673 if (typeof(prefilter) === 'function' && prefilter(currentPath, key)) { return; }
674 else if (typeof(prefilter) === 'object') {
675 if (prefilter.prefilter && prefilter.prefilter(currentPath, key)) { return; }
676 if (prefilter.normalize) {
677 var alt = prefilter.normalize(currentPath, key, lhs, rhs);
678 if (alt) {
679 lhs = alt[0];
680 rhs = alt[1];
681 }
682 }
683 }
684 }
685 currentPath.push(key);
686 }
687
688 // Use string comparison for regexes
689 if (realTypeOf(lhs) === 'regexp' && realTypeOf(rhs) === 'regexp') {
690 lhs = lhs.toString();
691 rhs = rhs.toString();
692 }
693
694 var ltype = typeof lhs;
695 var rtype = typeof rhs;
696 if (ltype === 'undefined') {
697 if (rtype !== 'undefined') {
698 changes(new DiffNew(currentPath, rhs));
699 }
700 } else if (rtype === 'undefined') {
701 changes(new DiffDeleted(currentPath, lhs));
702 } else if (realTypeOf(lhs) !== realTypeOf(rhs)) {
703 changes(new DiffEdit(currentPath, lhs, rhs));
704 } else if (Object.prototype.toString.call(lhs) === '[object Date]' && Object.prototype.toString.call(rhs) === '[object Date]' && ((lhs - rhs) !== 0)) {
705 changes(new DiffEdit(currentPath, lhs, rhs));
706 } else if (ltype === 'object' && lhs !== null && rhs !== null) {
707 stack = stack || [];
708 if (stack.indexOf(lhs) < 0) {
709 stack.push(lhs);
710 if (Array.isArray(lhs)) {
711 var i, len = lhs.length;
712 for (i = 0; i < lhs.length; i++) {
713 if (i >= rhs.length) {
714 changes(new DiffArray(currentPath, i, new DiffDeleted(undefined, lhs[i])));
715 } else {
716 deepDiff(lhs[i], rhs[i], changes, prefilter, currentPath, i, stack);
717 }
718 }
719 while (i < rhs.length) {
720 changes(new DiffArray(currentPath, i, new DiffNew(undefined, rhs[i++])));
721 }
722 } else {
723 var akeys = Object.keys(lhs);
724 var pkeys = Object.keys(rhs);
725 akeys.forEach(function(k, i) {
726 var other = pkeys.indexOf(k);
727 if (other >= 0) {
728 deepDiff(lhs[k], rhs[k], changes, prefilter, currentPath, k, stack);
729 pkeys = arrayRemove(pkeys, other);
730 } else {
731 deepDiff(lhs[k], undefined, changes, prefilter, currentPath, k, stack);
732 }
733 });
734 pkeys.forEach(function(k) {
735 deepDiff(undefined, rhs[k], changes, prefilter, currentPath, k, stack);
736 });
737 }
738 stack.length = stack.length - 1;
739 }
740 } else if (lhs !== rhs) {
741 if (!(ltype === 'number' && isNaN(lhs) && isNaN(rhs))) {
742 changes(new DiffEdit(currentPath, lhs, rhs));
743 }
744 }
745 }
746
747 function accumulateDiff(lhs, rhs, prefilter, accum) {
748 accum = accum || [];
749 deepDiff(lhs, rhs,
750 function(diff) {
751 if (diff) {
752 accum.push(diff);
753 }
754 },
755 prefilter);
756 return (accum.length) ? accum : undefined;
757 }
758
759 function applyArrayChange(arr, index, change) {
760 if (change.path && change.path.length) {
761 var it = arr[index],
762 i, u = change.path.length - 1;
763 for (i = 0; i < u; i++) {
764 it = it[change.path[i]];
765 }
766 switch (change.kind) {
767 case 'A':
768 applyArrayChange(it[change.path[i]], change.index, change.item);
769 break;
770 case 'D':
771 delete it[change.path[i]];
772 break;
773 case 'E':
774 case 'N':
775 it[change.path[i]] = change.rhs;
776 break;
777 }
778 } else {
779 switch (change.kind) {
780 case 'A':
781 applyArrayChange(arr[index], change.index, change.item);
782 break;
783 case 'D':
784 arr = arrayRemove(arr, index);
785 break;
786 case 'E':
787 case 'N':
788 arr[index] = change.rhs;
789 break;
790 }
791 }
792 return arr;
793 }
794
795 function applyChange(target, source, change) {
796 if (target && source && change && change.kind) {
797 var it = target,
798 i = -1,
799 last = change.path ? change.path.length - 1 : 0;
800 while (++i < last) {
801 if (typeof it[change.path[i]] === 'undefined') {
802 it[change.path[i]] = (typeof change.path[i] === 'number') ? [] : {};
803 }
804 it = it[change.path[i]];
805 }
806 switch (change.kind) {
807 case 'A':
808 applyArrayChange(change.path ? it[change.path[i]] : it, change.index, change.item);
809 break;
810 case 'D':
811 delete it[change.path[i]];
812 break;
813 case 'E':
814 case 'N':
815 it[change.path[i]] = change.rhs;
816 break;
817 }
818 }
819 }
820
821 function revertArrayChange(arr, index, change) {
822 if (change.path && change.path.length) {
823 // the structure of the object at the index has changed...
824 var it = arr[index],
825 i, u = change.path.length - 1;
826 for (i = 0; i < u; i++) {
827 it = it[change.path[i]];
828 }
829 switch (change.kind) {
830 case 'A':
831 revertArrayChange(it[change.path[i]], change.index, change.item);
832 break;
833 case 'D':
834 it[change.path[i]] = change.lhs;
835 break;
836 case 'E':
837 it[change.path[i]] = change.lhs;
838 break;
839 case 'N':
840 delete it[change.path[i]];
841 break;
842 }
843 } else {
844 // the array item is different...
845 switch (change.kind) {
846 case 'A':
847 revertArrayChange(arr[index], change.index, change.item);
848 break;
849 case 'D':
850 arr[index] = change.lhs;
851 break;
852 case 'E':
853 arr[index] = change.lhs;
854 break;
855 case 'N':
856 arr = arrayRemove(arr, index);
857 break;
858 }
859 }
860 return arr;
861 }
862
863 function revertChange(target, source, change) {
864 if (target && source && change && change.kind) {
865 var it = target,
866 i, u;
867 u = change.path.length - 1;
868 for (i = 0; i < u; i++) {
869 if (typeof it[change.path[i]] === 'undefined') {
870 it[change.path[i]] = {};
871 }
872 it = it[change.path[i]];
873 }
874 switch (change.kind) {
875 case 'A':
876 // Array was modified...
877 // it will be an array...
878 revertArrayChange(it[change.path[i]], change.index, change.item);
879 break;
880 case 'D':
881 // Item was deleted...
882 it[change.path[i]] = change.lhs;
883 break;
884 case 'E':
885 // Item was edited...
886 it[change.path[i]] = change.lhs;
887 break;
888 case 'N':
889 // Item is new...
890 delete it[change.path[i]];
891 break;
892 }
893 }
894 }
895
896 function applyDiff(target, source, filter) {
897 if (target && source) {
898 var onChange = function(change) {
899 if (!filter || filter(target, source, change)) {
900 applyChange(target, source, change);
901 }
902 };
903 deepDiff(target, source, onChange);
904 }
905 }
906
907 Object.defineProperties(accumulateDiff, {
908
909 diff: {
910 value: accumulateDiff,
911 enumerable: true
912 },
913 observableDiff: {
914 value: deepDiff,
915 enumerable: true
916 },
917 applyDiff: {
918 value: applyDiff,
919 enumerable: true
920 },
921 applyChange: {
922 value: applyChange,
923 enumerable: true
924 },
925 revertChange: {
926 value: revertChange,
927 enumerable: true
928 },
929 isConflict: {
930 value: function() {
931 return 'undefined' !== typeof conflict;
932 },
933 enumerable: true
934 },
935 noConflict: {
936 value: function() {
937 if (conflictResolution) {
938 conflictResolution.forEach(function(it) {
939 it();
940 });
941 conflictResolution = null;
942 }
943 return accumulateDiff;
944 },
945 enumerable: true
946 }
947 });
948
949 return accumulateDiff;
950 }));
951
952 /* WEBPACK VAR INJECTION */}.call(exports, (function() { return this; }())))
953
954/***/ }
955/******/ ])
956});
957;
\No newline at end of file