@graspologic/common
Advanced tools
Comparing version 0.5.0-2 to 0.5.0-3
@@ -50,3 +50,3 @@ "use strict"; | ||
emit(name, ...args) { | ||
emit(name, payload) { | ||
var listeners = this.listeners[name]; | ||
@@ -56,3 +56,3 @@ | ||
listeners.forEach(l => { | ||
l.apply(this, args); | ||
l.call(this, payload); | ||
}); | ||
@@ -59,0 +59,0 @@ } |
@@ -41,3 +41,3 @@ /*! | ||
emit(name, ...args) { | ||
emit(name, payload) { | ||
var listeners = this.listeners[name]; | ||
@@ -47,3 +47,3 @@ | ||
listeners.forEach(l => { | ||
l.apply(this, args); | ||
l.call(this, payload); | ||
}); | ||
@@ -50,0 +50,0 @@ } |
@@ -5,3 +5,3 @@ /*! | ||
*/ | ||
import { ClassType, Arguments } from './mixin'; | ||
import { ClassType, SingleArgument } from './mixin'; | ||
export declare type Disconnect = () => void; | ||
@@ -20,3 +20,3 @@ export interface HasEvents<Events> { | ||
*/ | ||
emit<N extends keyof Events>(name: N, ...args: any[]): void; | ||
emit<N extends keyof Events>(name: N, payload?: SingleArgument<Events[N]>): void; | ||
/** | ||
@@ -41,3 +41,3 @@ * Returns true if there are any listeners for the given event | ||
*/ | ||
emit<N extends keyof Events>(name: N, ...args: Arguments<Events[N]>): void; | ||
emit<N extends keyof Events>(name: N, payload?: SingleArgument<Events[N]>): void; | ||
/** | ||
@@ -44,0 +44,0 @@ * Returns true if there are any listeners for the given event |
@@ -6,2 +6,3 @@ /*! | ||
export declare type Arguments<T> = [T] extends [(...args: infer U) => any] ? U : [T] extends [void] ? [] : [T]; | ||
export declare type SingleArgument<T> = [T] extends [(arg: infer U) => any] ? U : [T] extends [void] ? [] : [T]; | ||
export interface ClassType<T> { | ||
@@ -8,0 +9,0 @@ new (...args: any[]): T; |
@@ -502,3 +502,3 @@ // Generated by dts-bundle v0.7.3 | ||
declare module '@graspologic/common/utils/events' { | ||
import { ClassType, Arguments } from '@graspologic/common/utils/mixin'; | ||
import { ClassType, SingleArgument } from '@graspologic/common/utils/mixin'; | ||
export type Disconnect = () => void; | ||
@@ -517,3 +517,3 @@ export interface HasEvents<Events> { | ||
*/ | ||
emit<N extends keyof Events>(name: N, ...args: any[]): void; | ||
emit<N extends keyof Events>(name: N, payload?: SingleArgument<Events[N]>): void; | ||
/** | ||
@@ -537,3 +537,3 @@ * Returns true if there are any listeners for the given event | ||
*/ | ||
emit<N extends keyof Events>(name: N, ...args: Arguments<Events[N]>): void; | ||
emit<N extends keyof Events>(name: N, payload?: SingleArgument<Events[N]>): void; | ||
/** | ||
@@ -553,2 +553,3 @@ * Returns true if there are any listeners for the given event | ||
export type Arguments<T> = [T] extends [(...args: infer U) => any] ? U : [T] extends [void] ? [] : [T]; | ||
export type SingleArgument<T> = [T] extends [(arg: infer U) => any] ? U : [T] extends [void] ? [] : [T]; | ||
export interface ClassType<T> { | ||
@@ -555,0 +556,0 @@ new (...args: any[]): T; |
@@ -5,3 +5,3 @@ /*! | ||
*/ | ||
import { ClassType, Arguments } from './mixin'; | ||
import { ClassType, SingleArgument } from './mixin'; | ||
export declare type Disconnect = () => void; | ||
@@ -20,3 +20,3 @@ export interface HasEvents<Events> { | ||
*/ | ||
emit<N extends keyof Events>(name: N, ...args: any[]): void; | ||
emit<N extends keyof Events>(name: N, payload?: SingleArgument<Events[N]>): void; | ||
/** | ||
@@ -41,3 +41,3 @@ * Returns true if there are any listeners for the given event | ||
*/ | ||
emit<N extends keyof Events>(name: N, ...args: Arguments<Events[N]>): void; | ||
emit<N extends keyof Events>(name: N, payload?: SingleArgument<Events[N]>): void; | ||
/** | ||
@@ -44,0 +44,0 @@ * Returns true if there are any listeners for the given event |
@@ -33,7 +33,7 @@ /*! | ||
*/ | ||
emit(name, ...args) { | ||
emit(name, payload) { | ||
var listeners = this.listeners[name]; | ||
if (listeners) { | ||
listeners.forEach((l) => { | ||
l.apply(this, args); | ||
l.call(this, payload); | ||
}); | ||
@@ -40,0 +40,0 @@ } |
@@ -6,2 +6,3 @@ /*! | ||
export declare type Arguments<T> = [T] extends [(...args: infer U) => any] ? U : [T] extends [void] ? [] : [T]; | ||
export declare type SingleArgument<T> = [T] extends [(arg: infer U) => any] ? U : [T] extends [void] ? [] : [T]; | ||
export interface ClassType<T> { | ||
@@ -8,0 +9,0 @@ new (...args: any[]): T; |
{ | ||
"name": "@graspologic/common", | ||
"version": "0.5.0-2", | ||
"version": "0.5.0-3", | ||
"license": "MIT", | ||
@@ -5,0 +5,0 @@ "description": "A common set of types and utils used by graspologic", |
@@ -5,3 +5,3 @@ /*! | ||
*/ | ||
import { applyMixins, ClassType, Arguments } from './mixin' | ||
import { applyMixins, ClassType, SingleArgument } from './mixin' | ||
@@ -24,3 +24,3 @@ export type Disconnect = () => void | ||
*/ | ||
emit<N extends keyof Events>(name: N, ...args: any[]): void | ||
emit<N extends keyof Events>(name: N, payload?: SingleArgument<Events[N]>): void | ||
@@ -64,7 +64,7 @@ /** | ||
*/ | ||
public emit<N extends keyof Events>(name: N, ...args: Arguments<Events[N]>) { | ||
public emit<N extends keyof Events>(name: N, payload?: SingleArgument<Events[N]>) { | ||
var listeners = this.listeners[name]; | ||
if (listeners) { | ||
listeners.forEach((l) => { | ||
(l as any).apply(this, args); | ||
(l as any).call(this, payload); | ||
}); | ||
@@ -100,2 +100,2 @@ } | ||
return EventImpl as any as ClassType<TBase & EventEmitter<Events>> | ||
} | ||
} |
@@ -10,2 +10,6 @@ /*! | ||
export type SingleArgument<T> = [T] extends [(arg: infer U) => any] | ||
? U | ||
: [T] extends [void] ? [] : [T] | ||
export interface ClassType<T> { | ||
@@ -26,2 +30,2 @@ new (...args: any[]): T | ||
return derivedCtor | ||
} | ||
} |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
340932
5781