Replace knownEvents modules with static strings.

This commit is contained in:
Nedyalko Nikolov
2015-04-23 15:47:56 +03:00
parent 8023390692
commit 95ca8d9c8c
101 changed files with 520 additions and 471 deletions

View File

@@ -30,20 +30,14 @@ declare module "data/observable" {
value: any;
}
/**
* Known event names.
*/
module knownEvents {
/**
* The name of the property changed event.
*/
export var propertyChange: string;
}
/**
* Observable is used when you want to be notified when a change occurs. Use on/off methods to add/remove listener.
*/
class Observable {
/**
* String value used when hooking to propertyChange event.
*/
public static propertyChangeEvent: string;
/**
* Creates an Observable instance and sets its properties accroding to the supplied JSON object.
@@ -56,14 +50,22 @@ declare module "data/observable" {
typeName: string;
/**
* Shortcut alias to the addEventListener method.
* A basic method signature to hook an event listener (shortcut alias to the addEventListener method).
* @param eventNames - String corresponding to events (e.g. "propertyChange"). Optionally could be used more events separated by `,` (e.g. "propertyChange", "change").
* @param callback - Callback function which will be executed when event is raised.
* @param thisArg - An optional parameter which will be used as `this` context for callback execution.
*/
on(eventNames: string, callback: (data: EventData) => void, thisArg?: any);
/**
* Raised when a propertyChange occurs.
*/
on(event: "propertyChange", callback: (data: EventData) => void, thisArg?: any);
/**
* Shortcut alias to the removeEventListener method.
*/
off(eventNames: string, callback?: any);
off(eventNames: string, callback?: any, thisArg?: any);
/**
* Adds a listener for the specified event name.

View File

@@ -6,11 +6,9 @@ interface ListenerEntry {
thisArg: any;
}
export module knownEvents {
export var propertyChange = "propertyChange";
}
export class Observable implements definition.Observable {
public static propertyChangeEvent = "propertyChange";
private _observers = {};
constructor(json?: any) {
@@ -31,8 +29,8 @@ export class Observable implements definition.Observable {
this.addEventListener(eventNames, callback, thisArg);
}
public off(eventNames: string, callback?: any) {
this.removeEventListener(eventNames, callback);
public off(eventNames: string, callback?: any, thisArg?: any) {
this.removeEventListener(eventNames, callback, thisArg);
}
public addEventListener(eventNames: string, callback: (data: definition.EventData) => void, thisArg?: any) {
@@ -122,7 +120,7 @@ export class Observable implements definition.Observable {
public _createPropertyChangeData(name: string, value: any): definition.PropertyChangeData {
return {
eventName: knownEvents.propertyChange,
eventName: Observable.propertyChangeEvent,
propertyName: name,
object: this,
value: value