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

feat(vanilla): customizable atom.unstable_is #2356

Merged
merged 9 commits into from
Jan 24, 2024

Conversation

dai-shi
Copy link
Member

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

supersedes #2353

  • introduce atom.unstable_is
  • make default read & write functions stable

Copy link

vercel bot commented Jan 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 Jan 24, 2024 11:36am

Copy link

codesandbox-ci bot commented Jan 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.

Latest deployment of this branch, based on commit 2b2e3e7:

Sandbox Source
React Configuration
React TypeScript Configuration
React Browserify Configuration
React Snowpack Configuration
Next.js Configuration
Next.js with custom Babel config Configuration
React with custom Babel config Configuration

Copy link

github-actions bot commented Jan 23, 2024

Size Change: +228 B (0%)

Total Size: 70.3 kB

Filename Size Change
dist/system/vanilla.development.js 4.17 kB +47 B (+1%)
dist/system/vanilla.production.js 2.09 kB +29 B (+1%)
dist/umd/vanilla.development.js 4.94 kB +50 B (+1%)
dist/umd/vanilla.production.js 2.25 kB +54 B (+2%)
dist/vanilla.js 4.86 kB +48 B (+1%)
ℹ️ View Unchanged
Filename Size
dist/babel/plugin-debug-label.js 907 B
dist/babel/plugin-react-refresh.js 1.14 kB
dist/babel/preset.js 1.38 kB
dist/index.js 242 B
dist/react.js 1.06 kB
dist/react/utils.js 1.26 kB
dist/system/babel/plugin-debug-label.development.js 1.09 kB
dist/system/babel/plugin-debug-label.production.js 757 B
dist/system/babel/plugin-react-refresh.development.js 1.29 kB
dist/system/babel/plugin-react-refresh.production.js 929 B
dist/system/babel/preset.development.js 1.56 kB
dist/system/babel/preset.production.js 1.13 kB
dist/system/index.development.js 253 B
dist/system/index.production.js 182 B
dist/system/react.development.js 1.18 kB
dist/system/react.production.js 711 B
dist/system/react/utils.development.js 722 B
dist/system/react/utils.production.js 461 B
dist/system/utils.development.js 258 B
dist/system/utils.production.js 188 B
dist/system/vanilla/utils.development.js 4.73 kB
dist/system/vanilla/utils.production.js 2.88 kB
dist/umd/babel/plugin-debug-label.development.js 1.06 kB
dist/umd/babel/plugin-debug-label.production.js 845 B
dist/umd/babel/plugin-react-refresh.development.js 1.28 kB
dist/umd/babel/plugin-react-refresh.production.js 1.01 kB
dist/umd/babel/preset.development.js 1.53 kB
dist/umd/babel/preset.production.js 1.24 kB
dist/umd/index.development.js 381 B
dist/umd/index.production.js 329 B
dist/umd/react.development.js 1.18 kB
dist/umd/react.production.js 785 B
dist/umd/react/utils.development.js 1.43 kB
dist/umd/react/utils.production.js 1.03 kB
dist/umd/utils.development.js 398 B
dist/umd/utils.production.js 343 B
dist/umd/vanilla/utils.development.js 5.64 kB
dist/umd/vanilla/utils.production.js 3.47 kB
dist/utils.js 246 B
dist/vanilla/utils.js 5.5 kB

compressed-size-action

