mirror of
https://github.com/rstudio/shiny.git
synced 2026-01-14 09:28:02 -05:00
Properly handle undefined value for input subscribe callback (#4243)
* Close #4240: properly handle undefined value for input subscribe callback * Refactor normalization into a function
This commit is contained in:
@@ -5619,9 +5619,22 @@
|
||||
const type = binding.getType(el);
|
||||
if (type)
|
||||
id = id + ":" + type;
|
||||
inputs.setInput(id, value, { priority, binding, el });
|
||||
const normalizedPriority = normalizeEventPriority(priority);
|
||||
inputs.setInput(id, value, { priority: normalizedPriority, binding, el });
|
||||
}
|
||||
}
|
||||
function normalizeEventPriority(priority) {
|
||||
if (priority === false || priority === void 0) {
|
||||
return "immediate";
|
||||
}
|
||||
if (priority === true) {
|
||||
return "deferred";
|
||||
}
|
||||
if (typeof priority === "object" && "priority" in priority) {
|
||||
return priority.priority;
|
||||
}
|
||||
return priority;
|
||||
}
|
||||
var bindingsRegistry = (() => {
|
||||
const bindings = /* @__PURE__ */ new Map();
|
||||
function checkValidity(scope) {
|
||||
@@ -5735,17 +5748,7 @@ ${duplicateIdMsg}`;
|
||||
const thisBinding = binding;
|
||||
const thisEl = el;
|
||||
return function(priority) {
|
||||
let normalizedPriority;
|
||||
if (priority === true) {
|
||||
normalizedPriority = "deferred";
|
||||
} else if (priority === false) {
|
||||
normalizedPriority = "immediate";
|
||||
} else if (typeof priority === "object" && "priority" in priority) {
|
||||
normalizedPriority = priority.priority;
|
||||
} else {
|
||||
normalizedPriority = priority;
|
||||
}
|
||||
valueChangeCallback(inputs, thisBinding, thisEl, normalizedPriority);
|
||||
valueChangeCallback(inputs, thisBinding, thisEl, priority);
|
||||
};
|
||||
}();
|
||||
binding.subscribe(el, thisCallback);
|
||||
|
||||
File diff suppressed because one or more lines are too long
24
inst/www/shared/shiny.min.js
vendored
24
inst/www/shared/shiny.min.js
vendored
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
@@ -29,7 +29,7 @@ function valueChangeCallback(
|
||||
inputs: InputValidateDecorator,
|
||||
binding: InputBinding,
|
||||
el: HTMLElement,
|
||||
priority: EventPriority
|
||||
priority?: SubscribeEventPriority
|
||||
) {
|
||||
let id = binding.getId(el);
|
||||
|
||||
@@ -39,10 +39,32 @@ function valueChangeCallback(
|
||||
|
||||
if (type) id = id + ":" + type;
|
||||
|
||||
inputs.setInput(id, value, { priority, binding, el });
|
||||
// Normalize the priority to a valid EventPriority
|
||||
const normalizedPriority = normalizeEventPriority(priority);
|
||||
|
||||
inputs.setInput(id, value, { priority: normalizedPriority, binding, el });
|
||||
}
|
||||
}
|
||||
|
||||
// Narrow the type of the subscribe callback value to EventPriority
|
||||
function normalizeEventPriority(
|
||||
priority?: SubscribeEventPriority
|
||||
): EventPriority {
|
||||
if (priority === false || priority === undefined) {
|
||||
return "immediate";
|
||||
}
|
||||
|
||||
if (priority === true) {
|
||||
return "deferred";
|
||||
}
|
||||
|
||||
if (typeof priority === "object" && "priority" in priority) {
|
||||
return priority.priority;
|
||||
}
|
||||
|
||||
return priority;
|
||||
}
|
||||
|
||||
/**
|
||||
* Registry for input and output binding IDs. Used to check for duplicate IDs
|
||||
* and to keep track of which IDs have already been added to the app. Use an
|
||||
@@ -264,20 +286,8 @@ function bindInputs(
|
||||
const thisBinding = binding;
|
||||
const thisEl = el;
|
||||
|
||||
return function (priority: SubscribeEventPriority) {
|
||||
// Narrow the type of priority to EventPriority
|
||||
let normalizedPriority: EventPriority;
|
||||
if (priority === true) {
|
||||
normalizedPriority = "deferred";
|
||||
} else if (priority === false) {
|
||||
normalizedPriority = "immediate";
|
||||
} else if (typeof priority === "object" && "priority" in priority) {
|
||||
normalizedPriority = priority.priority;
|
||||
} else {
|
||||
normalizedPriority = priority;
|
||||
}
|
||||
|
||||
valueChangeCallback(inputs, thisBinding, thisEl, normalizedPriority);
|
||||
return function (priority?: SubscribeEventPriority) {
|
||||
valueChangeCallback(inputs, thisBinding, thisEl, priority);
|
||||
};
|
||||
})();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user