Skip to content

Instantly share code, notes, and snippets.

@mikeapr4
Created November 7, 2019 18:28
Show Gist options
  • Save mikeapr4/7e6fd89bc7635ae98824eae36a30aca2 to your computer and use it in GitHub Desktop.
Save mikeapr4/7e6fd89bc7635ae98824eae36a30aca2 to your computer and use it in GitHub Desktop.
Suspend Mixin to stop/start component re-rendering
/* 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