Skip to content

Commit

Permalink
feat(core): expose internals instead of unstable_derive (#2911)
Browse files Browse the repository at this point in the history
* wip: expose internal functions

* rename

* tests following the change

* separate internals entrypoint

* fix entries

* fix for umd, still wip

* revert them

* revert changes

* rename readme

* internals entry point

* impl

* fix store test

* derive test

* effect test

* fix rollup config

* hack types

* fix workflow files

* fix workflow files again

* hack types again

* fix rollup config

* ts ignore

* tried this?

* test: rename

* follow the change

* I think this is unnecessary

* fix AtomState type

* do not enumerate secret methods

* even better

* refactor

* another refactor

* wip: building-block functions

* give up scope tests for now

* some more refactors

* fix workflow file

* use symbol instead of weakmap for cancelable promise

* fix typo

* expose util and tentative functions

* does this fix?

* catch error from f hook

* only keeps one error

* do we want to support falsy errors?

* going back the circle

* store hook for atoms util

* does this help?

* for ts3.9

* store hooks tweaks (#2969)

* lazy assign store hooks internally

* initializeStoreHooks

* make it work with node 18

* refactor(internals): isolated mounted map in store (#2967)

* refactor(internals): isolated mounted map in store

* give up derive test

* rev4 compatibility

* a silly mistake

* storeHooks minor improvement (#2970)

* storeHooks: return delete function from add

* Update src/vanilla/internals.ts

---------

Co-authored-by: Daishi Kato <dai-shi@users.noreply.github.com>

* refactor(internals): store state in store args (#2972)

* refactor(internals): atomStateMap in storeState

* store args for everything and create building blocks

* createStoreArgs

* refactor

* refactor and type

* export internal types

* simplify types

* prefer readonly modifier

* expose building blocks

* elminate store args

* expose building blocks (#2974)

* expose building blocks

* elminate store args

* move top-level functions to createBuildingBlocks and add some organization

* tweak createBuildingBlocks

* update store and tests invocation of INTERNAL_createBuildingBlocks

* fix lint and decomposition

* refactor(internals): simplify building blocks

---------

Co-authored-by: daishi <daishi@axlight.com>

* comments

* customizable building blocks

* ts hack

* ts hack 2

* minor change

* nice to remove !

* refactor

* full building blocks (#2977)

* return a complete building blocks array

* return mutable building blocks

* revert to default function argument style

---------

Co-authored-by: daishi <daishi@axlight.com>

---------

Co-authored-by: David Maskasky <dmaskasky@gmail.com>
  • Loading branch information
dai-shi and dmaskasky authored Feb 11, 2025
1 parent 72c1144 commit 253e9bd
Show file tree
Hide file tree
Showing 10 changed files with 1,310 additions and 1,093 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/test-multiple-builds.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ jobs:
sed -i~ "s/resolve('\.\/src\(.*\)\.ts')/resolve('\.\/dist\1.js')/" vitest.config.mts
sed -i~ "s/import { useResetAtom } from 'jotai\/react\/utils'/const { useResetAtom } = require('..\/..\/..\/dist\/react\/utils.js')/" tests/react/utils/useResetAtom.test.tsx
sed -i~ "s/import { RESET, atomWithReducer, atomWithReset } from 'jotai\/vanilla\/utils'/const { RESET, atomWithReducer, atomWithReset } = require('..\/..\/..\/dist\/vanilla\/utils.js')/" tests/react/utils/useResetAtom.test.tsx
perl -i~ -0777 -pe "s/import {[^}]+} from 'jotai\/vanilla\/internals'/const { INTERNAL_buildStoreRev1: INTERNAL_buildStore, INTERNAL_initializeStoreHooks, INTERNAL_getBuildingBlocksRev1: INTERNAL_getBuildingBlocks } = require('..\/..\/dist\/vanilla\/internals.js')/g" tests/vanilla/store.test.tsx tests/vanilla/internals.test.tsx tests/vanilla/derive.test.tsx tests/vanilla/effect.test.ts
- name: Patch for ESM
if: ${{ matrix.build == 'esm' }}
run: |
Expand All @@ -55,6 +56,7 @@ jobs:
run: |
sed -i~ "s/resolve('\.\/src\(.*\)\.ts')/resolve('\.\/dist\/umd\1.${NODE_ENV}.js')/" vitest.config.mts
rm tests/react/utils/useResetAtom.test.tsx # FIXME we skip this for now. Actually I'm not sure if we really run tests with UMD build
rm tests/vanilla/store.test.tsx tests/vanilla/internals.test.tsx tests/vanilla/derive.test.tsx tests/vanilla/effect.test.ts # FIXME we skip this for now. Actually I'm not sure if we really run tests with UMD build
env:
NODE_ENV: ${{ matrix.env }}
- name: Patch for SystemJS
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@
"build:babel:preset": "rollup -c --config-babel_preset",
"build:vanilla": "rollup -c --config-vanilla",
"build:vanilla:utils": "rollup -c --config-vanilla_utils",
"build:vanilla:internals": "rollup -c --config-vanilla_internals",
"build:react": "rollup -c --config-react --client-only",
"build:react:utils": "rollup -c --config-react_utils --client-only",
"postbuild": "pnpm run patch-d-ts && pnpm run copy && pnpm run patch-ts3.8 && pnpm run patch-old-ts && pnpm run patch-esm-ts && pnpm run patch-readme",
Expand Down
2 changes: 2 additions & 0 deletions rollup.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ const extensions = ['.js', '.ts', '.tsx']
const { root } = path.parse(process.cwd())
export const entries = [
{ find: /.*\/vanilla\/utils\.ts$/, replacement: 'jotai/vanilla/utils' },
{ find: /.*\/internals\.ts$/, replacement: 'jotai/vanilla/internals' },
{ find: /.*\/react\/utils\.ts$/, replacement: 'jotai/react/utils' },
{ find: /.*\/vanilla\.ts$/, replacement: 'jotai/vanilla' },
{ find: /.*\/react\.ts$/, replacement: 'jotai/react' },
Expand Down Expand Up @@ -124,6 +125,7 @@ function createUMDConfig(input, output, env, clientOnly) {
'jotai/utils': 'jotaiUtils',
'jotai/react': 'jotaiReact',
'jotai/vanilla/utils': 'jotaiVanillaUtils',
'jotai/vanilla/internals': 'jotaiVanillaInternals',
'jotai/react/utils': 'jotaiReactUtils',
},
},
Expand Down
Loading

0 comments on commit 253e9bd

Please # to comment.