How to use the @robotlegsjs/core.inject function in @robotlegsjs/core

To help you get started, we’ve selected a few @robotlegsjs/core 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 RobotlegsJS / RobotlegsJS-Pixi / test / robotlegs / bender / extensions / mediatorMap / support / HookWithMediatorAndViewInjectionReportFunction.ts View on Github external
//  NOTICE: You are permitted to use, modify, and distribute this file
//  in accordance with the terms of the license agreement accompanying it.
// ------------------------------------------------------------------------------

import { Sprite } from "pixi.js";

import { injectable, inject, named, IHook } from "@robotlegsjs/core";

import { RectangleMediator } from "./RectangleMediator";

@injectable()
export class HookWithMediatorAndViewInjectionReportFunction implements IHook {
    @inject(RectangleMediator)
    public mediator: RectangleMediator;

    @inject(Sprite)
    public view: Sprite;

    @inject("Function")
    @named("reportView")
    public reportView: Function;

    public hook(): void {
        this.reportView(this.view, this.mediator.width, this.mediator.height);
    }
}
github RobotlegsJS / RobotlegsJS-Pixi / test / robotlegs / bender / extensions / mediatorMap / support / ExampleMediator2.ts View on Github external
//  NOTICE: You are permitted to use, modify, and distribute this file
//  in accordance with the terms of the license agreement accompanying it.
// ------------------------------------------------------------------------------

import { injectable, inject } from "@robotlegsjs/core";

import { Sprite } from "pixi.js";

import { MediatorWatcher } from "./MediatorWatcher";

@injectable()
export class ExampleMediator2 {
    @inject(MediatorWatcher)
    public mediatorWatcher: MediatorWatcher;

    @inject(Sprite)
    public view: Sprite;

    public initialize(): void {
        this.mediatorWatcher.notify("ExampleMediator2");
    }

    public destroy(): void {
        this.mediatorWatcher.notify("ExampleMediator2 destroy");
    }
}
github RobotlegsJS / RobotlegsJS-Pixi / test / robotlegs / bender / extensions / mediatorMap / support / ExampleDisplayObjectMediator.ts View on Github external
// ------------------------------------------------------------------------------
//  Copyright (c) 2017-present, RobotlegsJS. All Rights Reserved.
//
//  NOTICE: You are permitted to use, modify, and distribute this file
//  in accordance with the terms of the license agreement accompanying it.
// ------------------------------------------------------------------------------

import { injectable, inject } from "@robotlegsjs/core";

import { DisplayObject } from "pixi.js";

import { MediatorWatcher } from "./MediatorWatcher";

@injectable()
export class ExampleDisplayObjectMediator {
    @inject(MediatorWatcher)
    public mediatorWatcher: MediatorWatcher;

    @inject(DisplayObject)
    public view: DisplayObject;

    public initialize(): void {
        this.mediatorWatcher.notify("ExampleDisplayObjectMediator");
    }
}
github RobotlegsJS / RobotlegsJS-Pixi / test / robotlegs / bender / extensions / mediatorMap / support / OnlyIfViewHasChildrenGuard.ts View on Github external
// ------------------------------------------------------------------------------
//  Copyright (c) 2017-present, RobotlegsJS. All Rights Reserved.
//
//  NOTICE: You are permitted to use, modify, and distribute this file
//  in accordance with the terms of the license agreement accompanying it.
// ------------------------------------------------------------------------------

import { Sprite } from "pixi.js";

import { injectable, inject, IGuard } from "@robotlegsjs/core";

@injectable()
export class OnlyIfViewHasChildrenGuard implements IGuard {
    @inject(Sprite)
    public view: Sprite;

    public approve(): boolean {
        return this.view.children.length > 0;
    }
}
github RobotlegsJS / RobotlegsJS-Pixi / test / robotlegs / bender / extensions / mediatorMap / support / LifecycleReportingMediator.ts View on Github external
@inject("Function")
    @named("preInitializeCallback")
    @optional()
    public preInitializeCallback: Function;

    @inject("Function")
    @named("initializeCallback")
    @optional()
    public initializeCallback: Function;

    @inject("Function")
    @named("postInitializeCallback")
    @optional()
    public postInitializeCallback: Function;

    @inject("Function")
    @named("preDestroyCallback")
    @optional()
    public preDestroyCallback: Function;

    @inject("Function")
    @named("destroyCallback")
    @optional()
    public destroyCallback: Function;

    @inject("Function")
    @named("postDestroyCallback")
    @optional()
    public postDestroyCallback: Function;

    public initialized: Boolean = false;
github RonaldoSetzer / GAME-Match3 / typescript-match3 / src / matchthree / game / commands / SwapPiecesCommand.ts View on Github external
import { ICommand, inject, injectable } from "@robotlegsjs/core";

import { GameEvent } from "./../../events/GameEvent";
import { GameManager } from "./../managers/GameManager";
import { SwapModel } from "./../models/SwapModel";
import { TouchPhase } from "./../models/TouchPhase";

