How to use the inversify.injectable function in inversify

To help you get started, we’ve selected a few inversify examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github DonJayamanne / pythonVSCode / src / client / datascience / jupyter / jupyterSessionManagerFactory.ts View on Github external
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
'use strict';
import { inject, injectable } from 'inversify';

import { IConfigurationService } from '../../common/types';
import { IConnection, IJupyterPasswordConnect, IJupyterSessionManager, IJupyterSessionManagerFactory } from '../types';
import { JupyterSessionManager } from './jupyterSessionManager';
import { KernelSelector } from './kernels/kernelSelector';

@injectable()
export class JupyterSessionManagerFactory implements IJupyterSessionManagerFactory {

    constructor(
        @inject(IJupyterPasswordConnect) private jupyterPasswordConnect: IJupyterPasswordConnect,
        @inject(IConfigurationService) private config: IConfigurationService,
        @inject(KernelSelector) private kernelSelector: KernelSelector
    ) {
    }

    /**
     * Creates a new IJupyterSessionManager.
     * @param connInfo - connection information to the server that's already running.
     * @param failOnPassword - whether or not to fail the creation if a password is required.
     */
    public async create(connInfo: IConnection, failOnPassword?: boolean): Promise {
        const result = new JupyterSessionManager(this.jupyterPasswordConnect, this.config, failOnPassword, this.kernelSelector);
github JohnSimerlink / branches_front_end_private / app / objects / Subscribable.ts View on Github external
// tslint:disable max-classes-per-file
import {inject, injectable} from 'inversify';
import {ISubscribable, updatesCallback} from './ISubscribable';
import {IDatedMutation} from './mutations/IMutation';
import {SetMutationTypes} from './set/SetMutationTypes';
import {TYPES} from './types';

@injectable()
    // TODO: make abstract?
class Subscribable implements ISubscribable {
    protected updates: {val?: object} = {}
    protected pushes: {mutations?: IDatedMutation} = {}
    private updatesCallbacks: updatesCallback[];
    constructor(@inject(TYPES.SubscribableArgs){updatesCallbacks = []} = {updatesCallbacks: []}) {
        this.updatesCallbacks = updatesCallbacks /* let updatesCallbacks be injected for
         1) modularity reasons
         2) if we want to cache the state of this entire object, we could load in the previous state
         of set, mutations, and updatesCallbacks easy-peasy
         */
    }
    public onUpdate(func: updatesCallback) {
        // throw new TypeError('func - ' + JSON.stringify(func))
        this.updatesCallbacks.push(func)
    }
github eclipse / sprotty / src / model-source / commit-model.ts View on Github external
import { TYPES } from "../base/types";
import { ModelSource } from "./model-source";

/**
 * Commit the current SModel back to the model source.
 *
 * The SModel (AKA internal model) contains a lot of dirty/transitional state, such
 * as intermediate move postions or handles. When a user interaction that spans multiple
 * commands finishes, it fires a CommitModelAction to write the final changes back to
 * the model source.
 */
export class CommitModelAction implements Action {
    readonly kind = CommitModelCommand.KIND;
}

@injectable()
export class CommitModelCommand extends SystemCommand {
    static readonly KIND = 'commitModel';

    @inject(TYPES.ModelSource) modelSource: ModelSource;

    originalModel: SModelRootSchema;
    newModel: SModelRootSchema;

    constructor(@inject(TYPES.Action) action: CommitModelAction) {
        super();
    }

    execute(context: CommandExecutionContext): CommandResult {
        this.newModel = context.modelFactory.createSchema(context.root);
        return this.doCommit(this.newModel, context.root, true);
    }
github eclipsesource / graphical-lsp / client / packages / sprotty-client / src / features / tool-palette / tool-palette.ts View on Github external
header.ondblclick = (ev) => {
        const css = "collapsed";
        changeCSSClass(group, css);
        Array.from(group.children).forEach(item => changeCSSClass(item, css));
        window!.getSelection()!.removeAllRanges();
    };

    group.appendChild(header);
    return group;
}

function changeCSSClass(element: Element, css: string) {
    element.classList.contains(css) ? element.classList.remove(css) :
        element.classList.add(css);
}
@injectable()
export class ToolPaletteActionHandler implements IActionHandler {
    @inject(ToolPalette) protected readonly toolPalette: ToolPalette;

    handle(action: Action): ICommand | Action | void {
        if (isSetOperationsAction(action)) {
            this.toolPalette.setOperations(action.operations);
            return new SetUIExtensionVisibilityAction(ToolPalette.ID, true);
        } else if (action instanceof EnableDefaultToolsAction) {
            this.toolPalette.changeActiveButton();
        }
    }
}
github eclipse-theia / theia / packages / editor / src / browser / navigation / navigation-location-similarity.ts View on Github external
* This Source Code may also be made available under the following Secondary
 * Licenses when the conditions for such availability set forth in the Eclipse
 * Public License v. 2.0 are satisfied: GNU General Public License, version 2
 * with the GNU Classpath Exception which is available at
 * https://www.gnu.org/software/classpath/license.html.
 *
 * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
 ********************************************************************************/

import { injectable } from 'inversify';
import { NavigationLocation } from './navigation-location';

/**
 * Service for checking whether two navigation locations are similar or not.
 */
@injectable()
export class NavigationLocationSimilarity {

    /**
     * The number of lines to move in the editor to justify for new state.
     */
    private static EDITOR_SELECTION_THRESHOLD = 10;

    /**
     * `true` if the `left` and `right` locations are withing +- 10 lines in the same editor. Otherwise, `false`.
     */
    similar(left: NavigationLocation | undefined, right: NavigationLocation | undefined): boolean {
        if (left === undefined || right === undefined) {
            return left === right;
        }

        if (left.uri.toString() !== right.uri.toString()) {
github JohnSimerlink / branches_front_end_private / app / objects / stores / SubscribableStoreSource.ts View on Github external
updatesCallbacks,
			type
		});
	}
}

@injectable()
export class SubscribableTreeStoreSourceArgs {
	@inject(TYPES.Object) public hashmap;
	@inject(TYPES.Array) public updatesCalbacks: any[];
	@inject(TYPES.ObjectDataTypes)
	@tagged(TAGS.TREE_DATA, true)
	private type: CustomStoreDataTypes;
}

@injectable()
export class SubscribableTreeLocationStoreSourceArgs {
	@inject(TYPES.Object) public hashmap;
	@inject(TYPES.Array) public updatesCalbacks: any[];
	@inject(TYPES.ObjectDataTypes)
	@tagged(TAGS.TREE_LOCATIONS_DATA, true)
	private type: CustomStoreDataTypes;
}

@injectable()
export class SubscribableTreeUserStoreSourceArgs {
	@inject(TYPES.Object) public hashmap;
	@inject(TYPES.Array) public updatesCalbacks: any[];
	@inject(TYPES.ObjectDataTypes)
	@tagged(TAGS.TREE_USERS_DATA, true)
	private type: CustomStoreDataTypes;
}
github eclipsesource / graphical-lsp / client / packages / glsp-sprotty / src / features / tool-manager / tool-manager.ts View on Github external
}
    }

    configure(action: SetOperationsAction) {
        const configuredTools = action.operations.map(op => {
            const tool = this.toolFactory(op.operationKind)
            tool.elementTypeId = op.elementTypeId;
            return tool;
        }).filter(tool => tool.id !== UNDEFINED_TOOL_ID)

        this.registerTools(...configuredTools)

    }
}

@injectable()
export class ToolManagerActionHandlerInitializer implements IActionHandlerInitializer, IActionHandler {
    @inject(GLSP_TYPES.ToolManager)
    readonly toolManager: ToolManager;

    initialize(registry: ActionHandlerRegistry): void {
        registry.register(EnableStandardToolsAction.KIND, this);
        registry.register(EnableToolsAction.KIND, this);
        registry.register(SetOperationsAction.KIND, this);
    }

    handle(action: Action): void | ICommand | Action {
        if (action instanceof EnableStandardToolsAction) {
            this.toolManager.enableStandardTools();
        } else if (action instanceof EnableToolsAction) {
            this.toolManager.enable(action.toolIds);
        } else if (isSetOperationsAction(action)) {
github seagull-js / seagull / packages / services-http / src / mode / cloud.ts View on Github external
import { injectable } from 'inversify'
import fetch, { RequestInit, Response } from 'node-fetch'
import 'reflect-metadata'
import { HttpBase } from './base'

/**
 * Http (default) cloud mode implementation.
 */
@injectable()
export class Http extends HttpBase {
  /**
   * node-fetch
   * @see https://github.com/bitinn/node-fetch
   * @param url request url
   * @param init whatwg/fetch options
   */
  async fetch(url: string, init?: RequestInit): Promise {
    return await fetch(url, init)
  }
}
github dcos / dcos-ui / plugins / jobs / src / js / data / JobModel.ts View on Github external
const boundResolvers = resolvers({
  fetchJobs,
  fetchJobDetail,
  pollingInterval: Config.getRefreshRate(),
  runJob,
  createJob,
  updateJob,
  updateSchedule,
  deleteJob,
  stopJobRun
});

const JobType = Symbol("Job");

@injectable()
export class JobExtension implements DataLayerExtensionInterface {
  public id = JobType;

  public getResolvers() {
    return boundResolvers;
  }

  public getTypeDefinitions() {
    return typeDefs;
  }
}