feat: migrate pre-request script, test script, settings to nuxt composition
This commit is contained in:
@@ -20,6 +20,7 @@ export interface HoppRESTRequest {
|
||||
params: HoppRESTParam[]
|
||||
headers: HoppRESTHeader[]
|
||||
preRequestScript: string
|
||||
testScript: string
|
||||
}
|
||||
|
||||
export function makeRESTRequest(
|
||||
@@ -56,6 +57,7 @@ export function translateToNewRequest(x: any): HoppRESTRequest {
|
||||
const method = x.method
|
||||
|
||||
const preRequestScript = x.preRequestScript
|
||||
const testScript = x.testScript
|
||||
|
||||
const result: HoppRESTRequest = {
|
||||
endpoint,
|
||||
@@ -63,6 +65,7 @@ export function translateToNewRequest(x: any): HoppRESTRequest {
|
||||
params,
|
||||
method,
|
||||
preRequestScript,
|
||||
testScript,
|
||||
v: RESTReqSchemaVersion,
|
||||
}
|
||||
|
||||
|
||||
60
helpers/utils/composables.ts
Normal file
60
helpers/utils/composables.ts
Normal file
@@ -0,0 +1,60 @@
|
||||
import {
|
||||
customRef,
|
||||
onBeforeUnmount,
|
||||
readonly,
|
||||
Ref,
|
||||
ref,
|
||||
} from "@nuxtjs/composition-api"
|
||||
import { Observable, Subscription } from "rxjs"
|
||||
|
||||
export function useReadonlyStream<T>(stream$: Observable<T>, initialValue: T) {
|
||||
let sub: Subscription | null = null
|
||||
|
||||
onBeforeUnmount(() => {
|
||||
if (sub) {
|
||||
sub.unsubscribe()
|
||||
}
|
||||
})
|
||||
|
||||
const targetRef = ref(initialValue) as Ref<T>
|
||||
|
||||
sub = stream$.subscribe((value) => {
|
||||
targetRef.value = value
|
||||
})
|
||||
|
||||
return readonly(targetRef)
|
||||
}
|
||||
|
||||
export function useStream<T>(
|
||||
stream$: Observable<T>,
|
||||
initialValue: T,
|
||||
setter: (val: T) => void
|
||||
) {
|
||||
let sub: Subscription | null = null
|
||||
|
||||
onBeforeUnmount(() => {
|
||||
if (sub) {
|
||||
sub.unsubscribe()
|
||||
}
|
||||
})
|
||||
|
||||
return customRef((track, trigger) => {
|
||||
let value = initialValue
|
||||
|
||||
sub = stream$.subscribe((val) => {
|
||||
value = val
|
||||
trigger()
|
||||
})
|
||||
|
||||
return {
|
||||
get() {
|
||||
track()
|
||||
return value
|
||||
},
|
||||
set(value: T) {
|
||||
trigger()
|
||||
setter(value)
|
||||
},
|
||||
}
|
||||
})
|
||||
}
|
||||
Reference in New Issue
Block a user