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

remove events/EventEmitter && move Observer to ts #2097

Merged
merged 2 commits into from Feb 11, 2019
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/design.md
Expand Up @@ -5,7 +5,7 @@ design idea is pretty simple :
- main functionalities are split into several subsystems
- all subsystems are instantiated by the Hls instance.
- each subsystem heavily relies on events for internal/external communications.
- Events are handled using [EventEmitter](https://nodejs.org/api/events.html)
- Events are handled using [EventEmitter3](https://github.com/primus/eventemitter3)
- bundled for the browser by [webpack](https://webpack.js.org/)

## Code structure
Expand Down
2 changes: 1 addition & 1 deletion src/demux/demuxer-worker.js
Expand Up @@ -7,7 +7,7 @@ import DemuxerInline from '../demux/demuxer-inline';
import Event from '../events';
import { enableLogs } from '../utils/logger';

import { EventEmitter } from 'events';
import { EventEmitter } from 'eventemitter3';

let DemuxerWorker = function (self) {
// observer setup
Expand Down
2 changes: 1 addition & 1 deletion src/demux/demuxer.js
@@ -1,4 +1,4 @@
import { EventEmitter } from 'events';
import { EventEmitter } from 'eventemitter3';
import * as work from 'webworkify-webpack';

import Event from '../events';
Expand Down
22 changes: 0 additions & 22 deletions src/observer.js

This file was deleted.

15 changes: 15 additions & 0 deletions src/observer.ts
@@ -0,0 +1,15 @@
import { EventEmitter } from 'eventemitter3';

/**
* Simple adapter sub-class of Nodejs-like EventEmitter.
*/
export class Observer extends EventEmitter {
/**
* We simply want to pass along the event-name itself
* in every call to a handler, which is the purpose of our `trigger` method
* extending the standard API.
*/
trigger (event: string, ...data: Array<any>): void {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Something to consider for the future is if we made this generic so it took T as the data parameter so usage could look like:

trigger<T>(event: string, data: T): void { }

This could flow into emit, and then on the listen and the whole thing could have typed listeners.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM.

this.emit(event, event, ...data);
}
}
2 changes: 1 addition & 1 deletion tests/unit/controller/eme-controller.js
@@ -1,6 +1,6 @@
import EMEController from '../../../src/controller/eme-controller';
import HlsMock from '../../mocks/hls.mock';
import EventEmitter from 'events';
import { EventEmitter } from 'eventemitter3';
import { ErrorDetails } from '../../../src/errors';

const sinon = require('sinon');
Expand Down
8 changes: 8 additions & 0 deletions webpack.config.js
Expand Up @@ -33,6 +33,14 @@ const baseConfig = {
exclude: /node_modules/
}
]
},
node: {
global: false,
process: false,
__filename: false,
__dirname: false,
Buffer: false,
setImmediate: false
}
};

Expand Down