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

@ -5,14 +5,6 @@ declare module "data/virtual-array" {
import observable = require("data/observable");
import observableArray = require("data/observable-array");
/**
* Known event names.
*/
module knownEvents {
export var itemsLoading: string;
export var change: string;
}
/**
* Provides event args for "changed" event.
*/
@ -31,6 +23,16 @@ declare module "data/virtual-array" {
* Advanced array like class that helps loading items on demand.
*/
export class VirtualArray<T> extends observable.Observable {
/**
* String value used when hooking to change event.
*/
public static changeEvent: string;
/**
* String value used when hooking to itemsLoading event.
*/
public static itemsLoadingEvent: string;
constructor(arrayLength?: number);
/**
@ -58,17 +60,23 @@ declare module "data/virtual-array" {
*/
load(index: number, items: T[]): void;
on(event: string, callback: (data: observable.EventData) => void);
/**
* 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 still not loaded items are requested.
*/
on(event: "itemsLoading", callback: (args: ItemsLoading) => void);
on(event: "itemsLoading", callback: (args: ItemsLoading) => void, thisArg?: any);
/**
* Raised when a change occurs.
*/
on(event: "change", callback: (args: ChangedData<T>) => void);
on(event: "change", callback: (args: ChangedData<T>) => void, thisArg?: any);
}
/**

View File

@ -4,11 +4,6 @@ import virtualArrayDef = require("data/virtual-array");
var CHANGE = "change", UPDATE = "update", DELETE = "delete", ADD = "add";
export module knownEvents {
export var itemsLoading = "itemsLoading";
export var change = "change";
}
export class ChangeType implements virtualArrayDef.ChangeType {
static Add = "add";
static Delete = "delete";
@ -17,6 +12,9 @@ export class ChangeType implements virtualArrayDef.ChangeType {
}
export class VirtualArray<T> extends observable.Observable {
public static changeEvent = CHANGE;
public static itemsLoadingEvent = "itemsLoading";
private _requestedIndexes: Array<number>;
private _loadedIndexes: Array<number>;
private _length: number;
@ -139,7 +137,7 @@ export class VirtualArray<T> extends observable.Observable {
} else {
if (count > 0) {
this.notify({
eventName: knownEvents.itemsLoading, object: this,
eventName: VirtualArray.itemsLoadingEvent, object: this,
index: start,
count: count
});
@ -152,7 +150,7 @@ export class VirtualArray<T> extends observable.Observable {
if (start >= 0 && count > 0) {
this.notify({
eventName: knownEvents.itemsLoading, object: this,
eventName: VirtualArray.itemsLoadingEvent, object: this,
index: start,
count: count
});