mirror of
https://github.com/discourse/discourse.git
synced 2025-02-25 18:55:32 -06:00
Migrate Discourse Polls to use vdom instead of embedded ember
This commit is contained in:
@@ -110,6 +110,7 @@ export default Ember.Component.extend({
|
||||
const opts = { model: this.get('model') };
|
||||
const newTree = new this._widgetClass(args, this.register, opts);
|
||||
|
||||
newTree._rerenderable = this;
|
||||
newTree._emberView = this;
|
||||
const patches = diff(this._tree || this._rootNode, newTree);
|
||||
|
||||
|
||||
43
app/assets/javascripts/discourse/widgets/glue.js.es6
Normal file
43
app/assets/javascripts/discourse/widgets/glue.js.es6
Normal file
@@ -0,0 +1,43 @@
|
||||
import { diff, patch } from 'virtual-dom';
|
||||
import { queryRegistry } from 'discourse/widgets/widget';
|
||||
|
||||
export default class WidgetGlue {
|
||||
|
||||
constructor(name, register, attrs) {
|
||||
this._tree = null;
|
||||
this._rootNode = null;
|
||||
this.register = register;
|
||||
this.attrs = attrs;
|
||||
this._timeout = null;
|
||||
|
||||
this._widgetClass = queryRegistry(name) || this.register.lookupFactory(`widget:${name}`);
|
||||
if (!this._widgetClass) {
|
||||
console.error(`Error: Could not find widget: ${name}`);
|
||||
}
|
||||
}
|
||||
|
||||
appendTo(elem) {
|
||||
this._rootNode = elem;
|
||||
this.queueRerender();
|
||||
}
|
||||
|
||||
queueRerender() {
|
||||
this._timeout = Ember.run.scheduleOnce('render', this, this.rerenderWidget);
|
||||
}
|
||||
|
||||
rerenderWidget() {
|
||||
Ember.run.cancel(this._timeout);
|
||||
const newTree = new this._widgetClass(this.attrs, this.register);
|
||||
const patches = diff(this._tree || this._rootNode, newTree);
|
||||
|
||||
newTree._rerenderable = this;
|
||||
this._rootNode = patch(this._rootNode, patches);
|
||||
this._tree = newTree;
|
||||
}
|
||||
|
||||
cleanUp() {
|
||||
Ember.run.cancel(this._timeout);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -246,10 +246,11 @@ export default class Widget {
|
||||
keyDirty(widget.key);
|
||||
}
|
||||
|
||||
const emberView = widget._emberView;
|
||||
if (emberView) {
|
||||
return emberView.queueRerender();
|
||||
const rerenderable = widget._rerenderable;
|
||||
if (rerenderable) {
|
||||
return rerenderable.queueRerender();
|
||||
}
|
||||
|
||||
widget = widget.parentWidget;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user