refactor: init new state for body
This commit is contained in:
@@ -4,6 +4,7 @@ import {
|
||||
readonly,
|
||||
Ref,
|
||||
ref,
|
||||
watch,
|
||||
} from "@nuxtjs/composition-api"
|
||||
import { Observable, Subscription } from "rxjs"
|
||||
|
||||
@@ -58,3 +59,28 @@ export function useStream<T>(
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
export function pluckRef<T, K extends keyof T>(ref: Ref<T>, key: K): Ref<T[K]> {
|
||||
return customRef((track, trigger) => {
|
||||
const stopWatching = watch(ref, (newVal, oldVal) => {
|
||||
if (newVal[key] !== oldVal[key]) {
|
||||
trigger()
|
||||
}
|
||||
})
|
||||
|
||||
onBeforeUnmount(() => {
|
||||
stopWatching()
|
||||
})
|
||||
|
||||
return {
|
||||
get() {
|
||||
track()
|
||||
return ref.value[key]
|
||||
},
|
||||
set(value: T[K]) {
|
||||
trigger()
|
||||
ref.value = Object.assign(ref.value, { [key]: value })
|
||||
},
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
@@ -1,15 +0,0 @@
|
||||
export const knownContentTypes = [
|
||||
"application/json",
|
||||
"application/ld+json",
|
||||
"application/hal+json",
|
||||
"application/vnd.api+json",
|
||||
"application/xml",
|
||||
"application/x-www-form-urlencoded",
|
||||
"multipart/form-data",
|
||||
"text/html",
|
||||
"text/plain",
|
||||
]
|
||||
|
||||
export function isJSONContentType(contentType) {
|
||||
return /\bjson\b/i.test(contentType)
|
||||
}
|
||||
13
helpers/utils/contenttypes.ts
Normal file
13
helpers/utils/contenttypes.ts
Normal file
@@ -0,0 +1,13 @@
|
||||
export const knownContentTypes = {
|
||||
"application/json": "json",
|
||||
"application/ld+json": "json",
|
||||
"application/hal+json": "json",
|
||||
"application/vnd.api+json": "json",
|
||||
"application/xml": "xml",
|
||||
"application/x-www-form-urlencoded": "multipart",
|
||||
"multipart/form-data": "multipart",
|
||||
"text/html": "html",
|
||||
"text/plain": "plain",
|
||||
}
|
||||
|
||||
export type ValidContentTypes = keyof typeof knownContentTypes
|
||||
Reference in New Issue
Block a user