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

update:EventSender -> THREE.EventDispatcher #732

Merged
Merged
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
3 changes: 0 additions & 3 deletions docs/html/shared/EventSender.html

This file was deleted.

120 changes: 0 additions & 120 deletions docs/html/shared/EventSender.js.html

This file was deleted.

23 changes: 9 additions & 14 deletions packages/browser/src/GUI/js/Window.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
import { dragElement } from './Draggable.js';
import { EventSender } from '@ud-viz/shared';
import { windowManager } from './WindowManager.js';
import { WindowExtension } from './WindowExtension.js';

import { EventDispatcher } from 'three';

import '../css/window.css';

// Documentation is on the Wiki
// URL : https://github.com/MEPP-team/UD-Viz/wiki/Window-Framework
// You can see an example in UD-Viz-Shared/examples/DemoWindow

export class Window extends EventSender {
export class Window extends EventDispatcher {
/**
* Creates a window.
*
Expand Down Expand Up @@ -66,12 +67,6 @@ export class Window extends EventSender {
*/
this.windowExtensions = [];

this.registerEvent(Window.EVENT_CREATED);
this.registerEvent(Window.EVENT_DESTROYED);
this.registerEvent(Window.EVENT_SHOWN);
this.registerEvent(Window.EVENT_HIDDEN);
this.registerEvent(Window.EVENT_REDUCED);

windowManager.registerWindow(this);
}

Expand Down Expand Up @@ -132,8 +127,8 @@ export class Window extends EventSender {
}

this.windowCreated();
this.sendEvent(Window.EVENT_CREATED);
this.sendEvent(Window.EVENT_SHOWN);
this.dispatchEvent({ type: Window.EVENT_CREATED });
this.dispatchEvent({ type: Window.EVENT_SHOWN });
}
}

Expand All @@ -146,7 +141,7 @@ export class Window extends EventSender {
this.parentElement.removeChild(this.window);

this.windowDestroyed();
this.sendEvent(Window.EVENT_DESTROYED);
this.dispatchEvent({ type: Window.EVENT_DESTROYED });
}
}

