Skip to content

Commit

Permalink
return mutable building blocks
Browse files Browse the repository at this point in the history
  • Loading branch information
dmaskasky committed Feb 6, 2025
1 parent 0797e00 commit 52d4b97
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 7 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/test-multiple-builds.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +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/derive.test.tsx tests/vanilla/effect.test.ts
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 @@ -56,7 +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/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
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
5 changes: 3 additions & 2 deletions src/vanilla/internals.ts
Original file line number Diff line number Diff line change
Expand Up @@ -409,8 +409,9 @@ type BuildingBlocks = readonly [

const BUILDING_BLOCKS: unique symbol = Symbol() // no description intentionally

const getBuildingBlocks = (store: unknown): BuildingBlocks =>
(store as any)[BUILDING_BLOCKS]
const getBuildingBlocks = (store: unknown): Mutable<BuildingBlocks> => [
...((store as any)[BUILDING_BLOCKS] as BuildingBlocks),
]

const buildStore = (
...buildingBlocks: Partial<Mutable<BuildingBlocks>>
Expand Down
5 changes: 2 additions & 3 deletions tests/vanilla/internals.test.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
import { describe } from 'node:test'
import { expect, it } from 'vitest'
import { describe, expect, it } from 'vitest'
import { createStore } from 'jotai'
import { INTERNAL_getBuildingBlocksRev1 as INTERNAL_getBuildingBlocks } from 'jotai/vanilla/internals'

describe('internals', () => {
it('should not return a sparse building blocks array', () => {
function isSparse(arr: ReadonlyArray<unknown>) {
return arr.some((_, i) => !arr.hasOwnProperty(i))
return arr.some((_, i) => !Object.prototype.hasOwnProperty.call(arr, i))
}
const store = createStore()
const buildingBlocks = INTERNAL_getBuildingBlocks(store)
Expand Down

0 comments on commit 52d4b97

Please sign in to comment.