Skip to content

Commit

Permalink
try/catch on local storage undo/redo stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
parzival418 committed May 15, 2024
1 parent 49a2434 commit b6c08d6
Showing 1 changed file with 22 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,11 @@ const EventHandler = ({ pubSub, tab, spellId }) => {
currentState.shift()
}

localStorage.setItem(key, JSON.stringify([...currentState, state]))
try {
localStorage.setItem(key, JSON.stringify([...currentState, state]))
} catch (e) {
console.error(e)
}
}

const removeLastUndoState = spellid => {
Expand All @@ -96,7 +100,12 @@ const EventHandler = ({ pubSub, tab, spellId }) => {

addRedoState(spellid, removedState)

localStorage.setItem(key, JSON.stringify(currentState))
try {
localStorage.setItem(key, JSON.stringify(currentState))
} catch (e) {
console.error(e)
return null
}

return removedState
}
Expand All @@ -110,7 +119,11 @@ const EventHandler = ({ pubSub, tab, spellId }) => {
currentState.shift()
}

localStorage.setItem(key, JSON.stringify([...currentState, state]))
try {
localStorage.setItem(key, JSON.stringify([...currentState, state]))
} catch (e) {
console.error(e)
}
}

const removeLastRedoState = spellid => {
Expand All @@ -120,7 +133,12 @@ const EventHandler = ({ pubSub, tab, spellId }) => {

addUndoState(spellid, state)

localStorage.setItem(key, JSON.stringify(currentState))
try {
localStorage.setItem(key, JSON.stringify(currentState))
} catch (e) {
console.error(e)
return null
}

return state
}
Expand Down

0 comments on commit b6c08d6

Please sign in to comment.