Skip to content

Commit

Permalink
refactor(core): store with Object.assign (#2663)
Browse files Browse the repository at this point in the history
* refactor(core): store with Object.assign

* fix a gh action
  • Loading branch information
dai-shi authored Jul 17, 2024
1 parent ba9e8fe commit debff8b
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 10 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}"
20 changes: 10 additions & 10 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,11 +686,14 @@ 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,
Expand All @@ -711,13 +715,9 @@ export const createStore = (): Store => {
flushPending(pending)
},
}
return store
}
return {
get: readAtom,
set: writeAtom,
sub: subscribeAtom,
Object.assign(store, devStore)
}
return store
}

let defaultStore: Store | undefined
Expand Down

0 comments on commit debff8b

Please sign in to comment.