@injectable()
export class SwapPiecesCommand implements ICommand {
    @inject(SwapModel) private swapModel: SwapModel;
    @inject(GameManager) private gameManager: GameManager;
    @inject(GameEvent) private gameEvent: GameEvent;

    public execute(): void {
        this.swapModel.status = SwapModel.WAIT;
        this.swapModel.setPosition(this.gameEvent.extra.phase, this.gameEvent.extra.col, this.gameEvent.extra.row);

        if (this.gameEvent.extra.phase === TouchPhase.ENDED) {
            this.swapModel.status = SwapModel.SWAP;
            this.gameManager.nextStep.bind(this)();
        }
    }
}
github RonaldoSetzer / GAME-Tetris / typescript-tetris / src / mediators / GameOverPopupMediator.ts View on Github external
import { inject, injectable } from "@robotlegsjs/core";
import { Mediator } from "@robotlegsjs/pixi";

import { FlowService } from "./../services/FlowService";
import { GameService } from "./../services/GameService";
import { GameOverPopup } from "./../views/GameOverPopup";

@injectable()
export class GameOverPopupMediator extends Mediator {
    @inject(FlowService) private flowService: FlowService;
    @inject(GameService) private gameService: GameService;

    public initialize(): void {
        this.eventMap.mapListener(this.view.homeButton, "click", this.homeButton_onClick, this);
        this.eventMap.mapListener(this.view.retryButton, "click", this.retryButton_onClick, this);
    }
    public destroy(): void {
        this.eventMap.unmapListeners();
    }
    private homeButton_onClick(e: any): void {
        this.flowService.setHomeView();
        this.flowService.closePopup();
    }
    private retryButton_onClick(e: any): void {
        this.flowService.closePopup();
        this.gameService.createLevel();
    }
github RonaldoSetzer / GAME-Match3 / typescript-match3 / src / matchthree / mediators / PausePopupMediator.ts View on Github external
import { inject, injectable } from "@robotlegsjs/core";
import { Mediator } from "@robotlegsjs/pixi";

import { FlowService } from "./../services/FlowService";
import { GameService } from "./../services/GameService";
import { PausePopup } from "./../views/PausePopup";

@injectable()
export class PausePopupMediator extends Mediator {
    @inject(FlowService) private flowService: FlowService;
    @inject(GameService) private gameService: GameService;

    public initialize(): void {
        this.eventMap.mapListener(this.view.levelSelectButton, "click", this.levelSelectButton_onClick, this);
        this.eventMap.mapListener(this.view.resumeButton, "click", this.resumeButton_onClick, this);
        this.eventMap.mapListener(this.view.retryButton, "click", this.retryButton_onClick, this);
    }
    public destroy(): void {
        this.eventMap.unmapListeners();
    }
    private levelSelectButton_onClick(e: any): void {
        this.flowService.setLevelSelectView();
        this.flowService.closePopup();
    }
    private resumeButton_onClick(e: any): void {
        this.flowService.closePopup();
        this.flowService.showStartingPopup();
github RonaldoSetzer / GAME-Tetris / typescript-tetris / src / commands / GameOverCommand.ts View on Github external
import { ICommand, inject, injectable } from "@robotlegsjs/core";

import { GameModel } from "./../models/GameModel";
import { GameStatus } from "./../models/GameStatus";
import { FlowService } from "./../services/FlowService";

@injectable()
export class GameOverCommand implements ICommand {
    @inject(GameModel) private model: GameModel;
    @inject(FlowService) private flowService: FlowService;

    public execute(): void {
        this.model.status = GameStatus.GAMEOVER;
        this.flowService.showGameOverPopup();
    }
}
github RonaldoSetzer / GAME-Match3 / typescript-match3 / src / matchthree / mediators / OptionsViewMediator.ts View on Github external
import { inject, injectable } from "@robotlegsjs/core";
import { Mediator } from "@robotlegsjs/pixi";

import { FlowService } from "./../services/FlowService";
import { OptionsView } from "./../views/OptionsView";

@injectable()
export class OptionsViewMediator extends Mediator {
    @inject(FlowService) private flowService: FlowService;

    public initialize(): void {
        this.eventMap.mapListener(this.view.backButton, "click", this.backButton_onClick, this);
        this.eventMap.mapListener(this.view.deleteButton, "click", this.deleteButton_onClick, this);
    }
    public destroy(): void {
        this.eventMap.unmapListeners();
    }
    private backButton_onClick(e: any, thisObject: any): void {
        this.flowService.setHomeView();
    }
    private deleteButton_onClick(e: any): void {
        this.flowService.showAlertPopup();
    }
}

@robotlegsjs/core

An architecture-based IoC framework for JavaScript/TypeScript

MIT
Latest version published 2 years ago

Package Health Score

49 / 100
Full package analysis