UNPKG

immutable-di-history

Version:
48 lines (40 loc) 1.21 kB
'use strict'; Object.defineProperty(exports, '__esModule', { value: true }); exports['default'] = StateMonitor; function filterArgs(args) { var result = args; try { JSON.stringify(args); } catch (e) { result = args.map(function (arg) { return typeof arg === 'function' || typeof arg === 'object' ? '[circular]' : arg; }); } return result; } function StateMonitor(_ref) { var cursor = _ref.cursor; var historyPath = _ref.historyPath; var historyCursor = cursor.select([historyPath]); historyCursor.set([]); return function stateMonitor(_ref2, args) { var displayName = _ref2.displayName; var id = _ref2.id; var prevState = cursor.snap(); return function stop() { var diff = cursor.diff(prevState, [historyPath]); historyCursor.apply(function (h) { return h.concat([{ displayName: displayName, id: id, args: filterArgs(args), diff: diff }]); }); }; }; } module.exports = exports['default']; //# sourceMappingURL=StateMonitor.js.map