FIX: Can force all shadow trees to rerender

This commit is contained in:
Robin Ward 2016-02-16 14:20:16 -05:00
parent 9eed95dc7b
commit 5d9278c098
5 changed files with 27 additions and 12 deletions

View file

@ -1,5 +1,6 @@
import { diff, patch } from 'virtual-dom';
import { WidgetClickHook } from 'discourse/widgets/click-hook';
import { renderedKey } from 'discourse/widgets/widget';
export default Ember.Component.extend({
_tree: null,
@ -51,6 +52,8 @@ export default Ember.Component.extend({
this._afterRender();
this._afterRender = null;
}
renderedKey('*');
}
}

View file

@ -150,9 +150,13 @@ export default MountWidget.extend({
$('button.widget-button').removeClass('d-hover');
});
this.appEvents.on('post-stream:refresh', postId => {
if (postId) {
keyDirty(`post-${postId}`);
this.appEvents.on('post-stream:refresh', args => {
if (args) {
if (args.id) {
keyDirty(`post-${args.id}`);
} else if (args.force) {
keyDirty(`*`);
}
}
this.queueRerender();
});

View file

@ -310,7 +310,7 @@ export default Ember.Controller.extend(SelectedPostsCount, BufferedContent, {
} else {
return this.get("model").toggleBookmark().then(changedIds => {
if (!changedIds) { return; }
changedIds.forEach(id => this.appEvents.trigger('post-stream:refresh', id));
changedIds.forEach(id => this.appEvents.trigger('post-stream:refresh', { id }));
});
}
},
@ -326,14 +326,14 @@ export default Ember.Controller.extend(SelectedPostsCount, BufferedContent, {
selectedPosts.addObjects(posts);
}
this.set('allPostsSelected', true);
this.appEvents.trigger('post-stream:refresh');
this.appEvents.trigger('post-stream:refresh', { force: true });
},
deselectAll() {
this.get('selectedPosts').clear();
this.get('selectedReplies').clear();
this.set('allPostsSelected', false);
this.appEvents.trigger('post-stream:refresh');
this.appEvents.trigger('post-stream:refresh', { force: true });
},
toggleParticipant(user) {
@ -354,7 +354,7 @@ export default Ember.Controller.extend(SelectedPostsCount, BufferedContent, {
toggleMultiSelect() {
this.toggleProperty('multiSelect');
this.appEvents.trigger('post-stream:refresh');
this.appEvents.trigger('post-stream:refresh', { force: true });
},
finishedEditingTopic() {
@ -643,7 +643,7 @@ export default Ember.Controller.extend(SelectedPostsCount, BufferedContent, {
// Unsubscribe before subscribing again
this.unsubscribe();
const refresh = (id) => this.appEvents.trigger('post-stream:refresh', id);
const refresh = (id) => this.appEvents.trigger('post-stream:refresh', { id });
this.messageBus.subscribe("/topic/" + this.get('model.id'), data => {
const topic = this.get('model');
@ -729,7 +729,7 @@ export default Ember.Controller.extend(SelectedPostsCount, BufferedContent, {
postStream.get('posts').forEach(post => {
if (!post.read && postNumbers.indexOf(post.post_number) !== -1) {
post.set('read', true);
this.appEvents.trigger('post-stream:refresh', post.id);
this.appEvents.trigger('post-stream:refresh', { id: post.id });
}
});

View file

@ -228,7 +228,7 @@ export default {
// TODO: Use ember closure actions
const result = topicController._actions[action].call(topicController, post);
if (result && result.then) {
this.appEvents.trigger('post-stream:refresh', selectedPostId);
this.appEvents.trigger('post-stream:refresh', { id: selectedPostId });
}
}
}

View file

@ -4,12 +4,16 @@ import { h } from 'virtual-dom';
function emptyContent() { }
const _registry = {};
const _dirty = {};
let _dirty = {};
export function keyDirty(key) {
_dirty[key] = true;
}
export function renderedKey(key) {
delete _dirty[key];
}
function drawWidget(builder, attrs, state) {
const properties = {};
@ -95,7 +99,11 @@ export default class Widget {
if (prev && prev.shadowTree) {
this.shadowTree = true;
if (!_dirty[prev.key]) { return prev.vnode; }
if (!_dirty[prev.key] && !_dirty['*']) {
return prev.vnode;
}
renderedKey(prev.key);
}
return this.draw(h, this.attrs, this.state);