Skip to content

Commit

Permalink
#3: Implement Neutralino.events namespace
Browse files Browse the repository at this point in the history
  • Loading branch information
shalithasuranga committed Jul 31, 2021
1 parent 3b3c192 commit e6a7641
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
23 changes: 23 additions & 0 deletions src/api/events.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { request, RequestType } from '../http/request';

export function on(event: string, handler: any): Promise<any> {
return new Promise((resolve: any, reject: any) => {
window.addEventListener(event, handler);
resolve();
});
};

export function off(event: string, handler: any): Promise<any> {
return new Promise((resolve: any, reject: any) => {
window.removeEventListener(event, handler);
resolve();
});
};

export function dispatch(event: string, data: any): Promise<any> {
return new Promise((resolve: any, reject: any) => {
let customEvent = new CustomEvent(event, {detail: data});
window.dispatchEvent(customEvent);
resolve();
});
};
1 change: 1 addition & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ export * as storage from './api/storage';
export * as debug from './api/debug';
export * as app from './api/app';
export * as window from './api/window';
export * as events from './api/events';

export { init } from './api/init';

Expand Down

0 comments on commit e6a7641

Please sign in to comment.