Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP: Prepare package for generic display list #9

Open
wants to merge 31 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
b51291b
add minimal interfaces to abstract an generic display list structure
tiagoschenkel Aug 23, 2018
69ac33f
use abstract display list interfaces to decouple extensions from open…
tiagoschenkel Aug 23, 2018
66b8ca8
use tsconfig.example.json to compile example project
tiagoschenkel Aug 23, 2018
5a31a4a
initialize display object observer factory
tiagoschenkel Aug 23, 2018
da1f7b7
initialize display object observer factory
tiagoschenkel Aug 23, 2018
d5a1050
activate MediatorMap unit tests
tiagoschenkel Aug 23, 2018
ac2010f
initialize display object observer factory
tiagoschenkel Aug 23, 2018
ecc5edf
validate event handlers before call them
tiagoschenkel Aug 23, 2018
02c7e42
creates only one observer per display object
tiagoschenkel Aug 23, 2018
8453d2e
initialize display object observer factory
tiagoschenkel Aug 23, 2018
85cd509
initialize display object observer factory
tiagoschenkel Aug 23, 2018
13c651a
fix compilation errors
tiagoschenkel Aug 23, 2018
cbaa84c
allows the creation of only one observer per container
tiagoschenkel Aug 23, 2018
2782b1d
initialize display object observer factory
tiagoschenkel Aug 23, 2018
074ebf0
initialize display object observer factory
tiagoschenkel Aug 23, 2018
d51e7c1
initialize display object observer factory
tiagoschenkel Aug 23, 2018
3e6152d
initialize display object observer factory
tiagoschenkel Aug 23, 2018
ca878a8
initialize display object observer factory
tiagoschenkel Aug 23, 2018
2840331
initialize display object observer factory
tiagoschenkel Aug 23, 2018
51b4e8e
move interface to display object package
tiagoschenkel Aug 30, 2018
c0a67a1
move interface to display object package
tiagoschenkel Aug 30, 2018
dc756b4
move interface to display object package
tiagoschenkel Aug 30, 2018
8e6b77b
move interface to display object package
tiagoschenkel Aug 30, 2018
50777e3
update import statements
tiagoschenkel Aug 30, 2018
95ca2ec
update import statements
tiagoschenkel Aug 30, 2018
8ce8ba3
use const instead of let on exported symbol
tiagoschenkel Aug 30, 2018
b7ecd30
use const instead of let on exported symbol
tiagoschenkel Aug 30, 2018
ed601ab
use const instead of let on exported symbol
tiagoschenkel Aug 30, 2018
6f35ef0
update validation of parent
tiagoschenkel Aug 30, 2018
ab0fdc6
create only one observer per container and clean-up observers on dest…
tiagoschenkel Aug 30, 2018
84dc8d7
destroy display object observers on destroy method
tiagoschenkel Aug 30, 2018
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
18 changes: 16 additions & 2 deletions src/robotlegs/bender/bundles/openfl/OpenFLBundle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,11 @@
// in accordance with the terms of the license agreement accompanying it.
// ------------------------------------------------------------------------------

import { IBundle, IContext, ILogger, instanceOfType } from "@robotlegsjs/core";
import { interfaces, IBundle, IContext, ILogger, instanceOfType } from "@robotlegsjs/core";

import { IDisplayObject } from "../../displayList/api/IDisplayObject";
import { IDisplayObjectObserver } from "../../displayList/api/IDisplayObjectObserver";
import { IDisplayObjectObserverFactory } from "../../displayList/api/IDisplayObjectObserverFactory";

import { IContextView } from "../../extensions/contextView/api/IContextView";
import { ContextView } from "../../extensions/contextView/impl/ContextView";
Expand All @@ -17,6 +21,8 @@ import { StageCrawlerExtension } from "../../extensions/viewManager/StageCrawler
import { StageObserverExtension } from "../../extensions/viewManager/StageObserverExtension";
import { ViewManagerExtension } from "../../extensions/viewManager/ViewManagerExtension";

import { DisplayObjectObserver } from "./observer/DisplayObjectObserver";

