mirror of
https://github.com/jcwimer/wrestlingApp
synced 2026-04-11 16:01:56 +00:00
40 lines
854 B
JavaScript
40 lines
854 B
JavaScript
export function loadJson(storage, key) {
|
|
try {
|
|
const rawValue = storage.getItem(key)
|
|
if (!rawValue) return null
|
|
return JSON.parse(rawValue)
|
|
} catch (_error) {
|
|
return null
|
|
}
|
|
}
|
|
|
|
export function saveJson(storage, key, value) {
|
|
try {
|
|
storage.setItem(key, JSON.stringify(value))
|
|
return true
|
|
} catch (_error) {
|
|
return false
|
|
}
|
|
}
|
|
|
|
export function removeKey(storage, key) {
|
|
try {
|
|
storage.removeItem(key)
|
|
return true
|
|
} catch (_error) {
|
|
return false
|
|
}
|
|
}
|
|
|
|
export function performIfChanged(subscription, action, payload, lastSerializedPayload) {
|
|
if (!subscription) return lastSerializedPayload
|
|
|
|
const serializedPayload = JSON.stringify(payload)
|
|
if (serializedPayload === lastSerializedPayload) {
|
|
return lastSerializedPayload
|
|
}
|
|
|
|
subscription.perform(action, payload)
|
|
return serializedPayload
|
|
}
|