Can values be persisted across sessions? My use-case is to persist some slider values as I explore them.
Since localStorage
does not work in a sandboxed iframe—nor should it—I was wondering if adding a Storage
API to the standard library would be appropriate.
It could potentially postMessage
to the parent frame to save/load localStorage
values namespaced to the current notebook. So persisting a slider value might look like this:
viewof x = {
const range = html`<input type=range min=0 max=100>`;
range.value = 50; // default value
const key = 'myval';
range.addEventListener("input", () => Storage.save(key, range.value));
Storage.load(key).then(value => {
range.value = value; // load persisted value
range.dispatchEvent(new Event('input'));
});
return range;
}