Skip to content

Commit

Permalink
minor localStorage refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
pedroth committed Nov 29, 2023
1 parent 27d0d14 commit 3b3d622
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ const { tokenizer } = await import(NABLA_WORD + "/dist/web/Lexer.js");
* */
//========================================================================================

const nablaLocalStorage = () => {
const NablaLocalStorage = (() => {
const namespace = "nabladown";
return {
getItem: key => {
Expand All @@ -29,7 +29,7 @@ const nablaLocalStorage = () => {
return this;
}
};
};
})();

//========================================================================================
/* *
Expand Down Expand Up @@ -86,7 +86,7 @@ async function getInput() {
const NABLA_DOC_ADDRESS = "/test/resources/test2.nd";
return (
getURLData() ||
nablaLocalStorage().getItem("input") ||
NablaLocalStorage.getItem("input") ||
await fetch(NABLA_DOC_ADDRESS)
.then(data => {
if (!data.ok) return fetch(NABLA_WORD + NABLA_DOC_ADDRESS)
Expand All @@ -99,7 +99,7 @@ async function getInput() {


function getSelectedRenderName() {
return nablaLocalStorage().getItem("selectedRender") || "Nabla";
return NablaLocalStorage.getItem("selectedRender") || "Nabla";
}

function downloadNablaDownURL(output) {
Expand Down Expand Up @@ -140,7 +140,7 @@ function renderFactory({ selectedRender, exportHTMLIcon, output }) {
// render function
return async (tree, input) => {
// save previous scroll before removing children
const previousScroll = nablaLocalStorage().getItem("outputScroll");
const previousScroll = NablaLocalStorage.getItem("outputScroll");
removeAllChildNodes(output);
const [outputDOM, time] = await getTimedValue(async () => await selectedRender(tree, input))
output.appendChild(outputDOM);
Expand Down Expand Up @@ -180,7 +180,7 @@ function addEditorEventListener({
editor.onDidChangeModelContent(
debounce(() => {
const newInput = editor.getValue();
nablaLocalStorage().setItem("input", newInput);
NablaLocalStorage.setItem("input", newInput);
maybeParserWorker
.map(parseWorker => {
parseWorker.postMessage(newInput);
Expand Down Expand Up @@ -254,7 +254,7 @@ function renderOutputSelector(props) {
exportHTMLIcon,
output
});
nablaLocalStorage().setItem("selectedRender", renderName);
NablaLocalStorage.setItem("selectedRender", renderName);
const input = editor.getValue();
selectedRender(parse(input), input);
});
Expand Down Expand Up @@ -374,7 +374,7 @@ async function renderInputOutput() {

const output = document.createElement("div");
output.addEventListener("scroll", e => {
nablaLocalStorage().setItem("outputScroll", e.target.scrollTop);
NablaLocalStorage.setItem("outputScroll", e.target.scrollTop);
});
output.setAttribute("class", "output");

Expand Down

0 comments on commit 3b3d622

Please sign in to comment.