The API documentation does not include reduce
as an option for file inputs. Does that exclude me from being able to invoke a function in the same manners as for, e.g. a button Input?
I have a working approach, but I sense it’s not correct because after adding an input, all cells referencing the mutable appear to be perpetually reloading:
Here’s the notebook: Mutating when Adding File Attachment / Aaron Kyle Dennis | Observable
reduce
is exclusive to Inputs.button
where it lets you update a state (e.g. a counter).
What problem are you trying to solve that requires a Mutable
, instead of just an intermediate cell like
viewof file = ...
data = swap_data(file.json())
?
A function defined in this way would automatically execute on page load (returning null) would it not? I am trying to have three inputs (two buttons and a file attachment) all effect changes to an active ‘state_data’ variable, which I load from local storage and don’t wish to clobber on page load. Directly referencing the file input before selecting a file returns a null value, which breaks my inputs. I am looking for a way to update only after a user selects a file.
It’s messy, but here’s where I have been working on the concept: Data Mutation and Persistence / Aaron Kyle Dennis | Observable
Thank you for promoting me to work more on this. I updated the sandbox notebook above to better clarify / demonstrate the problem. In the process, I found a solution that works:
(async function(d) {
return d === null ? "pending file selection" : mutable state_data = await d.json();
})(local_data);