Updating state in a promise is not working? #11413
-
In Not working:
Working:
|
Beta Was this translation helpful? Give feedback.
Answered by
paoloricciuti
May 1, 2024
Replies: 1 comment 1 reply
-
Tbf it feels strange that this store.directory = await LocalFileSystemAdapter(store.localDirectory); is working. To cross module/function boundaries you need getters and setters. // store.svelte.ts
import { UniversalDirectory } from './filesystem.svelte';
let localDirectory: FileSystemDirectoryHandle = $state();
let directory: UniversalDirectory = $state();
export const store = {
get localDirectory(){
return localDirectory;
},
set localDirectory(ld){
localDirectory = ld;
},
get directory(){
return directory;
},
set directory(d){
directory = d;
},
}; Alternatively if you are ok with only modifying the property of the store and never re-assign the store itself you can make use of the proxied nature of // store.svelte.ts
export const store = $state<YourType>({
localDirectory: undefined,
directory: undefined
}); |
Beta Was this translation helpful? Give feedback.
1 reply
Answer selected by
intzaaa
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Tbf it feels strange that this
is working. To cross module/function boundaries you need getters and setters.
Alternatively if you are ok with only m…