Created
November 7, 2019 18:28
-
-
Save mikeapr4/7e6fd89bc7635ae98824eae36a30aca2 to your computer and use it in GitHub Desktop.
Suspend Mixin to stop/start component re-rendering
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* eslint-disable no-underscore-dangle */ | |
export default (computedName) => ({ | |
watch: { | |
// We add in a mechanism to delay re-render of this component | |
// depending on derived reactive data. | |
[computedName](val) { | |
const render = this._watcher; | |
if (render && val) { | |
this._suspendGetter = render.getter; | |
render.getter = () => { render.dirty = true; }; | |
} else if (this._suspendGetter) { | |
render.getter = this._suspendGetter; | |
delete this._suspendGetter; | |
if (render.dirty) { | |
render.dirty = false; | |
render.update(); | |
} | |
} | |
}, | |
}, | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment