Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: pmndrs/jotai
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: v1.12.0
Choose a base ref
...
head repository: pmndrs/jotai
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: v1.12.1
Choose a head ref
  • 6 commits
  • 15 files changed
  • 2 contributors

Commits on Dec 24, 2022

  1. chore(tests): move vanilla-utils tests into tests/react (#1655)

    * chore(tests): move vanilla-utils tests into tests/react
    
    * fix github workflow file
    dai-shi authored Dec 24, 2022
    1
    Copy the full SHA
    6ed2bb2 View commit details

Commits on Dec 30, 2022

  1. Update bug_report.md

    dai-shi authored Dec 30, 2022
    1
    Copy the full SHA
    ff3d7d8 View commit details
  2. 1
    Copy the full SHA
    abc3dc1 View commit details
  3. 1
    Copy the full SHA
    e3530ee View commit details
  4. chore(deps): update dev dependencies (#1663)

    * update dev dependencies
    
    * update experimental react build
    
    * Revert "update experimental react build"
    
    This reverts commit 35bb95b.
    dai-shi authored Dec 30, 2022
    1
    Copy the full SHA
    bfadea0 View commit details
  5. 1.12.1

    dai-shi committed Dec 30, 2022
    1
    Copy the full SHA
    f0048c1 View commit details
2 changes: 1 addition & 1 deletion .github/ISSUE_TEMPLATE/bug_report.md
Original file line number Diff line number Diff line change
@@ -19,7 +19,7 @@ assignees: ''

Please do not ask questions in issues.

- [ ] I understand this is not a question.
- [ ] I've already opened a [discussion](https://github.com/pmndrs/jotai/discussions) before opening this issue.

Please include a minimal reproduction.

2 changes: 1 addition & 1 deletion .github/workflows/test-old-typescript.yml
Original file line number Diff line number Diff line change
@@ -52,7 +52,7 @@ jobs:
sed -i~ "s/^.* from '\.\/utils\/waitForAll';//" dist/ts3.4/utils.d.ts
yarn json -I -f package.json -e "this.resolutions={}; this.resolutions['@types/jest']='26.0.14'; this.resolutions['pretty-format']='25.5.0'; this.resolutions['@types/prettier']='2.4.2';"
yarn add -D @types/jest@26.0.14 pretty-format@25.5.0 @types/prettier@2.4.2 @types/yargs@17.0.13 @types/babel__traverse@7.18.2
rm -r tests/utils/atomWithObservable.* tests/utils/waitForAll.* tests/vanilla/utils/atomWithObservable.*
rm -r tests/utils/atomWithObservable.* tests/utils/waitForAll.* tests/react/vanilla-utils/atomWithObservable.*
- name: Ignore Async API tests for Older TS
if: ${{ matrix.typescript == '3.7.5' }}
run: |
26 changes: 13 additions & 13 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "jotai",
"private": true,
"version": "1.12.0",
"version": "1.12.1",
"description": "👻 Next gen state management that will spook you",
"main": "./index.js",
"types": "./index.d.ts",
@@ -141,31 +141,31 @@
]
},
"devDependencies": {
"@babel/core": "^7.20.5",
"@babel/plugin-transform-react-jsx": "^7.19.0",
"@babel/plugin-transform-typescript": "^7.20.2",
"@babel/core": "^7.20.7",
"@babel/plugin-transform-react-jsx": "^7.20.7",
"@babel/plugin-transform-typescript": "^7.20.7",
"@babel/preset-env": "^7.20.2",
"@babel/template": "^7.18.10",
"@babel/types": "^7.20.5",
"@babel/template": "^7.20.7",
"@babel/types": "^7.20.7",
"@redux-devtools/extension": "^3.2.3",
"@rollup/plugin-babel": "^6.0.3",
"@rollup/plugin-node-resolve": "^15.0.1",
"@rollup/plugin-replace": "^5.0.2",
"@rollup/plugin-typescript": "^10.0.1",
"@swc/core": "^1.3.23",
"@swc/core": "^1.3.24",
"@swc/jest": "^0.2.24",
"@tanstack/query-core": "^4.20.4",
"@testing-library/react": "^13.4.0",
"@types/jest": "^29.2.4",
"@types/react": "^18.0.26",
"@types/react-dom": "^18.0.9",
"@typescript-eslint/eslint-plugin": "^5.47.0",
"@typescript-eslint/parser": "^5.47.0",
"@types/react-dom": "^18.0.10",
"@typescript-eslint/eslint-plugin": "^5.47.1",
"@typescript-eslint/parser": "^5.47.1",
"@urql/core": "^3.1.1",
"benny": "^3.7.1",
"concurrently": "^7.6.0",
"downlevel-dts": "^0.11.0",
"esbuild": "^0.16.10",
"esbuild": "^0.16.12",
"eslint": "^8.30.0",
"eslint-config-prettier": "^8.5.0",
"eslint-import-resolver-alias": "^1.1.2",
@@ -193,7 +193,7 @@
"react": "^18.2.0",
"react-dom": "^18.2.0",
"redux": "^4.2.0",
"rollup": "^3.7.5",
"rollup": "^3.9.0",
"rollup-plugin-esbuild": "^5.0.0",
"rollup-plugin-terser": "^7.0.2",
"rxjs": "^7.8.0",
@@ -202,7 +202,7 @@
"ts-node": "^10.9.1",
"tslib": "^2.4.1",
"typescript": "^4.9.4",
"valtio": "^1.7.6",
"valtio": "^1.8.0",
"wonka": "^6.1.2",
"xstate": "^4.35.1",
"zustand": "^4.1.5"
18 changes: 16 additions & 2 deletions src/vanilla/store.ts
Original file line number Diff line number Diff line change
@@ -528,7 +528,21 @@ export const createStore = () => {
mountDependencies(atom, atomState, prevAtomState?.d)
}
const mounted = mountedMap.get(atom)
mounted?.l.forEach((listener) => listener())
if (
mounted &&
!(
// TODO This seems pretty hacky. Hope to fix it.
// Maybe we could `mountDependencies` in `setAtomState`?
(
prevAtomState &&
!hasPromiseAtomValue(prevAtomState) &&
(isEqualAtomValue(prevAtomState, atomState) ||
isEqualAtomError(prevAtomState, atomState))
)
)
) {
mounted.l.forEach((listener) => listener())
}
} else if (__DEV__) {
console.warn('[Bug] no atom state to flush')
}
@@ -541,9 +555,9 @@ export const createStore = () => {

const subscribeAtom = (atom: AnyAtom, listener: () => void) => {
const mounted = addAtom(atom)
flushPending()
const listeners = mounted.l
listeners.add(listener)
flushPending()
return () => {
listeners.delete(listener)
delAtom(atom)
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
33 changes: 33 additions & 0 deletions tests/vanilla/store.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import { atom, createStore } from 'jotai/vanilla'

it('should not fire on subscribe', async () => {
const store = createStore()
const countAtom = atom(0)
const callback1 = jest.fn()
const callback2 = jest.fn()
store.sub(countAtom, callback1)
store.sub(countAtom, callback2)
expect(callback1).not.toBeCalled()
expect(callback2).not.toBeCalled()
})

it('should not fire subscription if primitive atom value is the same', async () => {
const store = createStore()
const countAtom = atom(0)
const callback = jest.fn()
store.sub(countAtom, callback)
const calledTimes = callback.mock.calls.length
store.set(countAtom, 0)
expect(callback).toBeCalledTimes(calledTimes)
})

it('should not fire subscription if derived atom value is the same', async () => {
const store = createStore()
const countAtom = atom(0)
const derivedAtom = atom((get) => get(countAtom) * 0)
const callback = jest.fn()
store.sub(derivedAtom, callback)
const calledTimes = callback.mock.calls.length
store.set(countAtom, 1)
expect(callback).toBeCalledTimes(calledTimes)
})
943 changes: 479 additions & 464 deletions yarn.lock

Large diffs are not rendered by default.