Skip to content

Commit

Permalink
eclipse-che/che#9063 use own Disposable class in extension API
Browse files Browse the repository at this point in the history
  • Loading branch information
evidolob committed Mar 20, 2018
1 parent a4fb72d commit 5a04565
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@
* Red Hat, Inc. - initial API and implementation
*/
import { CommandRegistryExt, EXTENSION_RPC_CONTEXT as Ext, CommandRegistryMain } from '../api/extension-api';
import { Disposable } from '@theia/core/lib/common/disposable';
import { RPCProtocol } from '../api/rpc-protocol';
import * as theia from 'theia';
import { Disposable } from './types-impl';

export type Handler = <T>(...args: any[]) => T | PromiseLike<T>;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@
* Red Hat, Inc. - initial API and implementation
*/
import { MAIN_RPC_CONTEXT } from '../api/extension-api';
import { Disposable } from '@theia/core/lib/common/disposable';
import { RPCProtocol } from '../api/rpc-protocol';
import * as theia from 'theia';
import { CommandRegistryImpl } from './comand-registry';
import { Disposable } from './types-impl';

export function createAPI(rpc: RPCProtocol): typeof theia {
const commandRegistryExt = rpc.set(MAIN_RPC_CONTEXT.COMMAND_REGISTRY_EXT, new CommandRegistryImpl(rpc));
Expand All @@ -23,7 +23,8 @@ export function createAPI(rpc: RPCProtocol): typeof theia {
}
};
return <typeof theia>{
commands
commands,
Disposable: Disposable
};

}
31 changes: 31 additions & 0 deletions packages/isolated-extension-api/src/extension/types-impl.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/*
* Copyright (C) 2018 Red Hat, Inc.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Red Hat, Inc. - initial API and implementation
*/

export class Disposable {
private disposable: undefined | (() => void);

constructor(func: () => void) {
this.disposable = func;
}
/**
* Dispose this object.
*/
dispose(): void {
if (this.disposable) {
this.disposable();
this.disposable = undefined;
}
}

static create(func: () => void): Disposable {
return new Disposable(func);
}
}
14 changes: 13 additions & 1 deletion packages/isolated-extension-api/src/theia.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,21 @@
* Contributors:
* Red Hat, Inc. - initial API and implementation
*/
//import { Disposable } from '@theia/core/lib/common/disposable';

declare module 'theia' {

export class Disposable {

constructor(func: () => void);
/**
* Dispose this object.
*/
dispose(): void;

static create(func: () => void): Disposable;

}

/**
* A command is a unique identifier of a function
* which can be executed by a user via a keyboard shortcut,
Expand Down

0 comments on commit 5a04565

Please sign in to comment.