Skip to content

Instantly share code, notes, and snippets.

@jasonmit
Last active February 12, 2016 22:22
Show Gist options
  • Save jasonmit/6023f19b5b899bd61e3e to your computer and use it in GitHub Desktop.
Save jasonmit/6023f19b5b899bd61e3e to your computer and use it in GitHub Desktop.
// WARNING: DO NOT USE.
// When isDisabled is truthy, count will freeze in the DOM
// {{#hide-rerendering isDisabled}}
// {{count}}
// {{/hide-rerendering}}
import Ember from 'ember';
import hbs from 'htmlbars-inline-precompile';
const { Component, run, set, get } = Ember;
const PreventRender = Component.extend({
'is-blocking': false,
'prevent-render': false,
init() {
this._super(...arguments);
this.release = Ember.K;
},
disableRendering() {
if (get(this, 'is-blocking')) { return; }
set(this, 'is-blocking', true);
const child = this.$();
const pos = child.position();
const clone = child.clone();
child.css({ display: 'none' });
clone.removeAttr('id').insertBefore(child);
this.release = () => {
clone.remove();
child.css({ display: '' });
this.release = Ember.K;
set(this, 'is-blocking', false);
};
},
didReceiveAttrs() {
this._super(...arguments);
const prevent = get(this, 'prevent-render');
if (prevent) {
this.scheduled = run.scheduleOnce('afterRender', this, 'disableRendering');
} else if (get(this, 'is-blocking')) {
this.scheduled = run.scheduleOnce('afterRender', this, 'release');
}
},
willDestroyElement() {
run.cancel(this.scheduled);
this.release();
this._super(...arguments);
}
});
PreventRender.reopenClass({
positionalParams: ['prevent-render']
});
export default PreventRender;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment