From fe50d1a774a9a9033adca0c854aee60250057cb0 Mon Sep 17 00:00:00 2001 From: dmason30 Date: Tue, 18 Jul 2023 18:34:43 +0100 Subject: [PATCH] wip --- dist/js/index.js | 2 +- resources/js/index.js | 24 ++++++++++++++++++------ 2 files changed, 19 insertions(+), 7 deletions(-) diff --git a/dist/js/index.js b/dist/js/index.js index f40e68b..9b0abe2 100644 --- a/dist/js/index.js +++ b/dist/js/index.js @@ -1 +1 @@ -Nova.bootingCallbacks.unshift((function(n){n.mixin({data:function(){return{pollingListener:null}},mounted:function(){var n,i,t=this;null!==(n=this.$props)&&void 0!==n&&null!==(n=n.card)&&void 0!==n&&n.pollingInterval&&"function"==typeof this.fetch&&(this.pollingListener=setInterval((function(){t.fetch()}),null===(i=this.$props)||void 0===i||null===(i=i.card)||void 0===i?void 0:i.pollingInterval))},unmounted:function(){clearInterval(this.pollingListener)}})})); \ No newline at end of file +Nova.bootingCallbacks.unshift((function(n){n.mixin({data:function(){return{pollingListener:null}},mounted:function(){this.addCardPollingIntervalListener()},unmounted:function(){this.removeCardPollingIntervalListener()},updated:function(){this.addCardPollingIntervalListener()},methods:{addCardPollingIntervalListener:function(){var n,t,i=this;null!==(n=this.$props)&&void 0!==n&&null!==(n=n.card)&&void 0!==n&&n.pollingInterval&&"function"==typeof this.fetch&&(this.removeCardPollingIntervalListener(),this.pollingListener=setInterval((function(){i.fetch()}),null===(t=this.$props)||void 0===t||null===(t=t.card)||void 0===t?void 0:t.pollingInterval))},removeCardPollingIntervalListener:function(){clearInterval(this.pollingListener)}}})})); \ No newline at end of file diff --git a/resources/js/index.js b/resources/js/index.js index 06e341f..c924f09 100644 --- a/resources/js/index.js +++ b/resources/js/index.js @@ -5,14 +5,26 @@ Nova.bootingCallbacks.unshift((app) => { pollingListener: null, }), mounted() { - if (this.$props?.card?.pollingInterval && typeof this.fetch === 'function') { - this.pollingListener = setInterval(() => { - this.fetch(); - }, this.$props?.card?.pollingInterval); - } + this.addCardPollingIntervalListener(); }, unmounted() { - clearInterval(this.pollingListener); + this.removeCardPollingIntervalListener(); + }, + updated() { + this.addCardPollingIntervalListener(); }, + methods: { + addCardPollingIntervalListener() { + if (this.$props?.card?.pollingInterval && typeof this.fetch === 'function') { + this.removeCardPollingIntervalListener(); + this.pollingListener = setInterval(() => { + this.fetch(); + }, this.$props?.card?.pollingInterval); + } + }, + removeCardPollingIntervalListener() { + clearInterval(this.pollingListener); + } + } }); });