docs/frontend-system: update existing usage of ApiBlueprint
Signed-off-by: Patrik Oldsberg <poldsberg@gmail.com>
This commit is contained in:
@@ -199,13 +199,12 @@ import { ApiBlueprint } from '@backstage/frontend-plugin-api';
|
||||
|
||||
const scmIntegrationsApi = ApiBlueprint.make({
|
||||
name: 'scm-integrations',
|
||||
params: {
|
||||
factory: createApiFactory({
|
||||
params: define =>
|
||||
define({
|
||||
api: scmIntegrationsApiRef,
|
||||
deps: { configApi: configApiRef },
|
||||
factory: ({ configApi }) => ScmIntegrationsApi.fromConfig(configApi),
|
||||
}),
|
||||
},
|
||||
});
|
||||
```
|
||||
|
||||
|
||||
@@ -154,19 +154,18 @@ export function ExamplePage() {
|
||||
```
|
||||
|
||||
```tsx title="in src/plugin.ts - Registering a factory for our API"
|
||||
import { createApiFactory, ApiBlueprint } from '@backstage/frontend-plugin-api';
|
||||
import { ApiBlueprint } from '@backstage/frontend-plugin-api';
|
||||
import { exampleApiRef, DefaultExampleApi } from './api';
|
||||
|
||||
// highlight-add-start
|
||||
const exampleApi = ApiBlueprint.make({
|
||||
name: 'example',
|
||||
params: {
|
||||
factory: createApiFactory({
|
||||
params: define =>
|
||||
define({
|
||||
api: exampleApiRef,
|
||||
deps: {},
|
||||
factory: () => new DefaultExampleApi(),
|
||||
}),
|
||||
},
|
||||
});
|
||||
// highlight-add-end
|
||||
|
||||
|
||||
@@ -205,22 +205,17 @@ The major changes we'll make are
|
||||
The end result, after simplifying imports and cleaning up a bit, might look like this:
|
||||
|
||||
```tsx title="in @internal/plugin-example"
|
||||
import {
|
||||
storageApiRef,
|
||||
createApiFactory,
|
||||
ApiBlueprint,
|
||||
} from '@backstage/frontend-plugin-api';
|
||||
import { storageApiRef, ApiBlueprint } from '@backstage/frontend-plugin-api';
|
||||
import { workApiRef } from '@internal/plugin-example-react';
|
||||
import { WorkImpl } from './WorkImpl';
|
||||
|
||||
const exampleWorkApi = ApiBlueprint.make({
|
||||
params: {
|
||||
factory: createApiFactory({
|
||||
params: define =>
|
||||
define({
|
||||
api: workApiRef,
|
||||
deps: { storageApi: storageApiRef },
|
||||
factory: ({ storageApi }) => new WorkImpl({ storageApi }),
|
||||
}),
|
||||
},
|
||||
});
|
||||
```
|
||||
|
||||
|
||||
@@ -45,7 +45,6 @@ The plugin itself now wants to provide this API and its default implementation,
|
||||
```tsx title="in @internal/plugin-example"
|
||||
import {
|
||||
ApiBlueprint,
|
||||
createApiFactory,
|
||||
createFrontendPlugin,
|
||||
storageApiRef,
|
||||
StorageApi,
|
||||
@@ -63,15 +62,14 @@ class WorkImpl implements WorkApi {
|
||||
|
||||
const workApi = ApiBlueprint.make({
|
||||
name: 'work',
|
||||
params: {
|
||||
factory: createApiFactory({
|
||||
params: define =>
|
||||
define({
|
||||
api: workApiRef,
|
||||
deps: { storageApi: storageApiRef },
|
||||
factory: ({ storageApi }) => {
|
||||
return new WorkImpl({ storageApi });
|
||||
},
|
||||
}),
|
||||
},
|
||||
});
|
||||
|
||||
/**
|
||||
|
||||
@@ -46,14 +46,13 @@ Your utility APIs can depend on other utility APIs in their factories. You do th
|
||||
import {
|
||||
configApiRef,
|
||||
ApiBlueprint,
|
||||
createApiFactory,
|
||||
discoveryApiRef,
|
||||
} from '@backstage/frontend-plugin-api';
|
||||
import { MyApiImpl } from './MyApiImpl';
|
||||
|
||||
const myApi = ApiBlueprint.make({
|
||||
params: {
|
||||
factory: createApiFactory({
|
||||
params: define =>
|
||||
define({
|
||||
api: myApiRef,
|
||||
deps: {
|
||||
configApi: configApiRef,
|
||||
@@ -63,7 +62,6 @@ const myApi = ApiBlueprint.make({
|
||||
return new MyApiImpl({ configApi, discoveryApi });
|
||||
},
|
||||
}),
|
||||
},
|
||||
});
|
||||
```
|
||||
|
||||
|
||||
Reference in New Issue
Block a user