Skip to content

Commit

Permalink
Move Podium to an export. Closes hapijs#74
Browse files Browse the repository at this point in the history
  • Loading branch information
kanongil committed Oct 16, 2021
1 parent bfb4b28 commit 95a2dc3
Show file tree
Hide file tree
Showing 5 changed files with 76 additions and 76 deletions.
12 changes: 6 additions & 6 deletions API.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ is largely insignificant as implementing these features will have similar cost o
```js
const Podium = require('@hapi/podium');

const emitter = new Podium()
const emitter = new Podium.Podium()

const context = { count: 0 }

Expand Down Expand Up @@ -86,7 +86,7 @@ Along with channels, podium allows you to specify other event parameters. Below

```js
const Podium = require('@hapi/podium');
const podiumObject = new Podium();
const podiumObject = new Podium.Podium();

podiumObject.registerEvent([
{
Expand Down Expand Up @@ -135,7 +135,7 @@ podiumObject.emit({

```js
const Podium = require('@hapi/podium');
const podiumObject = new Podium();
const podiumObject = new Podium.Podium();

podiumObject.registerEvent([
{
Expand Down Expand Up @@ -193,7 +193,7 @@ console.log('after event2, ch1: ', arr);

```js
const Podium = require('@hapi/podium');
const podiumObject = new Podium();
const podiumObject = new Podium.Podium();

podiumObject.registerEvent([
{
Expand Down Expand Up @@ -250,7 +250,7 @@ console.log('after event2, ch1: ', arr);

```js
const Podium = require('@hapi/podium');
const podiumObject = new Podium();
const podiumObject = new Podium.Podium();

podiumObject.registerEvent([
{
Expand Down Expand Up @@ -287,7 +287,7 @@ podiumObject.emit({

```js
const Podium = require('@hapi/podium');
const emitter = new Podium('test');
const emitter = new Podium.Podium('test');

const updates = [];
emitter.on('test', (data) => updates.push({ id: 1, data }));
Expand Down
4 changes: 1 addition & 3 deletions lib/index.d.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/**
* Node (semi) compatible event emitter with extra features.
*/
declare class Podium {
export class Podium {
/**
* Creates a new podium emitter.
*
Expand Down Expand Up @@ -260,5 +260,3 @@ declare namespace Podium {
readonly tags?: boolean;
}
}

export = Podium;
56 changes: 29 additions & 27 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,46 +34,48 @@ internals.schema.listener = internals.schema.event.keys({
});


exports = module.exports = internals.Podium = class {
exports.decorate = function (target, source) {

constructor(events, options) {
exports.Podium.constructor.call(target);

// Use descriptive names to avoid conflict when inherited
for (const name of source._eventListeners.keys()) {
target._eventListeners.set(name, {
handlers: null,
flags: source._eventListeners.get(name).flags
});
}
};

this._eventListeners = new Map();
this._notificationsQueue = [];
this._eventsProcessing = false;

if (events) {
this.registerEvent(events, options);
exports.validate = function (events) {

const normalized = [];
events = [].concat(events);
for (let event of events) {
if (typeof event === 'string') {
event = { name: event };
}

normalized.push(Validate.attempt(event, internals.schema.event, 'Invalid event options'));
}

static decorate(target, source) {
return normalized;
};

internals.Podium.constructor.call(target);

for (const name of source._eventListeners.keys()) {
target._eventListeners.set(name, {
handlers: null,
flags: source._eventListeners.get(name).flags
});
}
}
exports.Podium = class {

static validate(events) {
constructor(events, options) {

const normalized = [];
events = [].concat(events);
for (let event of events) {
if (typeof event === 'string') {
event = { name: event };
}
// Use descriptive names to avoid conflict when inherited

normalized.push(Validate.attempt(event, internals.schema.event, 'Invalid event options'));
}
this._eventListeners = new Map();
this._notificationsQueue = [];
this._eventsProcessing = false;

return normalized;
if (events) {
this.registerEvent(events, options);
}
}

registerEvent(events, options = {}) {
Expand Down
Loading

0 comments on commit 95a2dc3

Please sign in to comment.