Use consistent value caching format

This commit is contained in:
Winston Chang
2017-03-10 12:03:24 -06:00
parent 306f33dfc4
commit 7a833456d9
5 changed files with 51 additions and 15 deletions

View File

@@ -216,7 +216,7 @@ var InputBatchSender = function(shinyapp) {
var InputNoResendDecorator = function(target, initialValues) {
this.target = target;
this.lastSentValues = initialValues || {};
this.lastSentValues = this.reset(initialValues);
};
(function() {
this.setInput = function(name, value) {
@@ -235,10 +235,25 @@ var InputNoResendDecorator = function(target, initialValues) {
this.lastSentValues[inputName] = { jsonValue, inputType };
this.target.setInput(name, value);
};
this.reset = function(values) {
values = values || {};
var strValues = values;
this.lastSentValues = strValues;
this.reset = function(values = {}) {
// Given an object with flat name-value format:
// { x: "abc", "y.shiny.number": 123 }
// Create an object in cache format and save it:
// { x: { jsonValue: '"abc"', inputType: "" },
// y: { jsonValue: "123", inputType: "shiny.number" } }
const cacheValues = {};
for (let inputName in values) {
if (values.hasOwnProperty(inputName)) {
let { name, inputType } = splitInputNameType(inputName);
cacheValues[name] = {
jsonValue: JSON.stringify(values[inputName]),
inputType: inputType
};
}
}
this.lastSentValues = cacheValues;
};
}).call(InputNoResendDecorator.prototype);