Skip to content
This repository has been archived by the owner on Jun 12, 2024. It is now read-only.

Commit

Permalink
fix(interfaces.ts): Interfaces were not correctly exported, fixed now.
Browse files Browse the repository at this point in the history
  • Loading branch information
Gerkin committed Feb 22, 2018
1 parent f60e8d2 commit ce8a0ea
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 27 deletions.
12 changes: 12 additions & 0 deletions src/interfaces.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
export interface IEventHandler {
(...args: any[]): Promise<any> | any;
}
export interface IEventsHash {
[key: string]: IEventHandler[];
}
export interface IEventHash {
[key: string]: IEventHandler | IEventHandler[];
}
export interface IOnceHandler extends IEventHandler {
origFn: IEventHandler;
}
14 changes: 0 additions & 14 deletions src/sequential-event.d.ts

This file was deleted.

11 changes: 7 additions & 4 deletions src/sequential-event.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import IEventHandler = SequentialEvent.IEventHandler;
import IEventsHash = SequentialEvent.IEventsHash;
import IEventHash = SequentialEvent.IEventHash;

import {
IEventHandler,
IEventHash,
IEventsHash,
IOnceHandler,
} from './interfaces';
import {
getNextPromise,
addEventListener,
Expand Down Expand Up @@ -185,3 +187,4 @@ export class SequentialEvent {
return this.__events.hasOwnProperty(event) && this.__events[event].length > 0;
}
}
export * from './interfaces';
19 changes: 10 additions & 9 deletions src/utils.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
/// <reference path="./sequential-event.d.ts"/>
import {
SequentialEvent,
IEventHandler,
IEventHash,
IEventsHash,
IOnceHandler,
} from './sequential-event';

import { SequentialEvent } from './sequential-event';

import IEventHandler = SequentialEvent.IEventHandler;
import IEventsHash = SequentialEvent.IEventsHash;
import IEventHash = SequentialEvent.IEventHash;
/**
* Handle execution of a single handler.
*
Expand Down Expand Up @@ -99,15 +100,15 @@ export const onceify = (
target: SequentialEvent,
eventName: string,
eventFn: IEventHandler
): SequentialEvent.IOnceHandler => {
): IOnceHandler => {
let called = false;
const once = function(...args: any[]) {
if (!called) {
target.off(eventName, once);
called = true;
return eventFn(...args);
}
} as SequentialEvent.IOnceHandler;
} as IOnceHandler;
once.origFn = eventFn;
return once;
};
Expand All @@ -123,7 +124,7 @@ const removeSingleListener = (
(() => {
const I = eventCat.length;
for (let i = 0; i < I; i++) {
if ((eventCat[i] as SequentialEvent.IOnceHandler).origFn === callback) {
if ((eventCat[i] as IOnceHandler).origFn === callback) {
return i;
}
}
Expand Down

0 comments on commit ce8a0ea

Please sign in to comment.