Skip to content

Commit

Permalink
fix(dist): update output files
Browse files Browse the repository at this point in the history
  • Loading branch information
ctoran committed Oct 17, 2015
1 parent e2c4352 commit dffe8a5
Show file tree
Hide file tree
Showing 15 changed files with 641 additions and 616 deletions.
3 changes: 3 additions & 0 deletions dist/amd/Interfaces.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
interface Constructor<T> {
new (...args: any[]): T;
}
31 changes: 14 additions & 17 deletions dist/amd/aurelia-event-aggregator.d.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,15 @@
declare module 'aurelia-event-aggregator' {
import * as LogManager from 'aurelia-logging';
export interface Subscription {
export interface Subscription {
dispose(): void;
}
class Handler {
constructor(messageType: any, callback: any);
handle(message: any): any;
}
export class EventAggregator {
constructor();
publish(event: string | any, data?: any): void;
subscribe(event: string | Function, callback: Function): Subscription;
subscribeOnce(event: string | Function, callback: Function): Subscription;
}
export function includeEventsIn(obj: Object): EventAggregator;
export function configure(config: Object): void;
}
}
export declare class EventAggregator {
private eventLookup;
private messageHandlers;
publish<T>(event: T): void;
publish(event: string, data?: any): void;
subscribe<T>(event: Constructor<T>, callback: (message: T) => void): Subscription;
subscribe(event: string, callback: (message: any, event?: string) => void): Subscription;
subscribeOnce<T>(event: Constructor<T>, callback: (message: T) => void): Subscription;
subscribeOnce(event: string, callback: (message: any, event?: string) => void): Subscription;
}
export declare function includeEventsIn(obj: any): EventAggregator;
export declare function configure(config: any): void;
220 changes: 105 additions & 115 deletions dist/amd/aurelia-event-aggregator.js

Large diffs are not rendered by default.

31 changes: 14 additions & 17 deletions dist/aurelia-event-aggregator.d.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,15 @@
declare module 'aurelia-event-aggregator' {
import * as LogManager from 'aurelia-logging';
export interface Subscription {
export interface Subscription {
dispose(): void;
}
class Handler {
constructor(messageType: any, callback: any);
handle(message: any): any;
}
export class EventAggregator {
constructor();
publish(event: string | any, data?: any): void;
subscribe(event: string | Function, callback: Function): Subscription;
subscribeOnce(event: string | Function, callback: Function): Subscription;
}
export function includeEventsIn(obj: Object): EventAggregator;
export function configure(config: Object): void;
}
}
export declare class EventAggregator {
private eventLookup;
private messageHandlers;
publish<T>(event: T): void;
publish(event: string, data?: any): void;
subscribe<T>(event: Constructor<T>, callback: (message: T) => void): Subscription;
subscribe(event: string, callback: (message: any, event?: string) => void): Subscription;
subscribeOnce<T>(event: Constructor<T>, callback: (message: T) => void): Subscription;
subscribeOnce(event: string, callback: (message: any, event?: string) => void): Subscription;
}
export declare function includeEventsIn(obj: any): EventAggregator;
export declare function configure(config: any): void;
178 changes: 77 additions & 101 deletions dist/aurelia-event-aggregator.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

106 changes: 106 additions & 0 deletions dist/aurelia-event-aggregator.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
import * as LogManager from 'aurelia-logging';

const logger = LogManager.getLogger('event-aggregator');

class Handler {
constructor(public messageType: any, public callback: (message: any) => void) {
}

handle(message: any) {
if (message instanceof this.messageType) {
this.callback.call(null, message);
}
}
}

export interface Subscription {
dispose(): void;
}

export class EventAggregator {
private eventLookup: any = {};
private messageHandlers: Handler[] = [];

publish<T>(event: T): void;
publish(event: string, data?: any): void;
publish(event: any, data?: any): void {
let subscribers: any[];
let i: number;

if (typeof event === 'string') {
subscribers = this.eventLookup[event];
if (subscribers) {
subscribers = subscribers.slice();
i = subscribers.length;

try {
while (i--) {
subscribers[i](data, event);
}
} catch (e) {
logger.error(e);
}
}
} else {
subscribers = this.messageHandlers.slice();
i = subscribers.length;

try {
while (i--) {
subscribers[i].handle(event);
}
} catch (e) {
logger.error(e);
}
}
}

subscribe<T>(event: Constructor<T>, callback: (message: T) => void): Subscription;
subscribe(event: string, callback: (message: any, event?: string) => void): Subscription;
subscribe(event: string|Constructor<any>, callback: (message: any, event?: string) => void): Subscription {
let handler: Function|Handler;
let subscribers: any[];

if (typeof event === 'string') {
handler = callback;
subscribers = this.eventLookup[event] || (this.eventLookup[event] = []);
} else {
handler = new Handler(event, callback);
subscribers = this.messageHandlers;
}

subscribers.push(handler);

return {
dispose() {
let idx = subscribers.indexOf(handler);
if (idx !== -1) {
subscribers.splice(idx, 1);
}
}
};
}

subscribeOnce<T>(event: Constructor<T>, callback: (message: T) => void): Subscription;
subscribeOnce(event: string, callback: (message: any, event?: string) => void): Subscription;
subscribeOnce(event: string|Constructor<any>, callback: (message: any, event?: string) => void): Subscription {
let sub = this.subscribe(<any>event, (a, b) => {
sub.dispose();
return callback(a, b);
});

return sub;
}
}

export function includeEventsIn(obj: any): EventAggregator {
let ea = new EventAggregator();
obj.subscribeOnce = (event: any, callback: any) => ea.subscribeOnce(event, callback);
obj.subscribe = (event: any, callback: any) => ea.subscribe(event, callback);
obj.publish = (event: any, data?: any) => ea.publish(event, data);
return ea;
}

export function configure(config: any): void {
config.instance(EventAggregator, includeEventsIn(config.aurelia));
}
3 changes: 3 additions & 0 deletions dist/commonjs/Interfaces.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
interface Constructor<T> {
new (...args: any[]): T;
}
Loading

0 comments on commit dffe8a5

Please sign in to comment.