-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: integrate storage with jotai (#5)
- Loading branch information
Showing
20 changed files
with
246 additions
and
44 deletions.
There are no files selected for viewing
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
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,6 @@ | ||
import { atomWithStorage } from 'jotai/utils'; | ||
import { createStorage } from '@webx-kit/storage'; | ||
|
||
const chromeStorage = createStorage(); | ||
|
||
export const apiKeyAtom = atomWithStorage<string | null>('apiKey', null, chromeStorage); |
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 |
---|---|---|
|
@@ -13,6 +13,7 @@ | |
"rsbuild", | ||
"svgr", | ||
"tailwindcss", | ||
"testid", | ||
"webx" | ||
] | ||
} |
This file was deleted.
Oops, something went wrong.
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,16 @@ | ||
import { createRoot } from 'react-dom/client'; | ||
import { useAtomValue } from 'jotai/react'; | ||
import { apiKeyAtom } from '../hooks/atoms'; | ||
|
||
const App = () => { | ||
const apiKey = useAtomValue(apiKeyAtom); | ||
return ( | ||
<div> | ||
<div data-testid="apiKey">{apiKey}</div> | ||
</div> | ||
); | ||
}; | ||
|
||
const root = document.createElement('div'); | ||
createRoot(root).render(<App />); | ||
document.body.append(root); |
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,6 @@ | ||
import { atomWithStorage } from 'jotai/utils'; | ||
import { createStorage } from '@/index'; | ||
|
||
const chromeStorage = createStorage(); | ||
|
||
export const apiKeyAtom = atomWithStorage<string>('apiKey', 'DEFAULT', chromeStorage); |
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,22 @@ | ||
import { createRoot } from 'react-dom/client'; | ||
import { useAtom } from 'jotai/react'; | ||
import { apiKeyAtom } from '../../hooks/atoms'; | ||
|
||
const App = () => { | ||
const [apiKey, setAPIKey] = useAtom(apiKeyAtom); | ||
return ( | ||
<div> | ||
<div data-testid="apiKey">{apiKey}</div> | ||
<button | ||
data-testid="change" | ||
onClick={() => { | ||
setAPIKey('Changed'); | ||
}} | ||
> | ||
Change | ||
</button> | ||
</div> | ||
); | ||
}; | ||
|
||
createRoot(document.getElementById('root')!).render(<App />); |
This file was deleted.
Oops, something went wrong.
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,14 @@ | ||
import { createRoot } from 'react-dom/client'; | ||
import { useAtomValue } from 'jotai/react'; | ||
import { apiKeyAtom } from '../../hooks/atoms'; | ||
|
||
const App = () => { | ||
const apiKey = useAtomValue(apiKeyAtom); | ||
return ( | ||
<div> | ||
<div data-testid="apiKey">{apiKey}</div> | ||
</div> | ||
); | ||
}; | ||
|
||
createRoot(document.getElementById('root')!).render(<App />); |
This file was deleted.
Oops, something went wrong.
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,39 @@ | ||
import { setupStaticServer } from '@webx-kit/test-utils/playwright'; | ||
import { expect, test } from './context'; | ||
|
||
const getWebpageURL = setupStaticServer(test); | ||
|
||
test('Single page', async ({ getURL, page }) => { | ||
await page.goto(await getURL('jotai.html')); | ||
|
||
await expect(page.getByTestId('apiKey')).toHaveText('DEFAULT'); | ||
await page.getByTestId('change').click(); | ||
await expect(page.getByTestId('apiKey')).toHaveText('Changed'); | ||
|
||
await page.reload(); | ||
await expect(page.getByTestId('apiKey')).toHaveText('Changed'); | ||
}); | ||
|
||
test('Cross pages', async ({ getURL, context }) => { | ||
const jotaiPage = await context.newPage(); | ||
const optionsPage = await context.newPage(); | ||
const webPage = await context.newPage(); | ||
|
||
await jotaiPage.goto(await getURL('jotai.html')); | ||
await optionsPage.goto(await getURL('options.html')); | ||
await webPage.goto(getWebpageURL()); | ||
|
||
await expect(jotaiPage.getByTestId('apiKey')).toHaveText('DEFAULT'); | ||
await expect(optionsPage.getByTestId('apiKey')).toHaveText('DEFAULT'); | ||
await expect(webPage.getByTestId('apiKey')).toHaveText('DEFAULT'); | ||
|
||
await jotaiPage.getByTestId('change').click(); | ||
await expect(jotaiPage.getByTestId('apiKey')).toHaveText('Changed'); | ||
await expect(optionsPage.getByTestId('apiKey')).toHaveText('Changed'); | ||
await expect(webPage.getByTestId('apiKey')).toHaveText('Changed'); | ||
|
||
await Promise.all([jotaiPage.reload(), optionsPage.reload(), webPage.reload()]); | ||
await expect(jotaiPage.getByTestId('apiKey')).toHaveText('Changed'); | ||
await expect(optionsPage.getByTestId('apiKey')).toHaveText('Changed'); | ||
await expect(webPage.getByTestId('apiKey')).toHaveText('Changed'); | ||
}); |
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 |
---|---|---|
@@ -1,20 +1,48 @@ | ||
{ | ||
"name": "@webx-kit/storage", | ||
"version": "0.0.0", | ||
"exports": { | ||
".": { | ||
"types": "./src/index.ts", | ||
"default": "./src/index.ts" | ||
} | ||
}, | ||
"types": "./src/index.ts", | ||
"publishConfig": { | ||
"exports": { | ||
".": { | ||
"types": "./dist/index.d.mts", | ||
"default": "./dist/index.mjs" | ||
} | ||
}, | ||
"types": "./dist/index.d.mts" | ||
}, | ||
"files": [ | ||
"dist" | ||
], | ||
"scripts": { | ||
"dev": "modern dev", | ||
"build": "tsup", | ||
"pretest": "modern build", | ||
"test": "playwright test", | ||
"lint:type": "tsc --noEmit" | ||
}, | ||
"devDependencies": { | ||
"@modern-js/app-tools": "^2.46.1", | ||
"@modern-js/utils": "^2.46.1", | ||
"@playwright/test": "^1.41.0", | ||
"@types/chrome": "^0.0.258", | ||
"@types/node": "^20.11.5", | ||
"@webx-kit/chrome-types": "workspace:^", | ||
"@types/react": "^18.2.48", | ||
"@types/react-dom": "^18.2.18", | ||
"@webx-kit/modernjs-plugin": "workspace:^", | ||
"@webx-kit/test-utils": "workspace:^", | ||
"jotai": "^2.6.2", | ||
"react": "^18.2.0", | ||
"react-dom": "^18.2.0", | ||
"tsup": "^8.0.1", | ||
"typescript": "^5.3.3" | ||
}, | ||
"peerDependencies": { | ||
"@types/chrome": "^0.0.258" | ||
} | ||
} |
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
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,9 @@ | ||
import { defineConfig } from 'tsup'; | ||
|
||
export default defineConfig({ | ||
entry: ['./src/index.ts'], | ||
outDir: './dist', | ||
format: 'esm', | ||
clean: true, | ||
dts: true, | ||
}); |
Oops, something went wrong.