Skip to content

Commit

Permalink
refactor: move remaining platform bits into dioc v3 style
Browse files Browse the repository at this point in the history
  • Loading branch information
AndrewBastin committed Apr 25, 2024
1 parent d48196e commit 5587248
Show file tree
Hide file tree
Showing 7 changed files with 17 additions and 20 deletions.
Expand Up @@ -201,7 +201,7 @@ export class TeamSearchService extends Service {
expandingCollections: Ref<string[]> = ref([])
expandedCollections: Ref<string[]> = ref([])

// FUTURE-TODO: ideally this should return the search results / formatted results instead of directly manipulating the result set
// TODO: ideally this should return the search results / formatted results instead of directly manipulating the result set
// eg: do the spotlight formatting in the spotlight searcher and not here
searchTeams = async (query: string, teamID: string) => {
if (!query.length) {
Expand Down
7 changes: 3 additions & 4 deletions packages/hoppscotch-common/src/modules/dioc.ts
@@ -1,5 +1,5 @@
import { HoppModule } from "."
import { Container, Service } from "dioc"
import { Container, ServiceClassInstance } from "dioc"
import { diocPlugin } from "dioc/vue"
import { DebugService } from "~/services/debug.service"
import { platform } from "~/platform"
Expand All @@ -22,19 +22,18 @@ if (import.meta.env.DEV) {
* services. Please use `useService` if within components or try to convert your
* legacy subsystem into a service if possible.
*/
export function getService<T extends typeof Service<any> & { ID: string }>(
export function getService<T extends ServiceClassInstance<any>>(
service: T
): InstanceType<T> {
return serviceContainer.bind(service)
}

export default <HoppModule>{
onVueAppInit(app) {
// TODO: look into this
// @ts-expect-error Something weird with Vue versions
app.use(diocPlugin, {
container: serviceContainer,
})

for (const service of platform.addedServices ?? []) {
serviceContainer.bind(service)
}
Expand Down
4 changes: 2 additions & 2 deletions packages/hoppscotch-common/src/platform/index.ts
Expand Up @@ -8,14 +8,14 @@ import { AnalyticsPlatformDef } from "./analytics"
import { InterceptorsPlatformDef } from "./interceptors"
import { HoppModule } from "~/modules"
import { InspectorsPlatformDef } from "./inspectors"
import { Service } from "dioc"
import { ServiceClassInstance } from "dioc"
import { IOPlatformDef } from "./io"
import { SpotlightPlatformDef } from "./spotlight"

export type PlatformDef = {
ui?: UIPlatformDef
addedHoppModules?: HoppModule[]
addedServices?: Array<typeof Service<unknown> & { ID: string }>
addedServices?: Array<ServiceClassInstance<unknown>>
auth: AuthPlatformDef
analytics?: AnalyticsPlatformDef
io: IOPlatformDef
Expand Down
7 changes: 4 additions & 3 deletions packages/hoppscotch-common/src/platform/inspectors.ts
@@ -1,4 +1,4 @@
import { Service } from "dioc"
import { Container, ServiceClassInstance } from "dioc"
import { Inspector } from "~/services/inspection"

/**
Expand All @@ -8,8 +8,9 @@ export type PlatformInspectorsDef = {
// We are keeping this as the only mode for now
// So that if we choose to add other modes, we can do without breaking
type: "service"
service: typeof Service<unknown> & { ID: string } & {
new (): Service & Inspector
// TODO: I don't think this type is effective, we have to come up with a better impl
service: ServiceClassInstance<unknown> & {
new (c: Container): Inspector
}
}

Expand Down
7 changes: 4 additions & 3 deletions packages/hoppscotch-common/src/platform/interceptors.ts
@@ -1,12 +1,13 @@
import { Service } from "dioc"
import { Container, ServiceClassInstance } from "dioc"
import { Interceptor } from "~/services/interceptor.service"

export type PlatformInterceptorDef =
| { type: "standalone"; interceptor: Interceptor }
| {
type: "service"
service: typeof Service<unknown> & { ID: string } & {
new (): Service & Interceptor
// TODO: I don't think this type is effective, we have to come up with a better impl
service: ServiceClassInstance<unknown> & {
new (c: Container): Interceptor
}
}

Expand Down
6 changes: 3 additions & 3 deletions packages/hoppscotch-common/src/platform/spotlight.ts
@@ -1,10 +1,10 @@
import { Service } from "dioc"
import { Container, ServiceClassInstance } from "dioc"
import { SpotlightSearcher } from "~/services/spotlight"

export type SpotlightPlatformDef = {
additionalSearchers?: Array<
typeof Service<unknown> & { ID: string } & {
new (): Service & SpotlightSearcher
ServiceClassInstance<unknown> & {
new (c: Container): SpotlightSearcher
}
>
}
Expand Up @@ -138,10 +138,6 @@ export class NativeInterceptorService extends Service implements Interceptor {

public cookieJarService = this.bind(CookieJarService)

constructor() {
super()
}

public runRequest(req: any) {
const processedReq = preProcessRequest(req)

Expand Down

0 comments on commit 5587248

Please sign in to comment.