Skip to content

Commit

Permalink
Add Core-preProcessTrackConfig extension point (#3653)
Browse files Browse the repository at this point in the history
  • Loading branch information
cmdcolin committed May 18, 2023
1 parent 42aa5b3 commit 001f2cc
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 10 deletions.
17 changes: 13 additions & 4 deletions packages/core/pluggableElementTypes/models/baseTrackConfig.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
/* eslint-disable @typescript-eslint/no-explicit-any */
import { types, Instance } from 'mobx-state-tree'
import { ConfigurationSchema } from '../../configuration'
import PluginManager from '../../PluginManager'
Expand Down Expand Up @@ -139,15 +138,23 @@ export function createBaseTrackConfig(pluginManager: PluginManager) {
}),
},
{
preProcessSnapshot: s => {
const snap = JSON.parse(JSON.stringify(s))
preProcessSnapshot: s2 => {
const snap = pluginManager.evaluateExtensionPoint(
'Core-preProcessTrackConfig',
JSON.parse(JSON.stringify(s2)),
) as {
trackId: string
name: string
type: string
displays: { type: string; displayId: string }[]
}
const displayTypes = new Set()
const { displays = [] } = snap
if (snap.trackId !== 'placeholderId') {
// Gets the displays on the track snapshot and the possible displays
// from the track type and adds any missing possible displays to the
// snapshot
displays.forEach((d: any) => d && displayTypes.add(d.type))
displays.forEach(d => d && displayTypes.add(d.type))
const trackType = pluginManager.getTrackType(snap.type)
trackType.displayTypes.forEach(displayType => {
if (!displayTypes.has(displayType.name)) {
Expand All @@ -165,13 +172,15 @@ export function createBaseTrackConfig(pluginManager: PluginManager) {
*/
explicitIdentifier: 'trackId',
explicitlyTyped: true,
// eslint-disable-next-line @typescript-eslint/no-explicit-any
actions: (self: any) => ({
addDisplayConf(conf: { type: string; displayId: string }) {
const { type } = conf
if (!type) {
throw new Error(`unknown display type ${type}`)
}
const display = self.displays.find(
// eslint-disable-next-line @typescript-eslint/no-explicit-any
(d: any) => d?.displayId === conf.displayId,
)
if (display) {
Expand Down
32 changes: 26 additions & 6 deletions website/docs/developer_guides/extension_points.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@ title: Extension points

The basic API is that producers can say:

```js
```typescript
const ret = pluginManager.evaluateExtensionPoint('ExtensionPointName', {
value: 1,
})
```

And consumers can say:

```js
```typescript
pluginManager.addToExtensionPoint('ExtensionPointName', arg => {
return arg.value + 1
})
Expand All @@ -37,7 +37,7 @@ call or add to.

The API is

```js
```typescript
// extra props are optional, can pass an extra context object your extension
// point receives
pluginManager.evaluateExtensionPoint(extensionPointName, args, props)
Expand All @@ -48,7 +48,7 @@ along to the args argument of the next one), and props are just passed along

There is also an async method:

```js
```typescript
// extra props are optional, can pass an extra context object your extension
// point receives
pluginManager.evaluateAsyncExtensionPoint(extensionPointName, args, props)
Expand All @@ -57,7 +57,7 @@ pluginManager.evaluateAsyncExtensionPoint(extensionPointName, args, props)
Users can additionally add to extension points, so that when they are evaluated,
it runs a chain of callbacks that are registered to that extension point:

```js
```typescript
pluginManager.addToExtensionPoint(extensionPointName, callback => newArgs)
```

Expand Down Expand Up @@ -395,7 +395,7 @@ use for the panel

Example:

```js
```typescript
pluginManager.addToExtensionPoint(
'Core-extraFeaturePanel',
(DefaultFeatureExtra, { model }) => {
Expand All @@ -406,6 +406,26 @@ pluginManager.addToExtensionPoint(
)
```

### Core-preProcessTrackConfig

type: synchronous

- `args` - `SnapshotIn<AnyConfigurationModel>` - Copy of the current track
config

Return value: A new track config

Example:

```typescript
pluginManager.addToExtensionPoint('Core-preProcessTrackConfig', snap => {
return {
...snap.metadata,
extraMetadata: 'extra metadata',
}
})
```

### LinearGenomeView-TracksContainer

type: synchronous
Expand Down

0 comments on commit 001f2cc

Please sign in to comment.