From e637c96078fb0514478e9c26dc80d7e2185fbe28 Mon Sep 17 00:00:00 2001 From: Michael Peake Date: Wed, 6 Mar 2019 13:21:33 +0000 Subject: [PATCH 1/4] only Main process tries to set state --- dist/persisted-state.js | 2 +- src/persisted-state.js | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/dist/persisted-state.js b/dist/persisted-state.js index af4dc12..4a3e7dd 100644 --- a/dist/persisted-state.js +++ b/dist/persisted-state.js @@ -1 +1 @@ -"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.default=void 0;var _deepmerge=_interopRequireDefault(require("deepmerge")),_electronStore=_interopRequireDefault(require("electron-store"));function _interopRequireDefault(a){return a&&a.__esModule?a:{default:a}}function _classCallCheck(a,b){if(!(a instanceof b))throw new TypeError("Cannot call a class as a function")}function _defineProperties(a,b){for(var c,d=0;d Date: Wed, 13 Nov 2019 17:40:28 +0000 Subject: [PATCH 2/4] added throttle option to persisted-state --- dist/index.js | 2 +- dist/persisted-state.js | 2 +- dist/shared-mutations.js | 2 +- src/persisted-state.js | 18 +++++++++++++++++- 4 files changed, 20 insertions(+), 4 deletions(-) diff --git a/dist/index.js b/dist/index.js index fb5c3ec..a7a7b00 100644 --- a/dist/index.js +++ b/dist/index.js @@ -1 +1 @@ -"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),Object.defineProperty(exports,"createPersistedState",{enumerable:!0,get:function a(){return _persistedState.default}}),Object.defineProperty(exports,"createSharedMutations",{enumerable:!0,get:function a(){return _sharedMutations.default}});var _persistedState=_interopRequireDefault(require("./persisted-state")),_sharedMutations=_interopRequireDefault(require("./shared-mutations"));function _interopRequireDefault(a){return a&&a.__esModule?a:{default:a}} \ No newline at end of file +"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),Object.defineProperty(exports,"createPersistedState",{enumerable:!0,get:function get(){return _persistedState["default"]}}),Object.defineProperty(exports,"createSharedMutations",{enumerable:!0,get:function get(){return _sharedMutations["default"]}});var _persistedState=_interopRequireDefault(require("./persisted-state")),_sharedMutations=_interopRequireDefault(require("./shared-mutations"));function _interopRequireDefault(a){return a&&a.__esModule?a:{default:a}} \ No newline at end of file diff --git a/dist/persisted-state.js b/dist/persisted-state.js index 4a3e7dd..3b8cb6e 100644 --- a/dist/persisted-state.js +++ b/dist/persisted-state.js @@ -1 +1 @@ -"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.default=void 0;var _deepmerge=_interopRequireDefault(require("deepmerge")),_electronStore=_interopRequireDefault(require("electron-store"));function _interopRequireDefault(a){return a&&a.__esModule?a:{default:a}}function _classCallCheck(a,b){if(!(a instanceof b))throw new TypeError("Cannot call a class as a function")}function _defineProperties(a,b){for(var c,d=0;dlast+a.options.throttle?(last=e,a.setState(d)):(clearTimeout(b),b=setTimeout(function(){return a.setState(d)},a.options.throttle))}else a.setState(d)})}}]),a}(),_default=function(){var a=0 { if (this.blacklist && this.blacklist(mutation)) return if (this.whitelist && !this.whitelist(mutation)) return - this.setState(state) + if (this.options.throttle) { + const now = Date.now() + if (!last || now > last + this.options.throttle) { + last = now + this.setState(state) + } else { + clearTimeout(trailingEventTimeout) + trailingEventTimeout = setTimeout(() => this.setState(state), this.options.throttle) + } + } else { + this.setState(state) + } }) } } From 7091990b302757400dc7393d768da6fe3b6f35e4 Mon Sep 17 00:00:00 2001 From: Michael Peake Date: Tue, 3 Dec 2019 16:35:32 +0000 Subject: [PATCH 3/4] fixed misnamed variable --- src/persisted-state.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/persisted-state.js b/src/persisted-state.js index 74196d0..cf6ed12 100644 --- a/src/persisted-state.js +++ b/src/persisted-state.js @@ -101,8 +101,8 @@ class PersistedState { if (this.options.throttle) { const now = Date.now() - if (!last || now > last + this.options.throttle) { - last = now + if (!lastSetStateDate || now > lastSetStateDate + this.options.throttle) { + lastSetStateDate = now this.setState(state) } else { clearTimeout(trailingEventTimeout) From 27a19cb70c58738a69cdd24e31125046c766a399 Mon Sep 17 00:00:00 2001 From: Michael Date: Mon, 9 Dec 2019 12:07:06 +0000 Subject: [PATCH 4/4] forgot to rebuild --- dist/persisted-state.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dist/persisted-state.js b/dist/persisted-state.js index 3b8cb6e..d8d87d8 100644 --- a/dist/persisted-state.js +++ b/dist/persisted-state.js @@ -1 +1 @@ -"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports["default"]=void 0;var _deepmerge=_interopRequireDefault(require("deepmerge")),_electronStore=_interopRequireDefault(require("electron-store"));function _interopRequireDefault(a){return a&&a.__esModule?a:{default:a}}function _classCallCheck(a,b){if(!(a instanceof b))throw new TypeError("Cannot call a class as a function")}function _defineProperties(a,b){for(var c,d=0;dlast+a.options.throttle?(last=e,a.setState(d)):(clearTimeout(b),b=setTimeout(function(){return a.setState(d)},a.options.throttle))}else a.setState(d)})}}]),a}(),_default=function(){var a=0b+a.options.throttle?(b=f,a.setState(e)):(clearTimeout(c),c=setTimeout(function(){return a.setState(e)},a.options.throttle))}else a.setState(e)})}}]),a}(),_default=function(){var a=0