Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

alternate implementation for #2801 #2888

Open
wants to merge 33 commits into
base: main
Choose a base branch
from
Open

Conversation

dai-shi
Copy link
Member

@dai-shi dai-shi commented Dec 23, 2024

alternate implementation for #2801

Goals:

  • Do not expose atomState
  • Do not expose internal listeners
  • Implement onInit as minimal as possible

Remaining:

  • Two FIXME comments in effect.test.ts
  • I'm not sure if there are some missing capabilities for atomSyncEffect

Copy link

vercel bot commented Dec 23, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
jotai ✅ Ready (Inspect) Visit Preview 💬 Add feedback Dec 28, 2024 11:51pm

Copy link

codesandbox-ci bot commented Dec 23, 2024

This pull request is automatically built and testable in CodeSandbox.

To see build info of the built libraries, click here or the icon next to each commit SHA.

Copy link

pkg-pr-new bot commented Dec 23, 2024

Open in Stackblitz

More templates

npm i https://pkg.pr.new/jotai@2888

commit: 7fb805c

Copy link

github-actions bot commented Dec 23, 2024

Size Change: +553 B (+0.6%)

Total Size: 92.6 kB

Filename Size Change
./dist/esm/vanilla.mjs 4.35 kB +107 B (+2.52%)
./dist/system/vanilla.development.js 4.45 kB +105 B (+2.42%)
./dist/system/vanilla.production.js 2.19 kB +48 B (+2.24%)
./dist/umd/vanilla.development.js 5.79 kB +136 B (+2.4%)
./dist/umd/vanilla.production.js 2.88 kB +28 B (+0.98%)
./dist/vanilla.js 5.67 kB +129 B (+2.33%)
ℹ️ View Unchanged
Filename Size
./dist/babel/plugin-debug-label.js 932 B
./dist/babel/plugin-react-refresh.js 1.14 kB
./dist/babel/preset.js 1.41 kB
./dist/esm/babel/plugin-debug-label.mjs 1 kB
./dist/esm/babel/plugin-react-refresh.mjs 1.19 kB
./dist/esm/babel/preset.mjs 1.49 kB
./dist/esm/index.mjs 62 B
./dist/esm/react.mjs 1.4 kB
./dist/esm/react/utils.mjs 746 B
./dist/esm/utils.mjs 67 B
./dist/esm/vanilla/utils.mjs 5.04 kB
./dist/index.js 242 B
./dist/react.js 1.44 kB
./dist/react/utils.js 1.39 kB
./dist/system/babel/plugin-debug-label.development.js 1.1 kB
./dist/system/babel/plugin-debug-label.production.js 775 B
./dist/system/babel/plugin-react-refresh.development.js 1.29 kB
./dist/system/babel/plugin-react-refresh.production.js 928 B
./dist/system/babel/preset.development.js 1.59 kB
./dist/system/babel/preset.production.js 1.14 kB
./dist/system/index.development.js 252 B
./dist/system/index.production.js 183 B
./dist/system/react.development.js 1.56 kB
./dist/system/react.production.js 864 B
./dist/system/react/utils.development.js 860 B
./dist/system/react/utils.production.js 462 B
./dist/system/utils.development.js 257 B
./dist/system/utils.production.js 187 B
./dist/system/vanilla/utils.development.js 5.25 kB
./dist/system/vanilla/utils.production.js 3.14 kB
./dist/umd/babel/plugin-debug-label.development.js 1.08 kB
./dist/umd/babel/plugin-debug-label.production.js 852 B
./dist/umd/babel/plugin-react-refresh.development.js 1.27 kB
./dist/umd/babel/plugin-react-refresh.production.js 1 kB
./dist/umd/babel/preset.development.js 1.54 kB
./dist/umd/babel/preset.production.js 1.22 kB
./dist/umd/index.development.js 383 B
./dist/umd/index.production.js 328 B
./dist/umd/react.development.js 1.57 kB
./dist/umd/react.production.js 936 B
./dist/umd/react/utils.development.js 1.53 kB
./dist/umd/react/utils.production.js 1.01 kB
./dist/umd/utils.development.js 399 B
./dist/umd/utils.production.js 342 B
./dist/umd/vanilla/utils.development.js 6.24 kB
./dist/umd/vanilla/utils.production.js 3.78 kB
./dist/utils.js 247 B
./dist/vanilla/utils.js 6.1 kB

compressed-size-action

Copy link

github-actions bot commented Dec 23, 2024

LiveCodes Preview in LiveCodes

Latest commit: 7fb805c
Last updated: Dec 28, 2024 11:51pm (UTC)

Playground Link
React demo https://livecodes.io?x=id/HJSX59JW3

See documentations for usage instructions.

@@ -1,3 +1,5 @@
import type { INTERNAL_PrdStore as Store } from './store'
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
import type { INTERNAL_PrdStore as Store } from './store'
import type { PrdOrDevStore as Store } from './store'

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's correct for the current implementation, but as I plan to remove DevStore by default in the future, this limits more. Maybe I did wrong with S extends Store too.

@@ -260,6 +264,7 @@ type StoreArgs = readonly [
atom: WritableAtom<Value, Args, Result>,
setAtom: (...args: Args) => Result,
) => OnUnmount | void,
atomOnInit: <Value>(atom: Atom<Value>, store: Store) => void,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should Init come before Mount in StoreArgs?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm fine with it.

Comment on lines 251 to 254
setAtomState: <Value>(
atom: Atom<Value>,
atomState: AtomState<Value>,
) => AtomState<Value>,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice 😎

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

though, returning a (possibly modified) atomState is not very intuitive.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hmm, maybe this could help, though its a little pedantic

setAtomState: <Value, AS extends AtomState<Value>>(
    atom: Atom<Value>,
    atomState: AS,
  ) => AS,

Copy link
Member Author

@dai-shi dai-shi Dec 26, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good idea. The arg must be original one.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants