Skip to content
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

[web] Cache/Manage pricings using global context #310

Merged
merged 9 commits into from
Oct 12, 2022

Conversation

junhoyeo
Copy link
Member

@junhoyeo junhoyeo commented Oct 12, 2022

#3

@vercel
Copy link

vercel bot commented Oct 12, 2022

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Updated
bento ✅ Ready (Inspect) Visit Preview Oct 12, 2022 at 1:12AM (UTC)

@junhoyeo junhoyeo merged commit 07932dc into develop Oct 12, 2022
@junhoyeo junhoyeo deleted the junhoyeo/pricings-as-global-cache branch October 12, 2022 01:17
Comment on lines +16 to +30
const buildCacheStore = <T extends any>(prefix: string) => ({
get: async (key: string): Promise<T | null> => {
const v = localStorage.getItem(prefix);
if (!v) {
return null;
}
return JSON.parse(v)[key] || null;
},
set: async (key: string, value: T) => {
const v = localStorage.getItem(prefix);
const prev = !v ? {} : JSON.parse(v);
localStorage.setItem(prefix, JSON.stringify({ ...prev, [key]: value }));
},
});
const CacheStore = buildCacheStore('@pricings');
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TODO: Use IndexedDB with localForage

junhoyeo added a commit that referenced this pull request Oct 12, 2022
Rename file: `pricings` -> `useCachedPricings`

Check server in `PricingsProvider`

export type `getCachedPrice`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant