Debug
This commit is contained in:
@@ -22,7 +22,7 @@ export function usePolicyUpdateState({
|
|||||||
}) {
|
}) {
|
||||||
const nux = useNux(ACTIVE_UPDATE_ID)
|
const nux = useNux(ACTIVE_UPDATE_ID)
|
||||||
const {mutate: save, variables} = useSaveNux()
|
const {mutate: save, variables} = useSaveNux()
|
||||||
const deviceStorage = useStorage(device, [ACTIVE_UPDATE_ID])
|
const deviceStorage = useStorage(device, [ACTIVE_UPDATE_ID], 'usePolicyUpdateState')
|
||||||
const debugOverride =
|
const debugOverride =
|
||||||
!!useStorage(device, ['policyUpdateDebugOverride'])[0] && IS_DEV
|
!!useStorage(device, ['policyUpdateDebugOverride'])[0] && IS_DEV
|
||||||
|
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ import {useCallback, useEffect, useState} from 'react'
|
|||||||
import {MMKV} from 'react-native-mmkv'
|
import {MMKV} from 'react-native-mmkv'
|
||||||
|
|
||||||
import {type Account, type Device} from '#/storage/schema'
|
import {type Account, type Device} from '#/storage/schema'
|
||||||
|
import {logger} from '#/components/PolicyUpdateOverlay/logger'
|
||||||
|
|
||||||
export * from '#/storage/schema'
|
export * from '#/storage/schema'
|
||||||
|
|
||||||
@@ -105,6 +106,7 @@ export function useStorage<
|
|||||||
>(
|
>(
|
||||||
storage: Store,
|
storage: Store,
|
||||||
scopes: [...StorageScopes<Store>, Key],
|
scopes: [...StorageScopes<Store>, Key],
|
||||||
|
debug?: string
|
||||||
): [
|
): [
|
||||||
StorageSchema<Store>[Key] | undefined,
|
StorageSchema<Store>[Key] | undefined,
|
||||||
(data: StorageSchema<Store>[Key]) => void,
|
(data: StorageSchema<Store>[Key]) => void,
|
||||||
@@ -116,6 +118,9 @@ export function useStorage<
|
|||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const sub = storage.addOnValueChangedListener(scopes, () => {
|
const sub = storage.addOnValueChangedListener(scopes, () => {
|
||||||
|
if (debug) logger.debug(`${debug} - storage change`, {
|
||||||
|
value: storage.get(scopes) ?? 'unset',
|
||||||
|
})
|
||||||
setValue(storage.get(scopes))
|
setValue(storage.get(scopes))
|
||||||
})
|
})
|
||||||
return () => sub.remove()
|
return () => sub.remove()
|
||||||
@@ -129,6 +134,11 @@ export function useStorage<
|
|||||||
[storage, scopes],
|
[storage, scopes],
|
||||||
)
|
)
|
||||||
|
|
||||||
|
if (debug) logger.debug(`${debug}`, {
|
||||||
|
value: value ?? 'unset',
|
||||||
|
raw: storage.get(scopes) ?? 'unset',
|
||||||
|
})
|
||||||
|
|
||||||
return [value, setter] as const
|
return [value, setter] as const
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user