DEV: prevents input/change events to cause a full rerender (#8339)

Code should decide when to do something with the event value, and maybe cause a re-rerender but it shouldn't be automatic. This is currently a gigantic waste of resources.
This commit is contained in:
Joffrey JAFFEUX 2019-11-13 15:49:01 +01:00 committed by GitHub
parent a7dd31496e
commit d2d846a88e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -47,10 +47,16 @@ export const WidgetDragHook = buildHook(DRAG_ATTRIBUTE_NAME);
export const WidgetInputHook = buildHook(INPUT_ATTRIBUTE_NAME);
export const WidgetChangeHook = buildHook(CHANGE_ATTRIBUTE_NAME);
function nodeCallback(node, attrName, cb) {
function nodeCallback(node, attrName, cb, options = { rerender: true }) {
const { rerender } = options;
const widget = findWidget(node, attrName);
if (widget) {
widget.rerenderResult(() => cb(widget));
if (rerender) {
widget.rerenderResult(() => cb(widget));
} else {
cb(widget);
}
}
}
@ -173,11 +179,15 @@ WidgetClickHook.setupDocumentCallback = function() {
});
$(document).on("input.discourse-widget", e => {
nodeCallback(e.target, INPUT_ATTRIBUTE_NAME, w => w.input(e));
nodeCallback(e.target, INPUT_ATTRIBUTE_NAME, w => w.input(e), {
rerender: false
});
});
$(document).on("change.discourse-widget", e => {
nodeCallback(e.target, CHANGE_ATTRIBUTE_NAME, w => w.change(e));
nodeCallback(e.target, CHANGE_ATTRIBUTE_NAME, w => w.change(e), {
rerender: false
});
});
_watchingDocument = true;