/**
* For that Classic Robotlegs flavour
*
Expand All @@ -42,6 +48,14 @@ export class OpenFLBundle implements IBundle {
this._context = context;
this._logger = context.getLogger(this);

this._context.injector
.bind<interfaces.Factory<IDisplayObjectObserver>>(IDisplayObjectObserverFactory)
.toFactory<IDisplayObjectObserver>(() => {
return (view: IDisplayObject, useCapture: boolean): IDisplayObjectObserver => {
return new DisplayObjectObserver(view, useCapture);
};
});

this._context.install(
ContextViewExtension,
ViewManagerExtension,
Expand All @@ -59,7 +73,7 @@ export class OpenFLBundle implements IBundle {
/* Private Functions */
/*============================================================================*/

private handleContextView(): void {
private handleContextView(contextView: ContextView): void {
this._context.configure(ContextViewListenerConfig);
}

Expand Down
129 changes: 129 additions & 0 deletions src/robotlegs/bender/bundles/openfl/observer/DisplayObjectObserver.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
// ------------------------------------------------------------------------------
// 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 { IDisplayObject } from "../../../displayList/api/IDisplayObject";
import { IDisplayObjectObserver } from "../../../displayList/api/IDisplayObjectObserver";

import { ConfigureViewEvent } from "../../../extensions/viewManager/impl/ConfigureViewEvent";

import DisplayObject from "openfl/display/DisplayObject";

import Event from "openfl/events/Event";

/**
*
*/
export class DisplayObjectObserver implements IDisplayObjectObserver {
private _displayObject: DisplayObject;
private _useCapture: boolean;

private _addedToStageHandler: Function;
private _removedFromStageHandler: Function;
private _configureViewHandler: Function;

/*============================================================================*/
/* Constructor */
/*============================================================================*/

/**
*
* @param displayObject
* @param useCapture
*/
constructor(displayObject: IDisplayObject, useCapture: boolean) {
if (displayObject !== null && displayObject !== undefined) {
this._displayObject = <DisplayObject>displayObject;
this._useCapture = useCapture;
} else {
throw new Error("DisplayObject can't be null or undefined");
}
}

/*============================================================================*/
/* Public Functions */
/*============================================================================*/

/**
*
* @param handler
*/
public addAddedToStageHandler(handler: Function): void {
if (handler !== null && handler !== undefined && this._displayObject.addEventListener !== undefined) {
this._addedToStageHandler = handler;
this._displayObject.addEventListener("addedToStage", this.onAddedToStage, this._useCapture);
}
}

/**
*
* @param handler
*/
public addRemovedFromStageHandler(handler: Function): void {
if (handler !== null && handler !== undefined && this._displayObject.addEventListener !== undefined) {
this._removedFromStageHandler = handler;
this._displayObject.addEventListener("removedFromStage", this.onRemovedFromStage, this._useCapture);
}
}

/**
*
* @param handler
*/
public addConfigureViewHandler(handler: Function): void {
if (handler !== null && handler !== undefined && this._displayObject.addEventListener !== undefined) {
this._configureViewHandler = handler;
this._displayObject.addEventListener(ConfigureViewEvent.CONFIGURE_VIEW, this.onConfigureView, this._useCapture);
}
}

/**
*
*/
public destroy(): void {
if (this._displayObject.removeEventListener !== undefined) {
this._displayObject.removeEventListener("addedToStage", this.onAddedToStage, this._useCapture);
this._displayObject.removeEventListener("removedFromStage", this.onRemovedFromStage, this._useCapture);
this._displayObject.removeEventListener(ConfigureViewEvent.CONFIGURE_VIEW, this.onConfigureView, this._useCapture);
}

this._displayObject = null;

this._addedToStageHandler = null;
this._removedFromStageHandler = null;
this._configureViewHandler = null;
}

/*============================================================================*/
/* Private Functions */
/*============================================================================*/

private onAddedToStage = (event: Event): void => {
this._addedToStageHandler(event.target);
};

private onRemovedFromStage = (event: Event): void => {
this._removedFromStageHandler(event.target);
};

private onConfigureView = (event: ConfigureViewEvent): void => {
// Stop that event!
event.stopPropagation();

this._configureViewHandler(event.currentTarget, event.target);
};

/*============================================================================*/
/* Public Properties */
/*============================================================================*/

/**
* The display object
*/
public get displayObject(): IDisplayObject {
return <IDisplayObject>this._displayObject;
}
}
13 changes: 13 additions & 0 deletions src/robotlegs/bender/displayList/api/IDisplayObject.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// ------------------------------------------------------------------------------
// 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 { IDisplayObjectContainer } from "./IDisplayObjectContainer";

export let IDisplayObject = Symbol("IDisplayObject");
export interface IDisplayObject {
parent: IDisplayObjectContainer;
}
18 changes: 18 additions & 0 deletions src/robotlegs/bender/displayList/api/IDisplayObjectContainer.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// ------------------------------------------------------------------------------
// 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 { IDisplayObject } from "./IDisplayObject";

export let IDisplayObjectContainer = Symbol("IDisplayObjectContainer");
export interface IDisplayObjectContainer extends IDisplayObject {
children?: IDisplayObject[];

numChildren?: number;
getChildAt?(index: number): IDisplayObject;

contains(child: IDisplayObject): boolean;
}
23 changes: 23 additions & 0 deletions src/robotlegs/bender/displayList/api/IDisplayObjectObserver.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
// ------------------------------------------------------------------------------
// 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 { IDisplayObject } from "./IDisplayObject";

/**
*
*/
export interface IDisplayObjectObserver {
displayObject: IDisplayObject;

addAddedToStageHandler(handler: Function): void;

addRemovedFromStageHandler(handler: Function): void;

addConfigureViewHandler(handler: Function): void;

destroy(): void;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// ------------------------------------------------------------------------------
// 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 { IDisplayObject } from "./IDisplayObject";
import { IDisplayObjectObserver } from "./IDisplayObjectObserver";

/**
*
*/
export let IDisplayObjectObserverFactory = Symbol("IDisplayObjectObserverFactory");
export type IDisplayObjectObserverFactory = (view: IDisplayObject, useCapture: boolean) => IDisplayObjectObserver;
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
// in accordance with the terms of the license agreement accompanying it.
// ------------------------------------------------------------------------------

import Stage from "openfl/display/Stage";
import { IDisplayObjectContainer } from "../../../displayList/api/IDisplayObjectContainer";

export let IContextView = Symbol("IContextView");
export const IContextView = Symbol("IContextView");
export interface IContextView {
view: Stage;
view: IDisplayObjectContainer;
}
10 changes: 5 additions & 5 deletions src/robotlegs/bender/extensions/contextView/impl/ContextView.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,15 @@

import { IConfig } from "@robotlegsjs/core";

import { IContextView } from "../api/IContextView";
import { IDisplayObjectContainer } from "../../../displayList/api/IDisplayObjectContainer";

import Stage from "openfl/display/Stage";
import { IContextView } from "../api/IContextView";

/**
* The Context View represents the root Container for a Context
*/
export class ContextView implements IContextView, IConfig {
private _view: Stage;
private _view: IDisplayObjectContainer;

/*============================================================================*/
/* Constructor */
Expand All @@ -25,7 +25,7 @@ export class ContextView implements IContextView, IConfig {
* The Context View represents the root Container for a Context
* @param view The root Container for this Context
*/
constructor(view: Stage) {
constructor(view: IDisplayObjectContainer) {
if (view !== null && view !== undefined) {
this._view = view;
} else {
Expand All @@ -45,7 +45,7 @@ export class ContextView implements IContextView, IConfig {
/**
* The root Container for this Context
*/
public get view(): Stage {
public get view(): IDisplayObjectContainer {
return this._view;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import { IMediatorUnmapper } from "../dsl/IMediatorUnmapper";
/**
* The Mediator Map allows you to bind Mediators to objects
*/
export let IMediatorMap = Symbol("IMediatorMap");
export const IMediatorMap = Symbol("IMediatorMap");
export interface IMediatorMap {
/**
* Maps a matcher that will be tested against incoming items to be handled.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@

import { IClass, IType, IInjector, applyHooks, guardsApprove, instantiateUnmapped, ITypeFilter } from "@robotlegsjs/core";

import { IDisplayObjectObserverFactory } from "../../../displayList/api/IDisplayObjectObserverFactory";

import { IMediatorMapping } from "../api/IMediatorMapping";

import { MediatorManager } from "./MediatorManager";
Expand Down Expand Up @@ -34,7 +36,7 @@ export class MediatorFactory {
*/
constructor(injector: IInjector, manager?: MediatorManager) {
this._injector = injector;
this._manager = manager || new MediatorManager(this);
this._manager = manager || new MediatorManager(this, this._injector.get(IDisplayObjectObserverFactory));
}

/*============================================================================*/
Expand Down
Loading