-
Notifications
You must be signed in to change notification settings - Fork 23
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Remove ng modules #2247
Remove ng modules #2247
Changes from 5 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import { ApplicationConfig } from '@angular/core'; | ||
import { provideConnect } from "../connect/connect.module"; | ||
import { provideProtractorTestingSupport } from "@angular/platform-browser"; | ||
|
||
export const appConfig: ApplicationConfig = { | ||
providers: [ | ||
provideConnect({ | ||
baseUrl: "https://demo.connectrpc.com", | ||
}), | ||
provideProtractorTestingSupport(), | ||
], | ||
}; |
This file was deleted.
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,29 +1,56 @@ | ||
import { ModuleWithProviders, NgModule } from "@angular/core"; | ||
import { Interceptor } from "@connectrpc/connect"; | ||
import { createConnectTransport } from "@connectrpc/connect-web"; | ||
import { INTERCEPTORS, TRANSPORT } from "./tokens"; | ||
import { inject, InjectionToken, Provider } from "@angular/core"; | ||
import { Interceptor, Transport } from "@connectrpc/connect"; | ||
import { | ||
createConnectTransport, | ||
createGrpcWebTransport, | ||
} from "@connectrpc/connect-web"; | ||
import { DescService } from "@bufbuild/protobuf"; | ||
import { createObservableClient, ObservableClient } from "./observable-client"; | ||
|
||
@NgModule() | ||
export class ConnectModule { | ||
public static forRoot( | ||
connectOptions: Omit< | ||
Parameters<typeof createConnectTransport>[0], | ||
"interceptors" | ||
>, | ||
): ModuleWithProviders<ConnectModule> { | ||
return { | ||
ngModule: ConnectModule, | ||
providers: [ | ||
{ | ||
provide: TRANSPORT, | ||
useFactory: (interceptors: Interceptor[]) => | ||
createConnectTransport({ | ||
...connectOptions, | ||
interceptors: interceptors, | ||
}), | ||
deps: [INTERCEPTORS], | ||
}, | ||
], | ||
}; | ||
} | ||
const TRANSPORT = new InjectionToken<Transport>("connect.transport"); | ||
|
||
const INTERCEPTORS = new InjectionToken<Interceptor[]>("connect.interceptors", { | ||
factory: () => [], | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Users can't add an interceptor if you don't export this const. |
||
}); | ||
|
||
export function createClientToken<T extends DescService>( | ||
service: T, | ||
): InjectionToken<ObservableClient<T>> { | ||
return new InjectionToken(`client for ${service.typeName}`, { | ||
factory() { | ||
return createObservableClient(service, inject(TRANSPORT)); | ||
}, | ||
}); | ||
} | ||
|
||
export function provideConnect( | ||
options: Omit<Parameters<typeof createConnectTransport>[0], "interceptors">, | ||
): Provider[] { | ||
return [ | ||
{ | ||
provide: TRANSPORT, | ||
useFactory: (interceptors: Interceptor[]) => | ||
createConnectTransport({ | ||
...options, | ||
interceptors, | ||
}), | ||
deps: [INTERCEPTORS], | ||
}, | ||
]; | ||
} | ||
|
||
export function provideGrpcWeb( | ||
options: Omit<Parameters<typeof createGrpcWebTransport>[0], "interceptors">, | ||
): Provider[] { | ||
return [ | ||
{ | ||
provide: TRANSPORT, | ||
useFactory: (interceptors: Interceptor[]) => | ||
createGrpcWebTransport({ | ||
...options, | ||
interceptors, | ||
}), | ||
deps: [INTERCEPTORS], | ||
}, | ||
]; | ||
} |
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,7 @@ | ||
import { InjectionToken } from "@angular/core"; | ||
import type { Interceptor, Transport } from "@connectrpc/connect"; | ||
import { ElizaService } from "src/gen/connectrpc/eliza/v1/eliza_pb"; | ||
import { ObservableClient } from "./observable-client"; | ||
import { createClientToken } from "./connect.module"; | ||
|
||
export const TRANSPORT = new InjectionToken<Transport>("connect.transport"); | ||
// Create an injection token for the Eliza service client | ||
export const ELIZA = createClientToken(ElizaService); | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we move this to There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. tokens.ts would be modified by users, connect.module.ts won't. We don't publish this as a library. I don't feel strongly about it. Do whatever it takes 🙂 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fair enough. In 68b684a, I unexported the transport and interceptor tokens since they're only used in |
||
export const INTERCEPTORS = new InjectionToken<Interceptor[]>( | ||
"connect.interceptors", | ||
{ | ||
factory: () => [], | ||
}, | ||
); | ||
|
||
export const ELIZA = new InjectionToken<ObservableClient<typeof ElizaService>>( | ||
ElizaService.name, | ||
); | ||
// Additional client tokens representing Connect services could be added here |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,7 @@ | ||
import { enableProdMode } from '@angular/core'; | ||
import { platformBrowserDynamic } from '@angular/platform-browser-dynamic'; | ||
import { bootstrapApplication } from '@angular/platform-browser'; | ||
import { AppComponent } from './app/app.component'; | ||
import { appConfig } from "./app/app.config"; | ||
|
||
import { AppModule } from './app/app.module'; | ||
import { environment } from './environments/environment'; | ||
|
||
if (environment.production) { | ||
enableProdMode(); | ||
} | ||
|
||
platformBrowserDynamic().bootstrapModule(AppModule) | ||
.catch(err => console.error(err)); | ||
bootstrapApplication(AppComponent, appConfig).catch((err) => | ||
console.error(err), | ||
); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Instead of
@Inject
, we use the functioninject
.