Expand All @@ -156,7 +151,7 @@ export class Window extends EventSender {
show() {
if (this.isCreated && !this.isVisible) {
this.window.style.setProperty('display', this.windowDisplayWhenVisible);
this.sendEvent(Window.EVENT_SHOWN);
this.dispatchEvent({ type: Window.EVENT_SHOWN });
}
}

Expand All @@ -166,7 +161,7 @@ export class Window extends EventSender {
hide() {
if (this.isVisible) {
this.window.style.setProperty('display', 'none');
this.sendEvent(Window.EVENT_HIDDEN);
this.dispatchEvent({ type: Window.EVENT_HIDDEN });
}
}

Expand All @@ -182,7 +177,7 @@ export class Window extends EventSender {
this.content.style.display = 'none';
this.window.style.height = getComputedStyle(this.header).height;
this.window.style.resize = 'none';
this.sendEvent(Window.EVENT_REDUCED);
this.dispatchEvent({ type: Window.EVENT_REDUCED });
}
}

Expand Down
11 changes: 5 additions & 6 deletions packages/browser/src/Widget/CameraPositioner/CameraPositioner.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import { MAIN_LOOP_EVENTS } from 'itowns';
import * as THREE from 'three';
import { findChildByID } from '../../HTMLUtil';
import { EventSender } from '@ud-viz/shared';

export class CameraPositioner extends EventSender {
export class CameraPositioner extends THREE.EventDispatcher {
/**
* Creates a CameraPositioner
*
Expand Down Expand Up @@ -32,9 +31,6 @@ export class CameraPositioner extends EventSender {
this.buttonValidateElement.onclick = () => {
this._validate();
};

// Event for position registering
this.registerEvent(CameraPositioner.EVENT_POSITION_SUBMITTED);
}

get innerContentHtml() {
Expand Down Expand Up @@ -136,7 +132,10 @@ export class CameraPositioner extends EventSender {
*/
_validate() {
const camera = this._getCameraPosition();
this.sendEvent(CameraPositioner.EVENT_POSITION_SUBMITTED, camera);
this.dispatchEvent({
type: CameraPositioner.EVENT_POSITION_SUBMITTED,
message: camera,
});
}

// ///////////
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,9 @@ export class DocumentCreationWindow {
this.positioner = new CameraPositioner(itownsView, cameraControls);
this.positioner.addEventListener(
CameraPositioner.EVENT_POSITION_SUBMITTED,
(data) => this._registerPositionAndQuaternion(data)
(data) => {
this._registerPositionAndQuaternion(data.message);
}
);

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ export class DocumentInspectorWindow {

this.provider.addEventListener(
DocumentProvider.EVENT_DISPLAYED_DOC_CHANGED,
(doc) => this.onDisplayedDocumentChange(doc)
(data) => this.onDisplayedDocumentChange(data.document)
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,11 +79,11 @@ export class DocumentNavigatorWindow {

this.provider.addEventListener(
DocumentProvider.EVENT_FILTERED_DOCS_UPDATED,
(documents) => this._onFilteredDocumentsUpdate(documents)
(data) => this._onFilteredDocumentsUpdate(data.documents)
);
this.provider.addEventListener(
DocumentProvider.EVENT_DISPLAYED_DOC_CHANGED,
(doc) => this._onDisplayedDocumentChange(doc)
(data) => this._onDisplayedDocumentChange(data.document)
);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { EventSender } from '@ud-viz/shared';
import { EventDispatcher } from 'three';
import { DocumentService } from '../Model/DocumentService';
import { Document } from '../Model/Document';
import { DocumentFilter } from './DocumentFilter';
Expand All @@ -10,7 +10,7 @@ import { DocumentFilter } from './DocumentFilter';
* events when the filtered documents, or the currently displayed document
* change.
*/
export class DocumentProvider extends EventSender {
export class DocumentProvider extends EventDispatcher {
/**
* Constructs a new documents provider.
*
Expand Down Expand Up @@ -53,9 +53,6 @@ export class DocumentProvider extends EventSender {
* @type {number}
*/
this.displayedDocumentIndex = undefined;

this.registerEvent(DocumentProvider.EVENT_FILTERED_DOCS_UPDATED);
this.registerEvent(DocumentProvider.EVENT_DISPLAYED_DOC_CHANGED);
}

/**
Expand Down Expand Up @@ -90,14 +87,14 @@ export class DocumentProvider extends EventSender {
} else {
this.displayedDocumentIndex = undefined;
}
this.sendEvent(
DocumentProvider.EVENT_FILTERED_DOCS_UPDATED,
this.getFilteredDocuments()
);
this.sendEvent(
DocumentProvider.EVENT_DISPLAYED_DOC_CHANGED,
this.getDisplayedDocument()
);
this.dispatchEvent({
type: DocumentProvider.EVENT_FILTERED_DOCS_UPDATED,
documents: this.getFilteredDocuments(),
});
this.dispatchEvent({
type: DocumentProvider.EVENT_DISPLAYED_DOC_CHANGED,
document: this.getDisplayedDocument(),
});
}

/**
Expand Down Expand Up @@ -148,10 +145,10 @@ export class DocumentProvider extends EventSender {
}

this.displayedDocumentIndex = index;
this.sendEvent(
DocumentProvider.EVENT_DISPLAYED_DOC_CHANGED,
this.getDisplayedDocument()
);
this.dispatchEvent({
type: DocumentProvider.EVENT_DISPLAYED_DOC_CHANGED,
document: this.getDisplayedDocument(),
});
}

/**
Expand All @@ -174,10 +171,10 @@ export class DocumentProvider extends EventSender {
(this.filteredDocuments.length + this.displayedDocumentIndex + offset) %
this.filteredDocuments.length;

this.sendEvent(
DocumentProvider.EVENT_DISPLAYED_DOC_CHANGED,
this.getDisplayedDocument()
);
this.dispatchEvent({
type: DocumentProvider.EVENT_DISPLAYED_DOC_CHANGED,
document: this.getDisplayedDocument(),
});
}

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { findChildByID } from '../../../../HTMLUtil';
import { EventSender } from '@ud-viz/shared';

import './GuidedTour.css';

Expand All @@ -14,10 +13,8 @@ import './GuidedTour.css';
*
//=============================================================================
*/
export class GuidedTour extends EventSender {
export class GuidedTour {
constructor(guidedTourController) {
super();

this.domElement = document.createElement('div');
this.domElement.innerHTML = this.innerContentHtml;

Expand Down
3 changes: 1 addition & 2 deletions packages/shared/Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
[@ud-viz/shared](https://npmjs.com/package/@ud-viz/shared) is a npm package based on [Three.js](https://threejs.org/) including data processing and model plus a game engine.

- [@ud-viz/shared](#ud-vizshared)
- [Directory Hierarchy](#directory-hierarchy)
- [Directory Hierarchy](#directory-hierarchy)
- [Getting started](#getting-started)
- [Developers](#developers)
- [Npm scripts](#npm-scripts)
Expand All @@ -25,7 +25,6 @@ UD-Viz/packages/shared
| | ├── Object3D.js # Game node of a 3D scene
| ├── Command.js # Basic object communication
| ├── Data.js # Module for data processing (split string, converts to uri...)
| ├── EventSender.js # Manage custom events
| ├── index.js # API description (webpack entry point)
| ├── ProcessInterval.js # Manage loop process requesters
| ├── Type.js # Check if a string is a valid number
Expand Down
117 changes: 0 additions & 117 deletions packages/shared/src/EventSender.js

This file was deleted.

2 changes: 0 additions & 2 deletions packages/shared/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@ module.exports = {
/** @type {import("./Type")} */
Type: require('./Type'),
ProcessInterval: require('./ProcessInterval'),
/** @type {import("./EventSender").EventSender} */
EventSender: require('./EventSender'),
Command: require('./Command'),
Game: {
Context: require('./Game/Context').Context,
Expand Down
Loading