@@ -40,6 +40,7 @@ type OnMount<Args extends unknown[], Result> = <
export interface Atom<Value> {
toString: () => string
read: Read<Value>
is?: (a: Atom<unknown>) => boolean
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 thought about requiring this property rather than making it optional, but as we want to release this as a patch, let's do this.
Eventually, if it makes sense (like moving to class syntax), we can consider changing it a required property.

Copy link
Contributor

@yf-yang yf-yang Jan 23, 2024

Choose a reason for hiding this comment

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

A scenario needs to be considered: A global atom anAtom has two copies copy1 and copy2, it is possible that copy1 internally calls set(copy2, value) (so copy1.is(copy2) should evals to true). Therefore, even with this change, we still needs to add another property in jotai-scope's intercepted copy to mark two copies as having the same original atom.

Copy link
Member Author

@dai-shi dai-shi Jan 23, 2024

Choose a reason for hiding this comment

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

So, does it mean it requires to be is?: (self: Atom<unknown>, target: Atom<unknown>) => boolean and doesn't use this?

Copy link
Contributor

Choose a reason for hiding this comment

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

Well, for the jotai-scope PR, there is no need to do so.
Personally, I think the term should not be called is, as is suggests equality and equality is symmetric, while in this case it is not.
https://doc.rust-lang.org/std/cmp/trait.PartialEq.html

@@ -40,6 +40,7 @@ type OnMount<Args extends unknown[], Result> = <
export interface Atom<Value> {
toString: () => string
read: Read<Value>
is?: (self: Atom<unknown>, target: Atom<unknown>) => boolean
Copy link
Member Author

Choose a reason for hiding this comment

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

Hm, it doesn't seem to add any capability.
If it works, it should work with this too:

Suggested change
is?: (self: Atom<unknown>, target: Atom<unknown>) => boolean
is?: (this: Atom<unknown>, target: Atom<unknown>) => boolean

@dai-shi
Copy link
Member Author

dai-shi commented Jan 23, 2024

I feel like adding unstable_ prefix for now. 🤔

@dai-shi dai-shi changed the title feat(vanilla): customizable atom.is feat(vanilla): customizable atom.unstable_is Jan 23, 2024
@yf-yang
Copy link
Contributor

yf-yang commented Jan 23, 2024

I've made jotai-scope work with commit 3185a1. Once this PR is done, I'll give it another try.

@dai-shi
Copy link
Member Author

dai-shi commented Jan 23, 2024

Can you actually try the csb build in jotaijs/jotai-scope#20 ?

https://ci.codesandbox.io/status/pmndrs/jotai/pr/2356/builds/463536
☝️ Find "Local Install Instructions"

I plan to merge this PR tomorrow, but it depends on other PRs in this repo.

@yf-yang
Copy link
Contributor

yf-yang commented Jan 23, 2024

Done, ping me when this one get merged.

@dai-shi dai-shi merged commit d06262a into main Jan 24, 2024
33 checks passed
@dai-shi dai-shi deleted the feat/vanilla/customizable-atom-is branch January 24, 2024 11:42
@dai-shi
Copy link
Member Author

dai-shi commented Jan 24, 2024

davydkov referenced this pull request in likec4/likec4 Feb 7, 2024
[![Mend
Renovate](https://app.renovatebot.com/images/banner.svg)](https://renovatebot.com)

This PR contains the following updates:

| Package | Change | Age | Adoption | Passing | Confidence |
|---|---|---|---|---|---|
| [jotai](https://github.com/pmndrs/jotai) | [`^2.6.0` ->
`^2.6.4`](https://renovatebot.com/diffs/npm/jotai/2.6.0/2.6.4) |
[![age](https://developer.mend.io/api/mc/badges/age/npm/jotai/2.6.4?slim=true)](https://docs.renovatebot.com/merge-confidence/)
|
[![adoption](https://developer.mend.io/api/mc/badges/adoption/npm/jotai/2.6.4?slim=true)](https://docs.renovatebot.com/merge-confidence/)
|
[![passing](https://developer.mend.io/api/mc/badges/compatibility/npm/jotai/2.6.0/2.6.4?slim=true)](https://docs.renovatebot.com/merge-confidence/)
|
[![confidence](https://developer.mend.io/api/mc/badges/confidence/npm/jotai/2.6.0/2.6.4?slim=true)](https://docs.renovatebot.com/merge-confidence/)
|

---

### Release Notes

<details>
<summary>pmndrs/jotai (jotai)</summary>

### [`v2.6.4`](https://github.com/pmndrs/jotai/releases/tag/v2.6.4)

[Compare
Source](https://github.com/pmndrs/jotai/compare/v2.6.3...v2.6.4)

Performance improvement! Check it out!

##### What's Changed

- refactor: refactoring store and options type by
[@&#8203;ssi02014](https://github.com/ssi02014) in
[https://github.com/pmndrs/jotai/pull/2360](https://github.com/pmndrs/jotai/pull/2360)
- refactor: modified Args type by
[@&#8203;ssi02014](https://github.com/ssi02014) in
[https://github.com/pmndrs/jotai/pull/2367](https://github.com/pmndrs/jotai/pull/2367)
- Improve performance of recomputeDependents by
[@&#8203;samkline](https://github.com/samkline) in
[https://github.com/pmndrs/jotai/pull/2363](https://github.com/pmndrs/jotai/pull/2363)
- fix(vanilla): fix unexpected cache in jotai-scope by
[@&#8203;yf-yang](https://github.com/yf-yang) in
[https://github.com/pmndrs/jotai/pull/2371](https://github.com/pmndrs/jotai/pull/2371)

##### New Contributors

- [@&#8203;ssi02014](https://github.com/ssi02014) made their first
contribution in
[https://github.com/pmndrs/jotai/pull/2360](https://github.com/pmndrs/jotai/pull/2360)
- [@&#8203;samkline](https://github.com/samkline) made their first
contribution in
[https://github.com/pmndrs/jotai/pull/2363](https://github.com/pmndrs/jotai/pull/2363)
- [@&#8203;yf-yang](https://github.com/yf-yang) made their first
contribution in
[https://github.com/pmndrs/jotai/pull/2371](https://github.com/pmndrs/jotai/pull/2371)

**Full Changelog**:
pmndrs/jotai@v2.6.3...v2.6.4

### [`v2.6.3`](https://github.com/pmndrs/jotai/releases/tag/v2.6.3)

[Compare
Source](https://github.com/pmndrs/jotai/compare/v2.6.2...v2.6.3)

Some improvements in core and utils 👏

#### What's Changed

- fix: atoms should not remount on recalculations (with async
dependencies) by [@&#8203;dmaskasky](https://github.com/dmaskasky) in
[https://github.com/pmndrs/jotai/pull/2347](https://github.com/pmndrs/jotai/pull/2347)
- fix(utils): atomWithReducer for jotai-scope by
[@&#8203;dai-shi](https://github.com/dai-shi) in
[https://github.com/pmndrs/jotai/pull/2351](https://github.com/pmndrs/jotai/pull/2351)
- fix(utils/atomWithStorage): defaultStorage with disabled local storage
crashes on mount by
[@&#8203;benediktschlager](https://github.com/benediktschlager) in
[https://github.com/pmndrs/jotai/pull/2354](https://github.com/pmndrs/jotai/pull/2354)
- feat(vanilla): customizable atom.unstable_is by
[@&#8203;dai-shi](https://github.com/dai-shi) in
[https://github.com/pmndrs/jotai/pull/2356](https://github.com/pmndrs/jotai/pull/2356)

#### New Contributors

- [@&#8203;SpringHgui](https://github.com/SpringHgui) made their first
contribution in
[https://github.com/pmndrs/jotai/pull/2320](https://github.com/pmndrs/jotai/pull/2320)
- [@&#8203;sakurawen](https://github.com/sakurawen) made their first
contribution in
[https://github.com/pmndrs/jotai/pull/2358](https://github.com/pmndrs/jotai/pull/2358)
- [@&#8203;JoltCode](https://github.com/JoltCode) made their first
contribution in
[https://github.com/pmndrs/jotai/pull/2357](https://github.com/pmndrs/jotai/pull/2357)
- [@&#8203;benediktschlager](https://github.com/benediktschlager) made
their first contribution in
[https://github.com/pmndrs/jotai/pull/2354](https://github.com/pmndrs/jotai/pull/2354)

**Full Changelog**:
pmndrs/jotai@v2.6.2...v2.6.3

### [`v2.6.2`](https://github.com/pmndrs/jotai/releases/tag/v2.6.2)

[Compare
Source](https://github.com/pmndrs/jotai/compare/v2.6.1...v2.6.2)

Some improvements for atomWithStorage. Feedback is welcome.

#### What's Changed

- fix(vanilla): should mount once with atom creator atom by
[@&#8203;nogaten](https://github.com/nogaten) in
[https://github.com/pmndrs/jotai/pull/2319](https://github.com/pmndrs/jotai/pull/2319)
- feat(utils): createJSONStrage options by
[@&#8203;dai-shi](https://github.com/dai-shi) in
[https://github.com/pmndrs/jotai/pull/2324](https://github.com/pmndrs/jotai/pull/2324)
- feat(utils): add withStorageValidator by
[@&#8203;dai-shi](https://github.com/dai-shi) in
[https://github.com/pmndrs/jotai/pull/2336](https://github.com/pmndrs/jotai/pull/2336)

#### New Contributors

- [@&#8203;L-Qun](https://github.com/L-Qun) made their first
contribution in
[https://github.com/pmndrs/jotai/pull/2318](https://github.com/pmndrs/jotai/pull/2318)
- [@&#8203;ahme-dev](https://github.com/ahme-dev) made their first
contribution in
[https://github.com/pmndrs/jotai/pull/2332](https://github.com/pmndrs/jotai/pull/2332)
- [@&#8203;nogaten](https://github.com/nogaten) made their first
contribution in
[https://github.com/pmndrs/jotai/pull/2319](https://github.com/pmndrs/jotai/pull/2319)

**Full Changelog**:
pmndrs/jotai@v2.6.1...v2.6.2

### [`v2.6.1`](https://github.com/pmndrs/jotai/releases/tag/v2.6.1)

[Compare
Source](https://github.com/pmndrs/jotai/compare/v2.6.0...v2.6.1)

This version has two minor improvements for library authors. It's
wonderful to see Jotai ecosystem growing. No major bugs have been
reported lately. It's fairly okay to say the current version is pretty
stable.

#### What's Changed

- fix(utils): add init property to the return type of atomWithReset by
[@&#8203;jaesoekjjang](https://github.com/jaesoekjjang) in
[https://github.com/pmndrs/jotai/pull/2304](https://github.com/pmndrs/jotai/pull/2304)
- fix(utils): add description for the RESET symbol. by
[@&#8203;MiroslavPetrik](https://github.com/MiroslavPetrik) in
[https://github.com/pmndrs/jotai/pull/2307](https://github.com/pmndrs/jotai/pull/2307)

#### New Contributors

- [@&#8203;wherehows](https://github.com/wherehows) made their first
contribution in
[https://github.com/pmndrs/jotai/pull/2270](https://github.com/pmndrs/jotai/pull/2270)
- [@&#8203;benson00077](https://github.com/benson00077) made their
first contribution in
[https://github.com/pmndrs/jotai/pull/2284](https://github.com/pmndrs/jotai/pull/2284)
- [@&#8203;ioExpander](https://github.com/ioExpander) made their first
contribution in
[https://github.com/pmndrs/jotai/pull/2280](https://github.com/pmndrs/jotai/pull/2280)
- [@&#8203;jaesoekjjang](https://github.com/jaesoekjjang) made their
first contribution in
[https://github.com/pmndrs/jotai/pull/2304](https://github.com/pmndrs/jotai/pull/2304)

**Full Changelog**:
pmndrs/jotai@v2.6.0...v2.6.1

</details>

---

### Configuration

📅 **Schedule**: Branch creation - At any time (no schedule defined),
Automerge - At any time (no schedule defined).

🚦 **Automerge**: Disabled by config. Please merge this manually once you
are satisfied.

♻ **Rebasing**: Whenever PR becomes conflicted, or you tick the
rebase/retry checkbox.

🔕 **Ignore**: Close this PR and you won't be reminded about this update
again.

---

- [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check
this box

---

This PR has been generated by [Mend
Renovate](https://www.mend.io/free-developer-tools/renovate/). View
repository job log
[here](https://developer.mend.io/github/likec4/likec4).

<!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiIzNy4xNzMuMCIsInVwZGF0ZWRJblZlciI6IjM3LjE3My4wIiwidGFyZ2V0QnJhbmNoIjoibWFpbiJ9-->

Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
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