Skip to content

Commit

Permalink
Merge branch 'main' into atom-tostring
Browse files Browse the repository at this point in the history
  • Loading branch information
dai-shi authored Jul 23, 2024
2 parents e10edc8 + 628aa3e commit 8fe2a7c
Show file tree
Hide file tree
Showing 8 changed files with 31 additions and 21 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/compressed-size-action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,5 @@ jobs:
cache: 'pnpm'
cache-dependency-path: '**/pnpm-lock.yaml'
- uses: preactjs/compressed-size-action@v2
with:
pattern: "./dist/**/*.{js,mjs}"
4 changes: 4 additions & 0 deletions .github/workflows/test-old-typescript.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,10 @@ jobs:
cache-dependency-path: '**/pnpm-lock.yaml'
- run: pnpm install --frozen-lockfile
- run: pnpm build
- name: Patch for v4/v3 TS
if: ${{ startsWith(matrix.typescript, '4.') || startsWith(matrix.typescript, '3.') }}
run: |
sed -i~ 's/"verbatimModuleSyntax": true,//' tsconfig.json
- name: Patch for Newer TS
if: ${{ matrix.typescript == '4.9.5' || matrix.typescript == '4.8.4' }}
run: |
Expand Down
3 changes: 2 additions & 1 deletion src/babel/plugin-debug-label.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import babel, { PluginObj } from '@babel/core'
import babel from '@babel/core'
import type { PluginObj } from '@babel/core'
import _templateBuilder from '@babel/template'
import { isAtom } from './utils.ts'
import type { PluginOptions } from './utils.ts'
Expand Down
3 changes: 2 additions & 1 deletion src/babel/plugin-react-refresh.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import babel, { PluginObj } from '@babel/core'
import babel from '@babel/core'
import type { PluginObj } from '@babel/core'
import _templateBuilder from '@babel/template'
import { isAtom } from './utils.ts'
import type { PluginOptions } from './utils.ts'
Expand Down
2 changes: 1 addition & 1 deletion src/babel/preset.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import babel from '@babel/core'
import pluginDebugLabel from './plugin-debug-label.ts'
import pluginReactRefresh from './plugin-react-refresh.ts'
import { PluginOptions } from './utils.ts'
import type { PluginOptions } from './utils.ts'

export default function jotaiPreset(
_: typeof babel,
Expand Down
34 changes: 17 additions & 17 deletions src/vanilla/store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,7 @@ type PrdStore = {
) => Result
sub: (atom: AnyAtom, listener: () => void) => () => void
}

type Store = PrdStore | (PrdStore & DevStoreRev4)

export type INTERNAL_DevStoreRev4 = DevStoreRev4
Expand Down Expand Up @@ -685,39 +686,38 @@ export const createStore = (): Store => {
}
}

const store: Store = {
get: readAtom,
set: writeAtom,
sub: subscribeAtom,
}

if (import.meta.env?.MODE !== 'production') {
const store: Store = {
get: readAtom,
set: writeAtom,
sub: subscribeAtom,
const devStore: DevStoreRev4 = {
// store dev methods (these are tentative and subject to change without notice)
dev4_get_internal_weak_map: () => atomStateMap,
dev4_get_mounted_atoms: () => debugMountedAtoms,
dev4_restore_atoms: (values) => {
const pending = createPending()
for (const [atom, value] of values) {
if (hasInitialValue(atom)) {
const aState = getAtomState(atom)
const hasPrevValue = 'v' in aState
const prevValue = aState.v
setAtomStateValueOrPromise(atom, aState, value)
mountDependencies(pending, atom, aState)
if (!hasPrevValue || !Object.is(prevValue, aState.v)) {
addPendingAtom(pending, atom, aState)
const atomState = getAtomState(atom)
const hasPrevValue = 'v' in atomState
const prevValue = atomState.v
setAtomStateValueOrPromise(atom, atomState, value)
mountDependencies(pending, atom, atomState)
if (!hasPrevValue || !Object.is(prevValue, atomState.v)) {
addPendingAtom(pending, atom, atomState)
recomputeDependents(pending, atom)
}
}
}
flushPending(pending)
},
}
return store
}
return {
get: readAtom,
set: writeAtom,
sub: subscribeAtom,
Object.assign(store, devStore)
}
return store
}

let defaultStore: Store | undefined
Expand Down
3 changes: 2 additions & 1 deletion src/vanilla/utils/atomWithLazy.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { PrimitiveAtom, atom } from '../../vanilla.ts'
import { atom } from '../../vanilla.ts'
import type { PrimitiveAtom } from '../../vanilla.ts'

export function atomWithLazy<Value>(
makeInitial: () => Value,
Expand Down
1 change: 1 addition & 0 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
"allowImportingTsExtensions": true,
"noUncheckedIndexedAccess": true,
"exactOptionalPropertyTypes": true,
"verbatimModuleSyntax": true,
"noEmit": true,
"baseUrl": ".",
"paths": {
Expand Down

0 comments on commit 8fe2a7c

Please sign in to comment.