-
-
Notifications
You must be signed in to change notification settings - Fork 92
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: Partial move stateful services to stateless
- Loading branch information
Showing
27 changed files
with
369 additions
and
494 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import { Instance, InstanceOptionsServiceKey } from '@xmcl/runtime-api' | ||
import { Ref } from 'vue' | ||
import { useService } from './service' | ||
import { useState } from './syncableState' | ||
|
||
export function useInstanceOptions(instance: Ref<Instance>) { | ||
const { watchOptions } = useService(InstanceOptionsServiceKey) | ||
return useState(computed(() => instance.value.path), () => watchOptions(instance.value.path)) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import { Disposable } from '@xmcl/runtime-api' | ||
import { Ref } from 'vue' | ||
|
||
export function useState<T>(key: Ref<string>, fetcher: () => Promise<Disposable<T>>) { | ||
const isValidating = ref(false) | ||
const state = ref<T | undefined>() | ||
let dispose = () => { } | ||
const error = ref(undefined as any) | ||
const mutate = () => { | ||
isValidating.value = true | ||
dispose() | ||
fetcher().then((v) => { | ||
state.value = v | ||
dispose = v.dispose | ||
}, (e) => { | ||
error.value = e | ||
}).finally(() => { | ||
isValidating.value = false | ||
}) | ||
} | ||
watch(key, mutate) | ||
onMounted(mutate) | ||
onUnmounted(dispose) | ||
return { | ||
isValidating, | ||
state, | ||
error, | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.