-
Notifications
You must be signed in to change notification settings - Fork 4
feat: namespace page-view localStorage key and migrate legacy key #113
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
alexs-mparticle
merged 12 commits into
development
from
feat/page-view-storage-migration
Aug 12, 2026
Merged
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
726e4cf
feat: namespace page-view localStorage key and migrate legacy key
alexs-mparticle d49ba2e
refactor: surface page-view persistence failures as diagnostic logs
alexs-mparticle 48a9fe8
refactor: extract localStorage helpers into src/storage.ts
alexs-mparticle fb2a4c3
refactor: drop redundant comments left by storage extraction
alexs-mparticle 7b4c9fb
fix: Remove unnecessary comments
alexs-mparticle b008b5e
docs: encourage modular extraction over single-file kit source
alexs-mparticle f466d07
refactor: simplify legacy page-view key guard to falsy check
alexs-mparticle 979f4d9
refactor: store page views as a field under a single namespaced key
alexs-mparticle 07cc062
refactor: address PR feedback on migration read and test helpers
alexs-mparticle 12a3c36
refactor: log instead of throw on failed legacy migration
alexs-mparticle 32a84c6
fix: Rename migrated object
alexs-mparticle b3996a9
refactor: route legacy page-view test seeding through a helper
alexs-mparticle File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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,55 @@ | ||
| export function readJSON(key: string): unknown { | ||
| try { | ||
| const stored = window.localStorage.getItem(key); | ||
| return stored === null ? null : JSON.parse(stored); | ||
| } catch { | ||
| return null; | ||
| } | ||
| } | ||
|
|
||
| export function writeJSON(key: string, value: unknown): boolean { | ||
| try { | ||
| window.localStorage.setItem(key, JSON.stringify(value)); | ||
| return true; | ||
| } catch { | ||
| return false; | ||
| } | ||
| } | ||
|
|
||
| export function removeKey(key: string): void { | ||
| try { | ||
| window.localStorage.removeItem(key); | ||
| } catch { | ||
| /* empty */ | ||
| } | ||
| } | ||
|
|
||
| function isPlainObject(value: unknown): value is Record<string, unknown> { | ||
| return typeof value === 'object' && value !== null && !Array.isArray(value); | ||
| } | ||
|
|
||
| export function readNamespacedField(namespaceKey: string, field: string): unknown { | ||
| const blob = readJSON(namespaceKey); | ||
| return isPlainObject(blob) ? blob[field] : undefined; | ||
| } | ||
|
|
||
| export function writeNamespacedField(namespaceKey: string, field: string, value: unknown): boolean { | ||
| const blob = readJSON(namespaceKey); | ||
| const next = isPlainObject(blob) ? { ...blob } : {}; | ||
| next[field] = value; | ||
| return writeJSON(namespaceKey, next); | ||
| } | ||
|
|
||
| export function removeNamespacedField(namespaceKey: string, field: string): void { | ||
| const blob = readJSON(namespaceKey); | ||
| if (!isPlainObject(blob) || !(field in blob)) { | ||
| return; | ||
| } | ||
| const next = { ...blob }; | ||
| delete next[field]; | ||
| if (Object.keys(next).length === 0) { | ||
| removeKey(namespaceKey); | ||
| } else { | ||
| writeJSON(namespaceKey, next); | ||
| } | ||
| } | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.