Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit13ac37b

Browse files
authored
breaking: drop deprecated devstore (#3095)
1 parentb5371c0 commit13ac37b

File tree

3 files changed

+41
-104
lines changed

3 files changed

+41
-104
lines changed

‎src/vanilla/atom.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
importtype{INTERNAL_PrdStoreasStore}from'./store'
1+
importtype{Store}from'./store'
22

33
typeGetter=<Value>(atom:Atom<Value>)=>Value
44

‎src/vanilla/store.ts‎

Lines changed: 6 additions & 95 deletions
Original file line numberDiff line numberDiff line change
@@ -1,93 +1,7 @@
1-
importtype{Atom,WritableAtom}from'./atom.ts'
2-
import{
3-
INTERNAL_buildStoreRev1asINTERNAL_buildStore,
4-
INTERNAL_initializeStoreHooks,
5-
}from'./internals.ts'
6-
importtype{INTERNAL_AtomState,INTERNAL_Store}from'./internals.ts'
1+
import{INTERNAL_buildStoreRev1asINTERNAL_buildStore}from'./internals.ts'
2+
importtype{INTERNAL_Store}from'./internals.ts'
73

8-
// TODO: rename this to `Store` in the near future
9-
exporttypeINTERNAL_PrdStore=INTERNAL_Store
10-
11-
// For debugging purpose only
12-
// This will be removed in the near future
13-
/*@deprecated Deprecated: Use devstore from the devtools library */
14-
exporttypeINTERNAL_DevStoreRev4={
15-
dev4_get_internal_weak_map:()=>{
16-
get:(atom:Atom<unknown>)=>INTERNAL_AtomState|undefined
17-
}
18-
dev4_get_mounted_atoms:()=>Set<Atom<unknown>>
19-
dev4_restore_atoms:(
20-
values:Iterable<readonly[Atom<unknown>,unknown]>,
21-
)=>void
22-
}
23-
24-
/*@deprecated Deprecated: Use devstore from the devtools library */
25-
constcreateDevStoreRev4=():INTERNAL_PrdStore&INTERNAL_DevStoreRev4=>{
26-
letinRestoreAtom=0
27-
conststoreHooks=INTERNAL_initializeStoreHooks({})
28-
constatomStateMap=newWeakMap()
29-
constmountedAtoms=newWeakMap()
30-
conststore=INTERNAL_buildStore(
31-
atomStateMap,
32-
mountedAtoms,
33-
undefined,
34-
undefined,
35-
undefined,
36-
undefined,
37-
storeHooks,
38-
undefined,
39-
(atom,get,set, ...args)=>{
40-
if(inRestoreAtom){
41-
returnset(atom, ...args)
42-
}
43-
returnatom.write(get,set, ...args)
44-
},
45-
)
46-
constdebugMountedAtoms=newSet<Atom<unknown>>()
47-
storeHooks.m.add(undefined,(atom)=>{
48-
debugMountedAtoms.add(atom)
49-
constatomState=atomStateMap.get(atom)
50-
// For DevStoreRev4 compatibility
51-
;(atomStateasany).m=mountedAtoms.get(atom)
52-
})
53-
storeHooks.u.add(undefined,(atom)=>{
54-
debugMountedAtoms.delete(atom)
55-
constatomState=atomStateMap.get(atom)
56-
// For DevStoreRev4 compatibility
57-
delete(atomStateasany).m
58-
})
59-
constdevStore:INTERNAL_DevStoreRev4={
60-
// store dev methods (these are tentative and subject to change without notice)
61-
dev4_get_internal_weak_map:()=>{
62-
console.log('Deprecated: Use devstore from the devtools library')
63-
returnatomStateMap
64-
},
65-
dev4_get_mounted_atoms:()=>debugMountedAtoms,
66-
dev4_restore_atoms:(values)=>{
67-
constrestoreAtom:WritableAtom<null,[],void>={
68-
read:()=>null,
69-
write:(_get,set)=>{
70-
++inRestoreAtom
71-
try{
72-
for(const[atom,value]ofvalues){
73-
if('init'inatom){
74-
set(atomasnever,value)
75-
}
76-
}
77-
}finally{
78-
--inRestoreAtom
79-
}
80-
},
81-
}
82-
store.set(restoreAtom)
83-
},
84-
}
85-
returnObject.assign(store,devStore)
86-
}
87-
88-
typePrdOrDevStore=
89-
|INTERNAL_PrdStore
90-
|(INTERNAL_PrdStore&INTERNAL_DevStoreRev4)
4+
exporttypeStore=INTERNAL_Store
915

926
letoveriddenCreateStore:typeofcreateStore|undefined
937

@@ -97,19 +11,16 @@ export function INTERNAL_overrideCreateStore(
9711
overiddenCreateStore=fn(overiddenCreateStore)
9812
}
9913

100-
exportfunctioncreateStore():PrdOrDevStore{
14+
exportfunctioncreateStore():Store{
10115
if(overiddenCreateStore){
10216
returnoveriddenCreateStore()
10317
}
104-
if(import.meta.env?.MODE!=='production'){
105-
returncreateDevStoreRev4()
106-
}
10718
returnINTERNAL_buildStore()
10819
}
10920

110-
letdefaultStore:PrdOrDevStore|undefined
21+
letdefaultStore:Store|undefined
11122

112-
exportfunctiongetDefaultStore():PrdOrDevStore{
23+
exportfunctiongetDefaultStore():Store{
11324
if(!defaultStore){
11425
defaultStore=createStore()
11526
if(import.meta.env?.MODE!=='production'){

‎tests/vanilla/store.test.tsx‎

Lines changed: 34 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,37 @@ import type { Atom, Getter, PrimitiveAtom } from 'jotai/vanilla'
55
import{
66
INTERNAL_buildStoreRev1asINTERNAL_buildStore,
77
INTERNAL_getBuildingBlocksRev1asINTERNAL_getBuildingBlocks,
8+
INTERNAL_initializeStoreHooks,
89
}from'jotai/vanilla/internals'
10+
importtype{INTERNAL_Store}from'jotai/vanilla/internals'
11+
12+
typeDevStore={
13+
get_mounted_atoms:()=>Set<Atom<unknown>>
14+
}
15+
16+
constcreateDevStore=():INTERNAL_Store&DevStore=>{
17+
conststoreHooks=INTERNAL_initializeStoreHooks({})
18+
conststore=INTERNAL_buildStore(
19+
undefined,
20+
undefined,
21+
undefined,
22+
undefined,
23+
undefined,
24+
undefined,
25+
storeHooks,
26+
)
27+
constdebugMountedAtoms=newSet<Atom<unknown>>()
28+
storeHooks.m.add(undefined,(atom)=>{
29+
debugMountedAtoms.add(atom)
30+
})
31+
storeHooks.u.add(undefined,(atom)=>{
32+
debugMountedAtoms.delete(atom)
33+
})
34+
constdevStore:DevStore={
35+
get_mounted_atoms:()=>debugMountedAtoms,
36+
}
37+
returnObject.assign(store,devStore)
38+
}
939

1040
typeAtomStateMapType=ReturnType<typeofINTERNAL_getBuildingBlocks>[0]
1141

@@ -52,29 +82,25 @@ it('should not fire subscription if derived atom value is the same', async () =>
5282
})
5383

5484
it('should unmount with store.get',async()=>{
55-
conststore=createStore()
85+
conststore=createDevStore()
5686
constcountAtom=atom(0)
5787
constcallback=vi.fn()
5888
constunsub=store.sub(countAtom,callback)
5989
store.get(countAtom)
6090
unsub()
61-
constresult=Array.from(
62-
'dev4_get_mounted_atoms'instore ?store.dev4_get_mounted_atoms() :[],
63-
)
91+
constresult=Array.from(store.get_mounted_atoms())
6492
expect(result).toEqual([])
6593
})
6694

6795
it('should unmount dependencies with store.get',async()=>{
68-
conststore=createStore()
96+
conststore=createDevStore()
6997
constcountAtom=atom(0)
7098
constderivedAtom=atom((get)=>get(countAtom)*2)
7199
constcallback=vi.fn()
72100
constunsub=store.sub(derivedAtom,callback)
73101
store.get(derivedAtom)
74102
unsub()
75-
constresult=Array.from(
76-
'dev4_restore_atoms'instore ?store.dev4_get_mounted_atoms() :[],
77-
)
103+
constresult=Array.from(store.get_mounted_atoms())
78104
expect(result).toEqual([])
79105
})
80106

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp