Skip to content

Commit

Permalink
chore: storage delete JSONR
Browse files Browse the repository at this point in the history
  • Loading branch information
molvqingtai committed Nov 6, 2024
1 parent 893342a commit 7681682
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 23 deletions.
1 change: 0 additions & 1 deletion src/domain/Room.ts
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,6 @@ const RoomDomain = Remesh.domain({
name: 'Room.SendSyncHistoryMessageCommand',
impl: ({ get }, { peerId, lastMessageTime }: { peerId: string; lastMessageTime: number }) => {
const self = get(SelfUserQuery())
console.log('SendSyncHistoryMessageCommand', peerId, peerRoom.peerId)

const historyMessages = get(messageListDomain.query.ListQuery()).filter(
(message) =>
Expand Down
33 changes: 11 additions & 22 deletions src/domain/impls/Storage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,11 @@ import { webExtensionDriver } from '@/utils/webExtensionDriver'

import { Storage } from '@/domain/externs/Storage'
import { EVENT } from '@/constants/event'
import { JSONR } from '@/utils'

/**
* Waiting to be resolved
* @see https://github.com/unjs/unstorage/issues/277
* */

export const localStorage = createStorage({
driver: localStorageDriver({ base: `${STORAGE_NAME}:` })
Expand All @@ -23,8 +27,8 @@ export const browserSyncStorage = createStorage({

export const LocalStorageImpl = LocalStorageExtern.impl({
name: STORAGE_NAME,
get: async (key) => JSONR.parse(await localStorage.getItem(key)),
set: (key, value) => localStorage.setItem(key, JSONR.stringify(value)),
get: localStorage.getItem,
set: localStorage.setItem,
remove: localStorage.removeItem,
clear: localStorage.clear,
watch: async (callback) => {
Expand All @@ -46,14 +50,8 @@ export const LocalStorageImpl = LocalStorageExtern.impl({

export const IndexDBStorageImpl = IndexDBStorageExtern.impl({
name: STORAGE_NAME,
get: async (key) => JSONR.parse(await indexDBStorage.getItem(key)),
set: (key, value) => {
/**
* Waiting to be resolved
* @see https://github.com/unjs/unstorage/issues/277
* */
return indexDBStorage.setItem(key, JSONR.stringify(value))
},
get: indexDBStorage.getItem,
set: indexDBStorage.setItem,
remove: indexDBStorage.removeItem,
clear: indexDBStorage.clear,
watch: indexDBStorage.watch as Storage['watch'],
Expand All @@ -62,17 +60,8 @@ export const IndexDBStorageImpl = IndexDBStorageExtern.impl({

export const BrowserSyncStorageImpl = BrowserSyncStorageExtern.impl({
name: STORAGE_NAME,
get: async (key) => {
const value: any = await browserSyncStorage.getItem(key)

// Compatibility with old version data
try {
return JSONR.parse(value)
} catch {
return value
}
},
set: (key, value) => browserSyncStorage.setItem(key, JSONR.stringify(value)),
get: browserSyncStorage.getItem,
set: browserSyncStorage.setItem,
remove: browserSyncStorage.removeItem,
clear: browserSyncStorage.clear,
watch: browserSyncStorage.watch as Storage['watch'],
Expand Down

0 comments on commit 7681682

Please sign in to comment.