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

@@ -164,7 +164,7 @@ export class Binding {
this.weakEventListenerOptions = {
targetWeakRef: this.target,
sourceWeakRef: this.sourceOptions.instance,
eventName: observable.knownEvents.propertyChange,
eventName: observable.Observable.propertyChangeEvent,
handler: this.onSourcePropertyChanged,
handlerContext: this,
key: this.options.targetProperty

View File

@@ -332,13 +332,13 @@ export class DependencyObservable extends observable.Observable {
property.metadata.onValueChanged({
object: this,
property: property,
eventName: observable.knownEvents.propertyChange,
eventName: observable.Observable.propertyChangeEvent,
newValue: newValue,
oldValue: oldValue
});
}
if (this.hasListeners(observable.knownEvents.propertyChange)) {
if (this.hasListeners(observable.Observable.propertyChangeEvent)) {
var changeData = super._createPropertyChangeData(property.name, newValue);
this.notify(changeData);
}

View File

@@ -95,7 +95,7 @@ export class ProxyObject extends bindable.Bindable implements definition.ProxyOb
proxyMetadata.onSetNativeValue({
object: this,
property: property,
eventName: observable.knownEvents.propertyChange,
eventName: observable.Observable.propertyChangeEvent,
newValue: newValue,
oldValue: oldValue
});

View File

@@ -64,11 +64,6 @@ export function getAncestor(view: View, typeName: string): definition.View {
return parent;
}
export module knownEvents {
export var loaded = "loaded";
export var unloaded = "unloaded";
}
var viewIdCounter = 0;
function onCssClassPropertyChanged(data: dependencyObservable.PropertyChangeData) {
@@ -107,6 +102,8 @@ function onCssClassPropertyChanged(data: dependencyObservable.PropertyChangeData
);
export class View extends proxy.ProxyObject implements definition.View {
public static loadedEvent = "loaded";
public static unloadedEvent = "unloaded";
public static idProperty = idProperty;
public static cssClassProperty = cssClassProperty;

52
ui/core/view.d.ts vendored
View File

@@ -4,6 +4,7 @@ declare module "ui/core/view" {
import proxy = require("ui/core/proxy");
import gestures = require("ui/gestures");
import color = require("color");
import observable = require("data/observable");
/**
* Gets a child view by id.
@@ -28,21 +29,6 @@ declare module "ui/core/view" {
*/
export function getAncestor(view: View, typeName: string): View;
/**
* Defines an enum with events for view class.
*/
module knownEvents {
/**
* Raised when the view is added to visual tree and loaded (shown).
*/
export var loaded: string;
/**
* Raised when the view is unloaded.
*/
export var unloaded: string;
}
/**
* Defines interface for an optional parameter used to create a view.
*/
@@ -109,6 +95,16 @@ declare module "ui/core/view" {
* A View occupies a rectangular area on the screen and is responsible for drawing and layouting of all UI components within.
*/
export class View extends proxy.ProxyObject {
/**
* String value used when hooking to loaded event.
*/
public static loadedEvent: string;
/**
* String value used when hooking to unloaded event.
*/
public static unloadedEvent: string;
/**
* Represents the observable property backing the id property of each View.
*/
@@ -118,7 +114,15 @@ declare module "ui/core/view" {
* Represents the observable property backing the cssClass property of each View.
*/
public static cssClassProperty: dependencyObservable.Property;
/**
* Represents the observable property backing the isEnabled property of each View.
*/
public static isEnabledProperty: dependencyObservable.Property;
/**
* Represents the observable property backing the isUserInteractionEnabled property of each View.
*/
public static isUserInteractionEnabledProperty: dependencyObservable.Property;
constructor(options?: Options);
@@ -353,6 +357,24 @@ declare module "ui/core/view" {
observe(type: number, callback: (args: gestures.GestureEventData) => void): gestures.GesturesObserver;
/**
* 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: observable.EventData) => void, thisArg?: any);
/**
* Raised when a loaded event occurs.
*/
on(event: "loaded", callback: (args: observable.EventData) => void, thisArg?: any);
/**
* Raised when an unloaded event occurs.
*/
on(event: "unloaded", callback: (args: observable.EventData) => void, thisArg?: any);
// Lifecycle events
onLoaded(): void;
onUnloaded(): void;