Enhance: validate local storage (#4784)

* Validate localStorage with spec

This will help get at the source of errors like #4706 quicker

* Fix settings bugs

Close #4679 as shortcut tooltip setting is now visible.
No need to js/alert when a setting is changed. Probably leftover bugging

* Add docs and example of reusing specs in bb task

Co-authored-by: Andelf <andelf@gmail.com>
This commit is contained in:
Gabriel Horner
2022-04-01 03:46:52 -04:00
committed by GitHub
parent 28d3cb4658
commit 0ccbe4d046
8 changed files with 109 additions and 5 deletions

View File

@@ -2,6 +2,8 @@
(:refer-clojure :exclude [get set remove])
(:require [cljs.reader :as reader]
[datascript.transit :as dt]
[frontend.spec.storage :as storage-spec]
[cljs.spec.alpha :as s]
[frontend.util :as util]))
;; TODO: refactor: separate side effects
@@ -12,6 +14,10 @@
(defn set
[key value]
;; Prevent invalid data from being saved into storage
(s/assert ::storage-spec/local-storage
;; Translate key to keyword for spec as not all keys are keywords
{(keyword key) value})
(when-not util/node-test?
(.setItem ^js js/localStorage (name key) (pr-str value))))