Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion src/API.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,16 @@ export interface EntryPointOrPackagesMap {
[name: string]: EntryPointOrPackage
}

export interface Contribution {
unsubscribe(): void
}

export type ExtensionItemFilter<T> = (extensionItem: ExtensionItem<T>) => boolean
export interface ExtensionSlot<T> {
readonly name: string
readonly host: AppHost
readonly declaringShell?: Shell
contribute(shell: Shell, item: T, condition?: ContributionPredicate): void
contribute(shell: Shell, item: T, condition?: ContributionPredicate): Contribution
getItems(forceAll?: boolean): ExtensionItem<T>[]
getSingleItem(): ExtensionItem<T>
getItemByName(name: string): ExtensionItem<T>
Expand Down
17 changes: 13 additions & 4 deletions src/extensionSlot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ import {
Shell,
SlotKey,
CustomExtensionSlot,
CustomExtensionSlotHandler
CustomExtensionSlotHandler,
Contribution
} from './API'
import _ from 'lodash'

Expand All @@ -32,13 +33,21 @@ export function createExtensionSlot<T>(key: SlotKey<T>, host: AppHost, declaring
discardBy
}

function contribute(fromShell: Shell, item: T, condition?: ContributionPredicate): void {
items.push({
function contribute(fromShell: Shell, item: T, condition?: ContributionPredicate): Contribution {
const contribution = {
shell: fromShell,
contribution: item,
condition: condition || alwaysTrue,
uniqueId: _.uniqueId(`${fromShell.name}_extItem_`)
})
}

items.push(contribution)

return {
unsubscribe: () => {
items = items.filter(i => i !== contribution)
}
}
}

function getItems(forceAll: boolean = false): ExtensionItem<T>[] {
Expand Down
3 changes: 2 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ export {
ShellLoggerSpan,
HostLogger,
LogSeverity,
APILayer
APILayer,
Contribution
} from './API'

export { AppMainView } from './appMainView'
Expand Down