-
-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
52 additions
and
4 deletions.
There are no files selected for viewing
7 changes: 5 additions & 2 deletions
7
packages/linejs/src/storage/denokv.ts → example/storage/denokv.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
/// <reference lib="dom"/> | ||
|
||
import type { | ||
BaseStorage, | ||
Storage, | ||
} from "../../packages/linejs/src/storage/base.ts"; | ||
export class LocalStorage implements BaseStorage { | ||
prefix = "linejs:"; | ||
constructor() { | ||
} | ||
public async set( | ||
key: Storage["Key"], | ||
value: Storage["Value"], | ||
): Promise<void> { | ||
localStorage.setItem(this.prefix + key, JSON.stringify(value)); | ||
} | ||
public async get( | ||
key: Storage["Key"], | ||
): Promise<Storage["Value"] | undefined> { | ||
try { | ||
return JSON.parse( | ||
localStorage.getItem(this.prefix + key) || "null", | ||
); | ||
} catch (_) { | ||
} | ||
} | ||
public async delete(key: Storage["Key"]): Promise<void> { | ||
localStorage.removeItem(this.prefix + key); | ||
} | ||
public async clear(): Promise<void> { | ||
localStorage.clear(); | ||
} | ||
public async migrate(storage: BaseStorage): Promise<void> { | ||
for (let index = 0; index < localStorage.length; index++) { | ||
const k = localStorage.key(index); | ||
if (k) { | ||
storage.set( | ||
k.replace(this.prefix, ""), | ||
localStorage.getItem(k), | ||
); | ||
} else { | ||
continue; | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
## What changed | ||
## What's changed | ||
|
||
### Client | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters