From 95ca8d9c8cf463e6d7dc8a255a6b01de5a5f90a4 Mon Sep 17 00:00:00 2001 From: Nedyalko Nikolov Date: Thu, 23 Apr 2015 15:47:56 +0300 Subject: [PATCH] Replace knownEvents modules with static strings. --- apps/TelerikNEXT/app-view-model.ts | 10 ++-- apps/cuteness.io/reddit-app-view-model.ts | 4 +- apps/cuteness.io/reddit-item-view-model.ts | 6 +-- apps/editable-text-demo/model.ts | 2 +- .../ApplicationLoadTimeAndFPS/mainPage.ts | 2 +- .../ComplexObjectGraphMemoryTest/mainPage.ts | 2 +- .../ControlCreationSpeedTest/mainPage.ts | 4 +- .../mainPage.ts | 4 +- .../NavigationMemoryLeakTest/mainPage.ts | 2 +- .../perf-tests/NavigationTest/details-page.ts | 6 +-- apps/perf-tests/NavigationTest/master-page.ts | 6 +-- apps/perf-tests/NavigationTest/page1.ts | 4 +- apps/perf-tests/NavigationTest/page2.ts | 2 +- .../SingleUIObjectMemoryLeakTest/mainPage.ts | 4 +- apps/perf-tests/SpeedTests/mainPage.ts | 6 +-- apps/perf-tests/controls-page.ts | 2 +- apps/perf-tests/nav-page.ts | 6 +-- apps/pickers-demo/model.ts | 14 ++--- apps/tab-view-demo/mainPage.ts | 4 +- apps/tests/app/mainPage.ts | 2 +- apps/tests/app/pageNavigation.ts | 2 +- apps/tests/app/testRunnerPage.ts | 8 +-- apps/tests/observable-array-tests.ts | 32 +++++------ .../pages/navigation/pageA-new-activity.ts | 2 +- apps/tests/pages/navigation/pageA.ts | 6 +-- .../pages/navigation/pageB-new-activity.ts | 4 +- apps/tests/pages/navigation/pageB.ts | 6 +-- .../pages/navigation/pageC-new-activity.ts | 4 +- apps/tests/pages/navigation/pageC.ts | 6 +-- apps/tests/pages/page11.ts | 2 +- apps/tests/pages/page7.ts | 2 +- apps/tests/pages/page8.ts | 4 +- apps/tests/pages/property-bindings.ts | 2 +- apps/tests/text/formatted-string-tests.ts | 8 +-- apps/tests/ui/bindable-tests.ts | 2 +- apps/tests/ui/button/button-tests.ts | 2 +- apps/tests/ui/dependency-observable-tests.ts | 6 +-- apps/tests/ui/list-view/list-view-tests.ts | 34 ++++++------ apps/tests/ui/observable-tests.ts | 54 +++++++++---------- apps/tests/ui/page/page-tests-common.ts | 8 +-- apps/tests/ui/page/page-tests.ios.ts | 6 +-- apps/tests/ui/progress/progress-tests.ts | 4 +- apps/tests/ui/search-bar/search-bar-tests.ts | 4 +- apps/tests/ui/slider/slider-tests.ts | 20 +++---- apps/tests/ui/style/style-properties-tests.ts | 8 +-- apps/tests/ui/switch/switch-tests.ts | 4 +- apps/tests/ui/tab-view/tab-view-tests.ts | 4 +- apps/tests/ui/view/view-tests-common.ts | 6 +-- apps/tests/ui/web-view/web-view-tests.ts | 4 +- apps/tests/virtual-array-tests.ts | 22 ++++---- .../xml-declaration/mymodule/MyControl.ts | 2 +- apps/ui-tests-app/mainPage.ts | 2 +- apps/ui-tests-app/pages/gestures.ts | 2 +- apps/ui-tests-app/pages/i73.ts | 2 +- apps/web-view-demo/model.ts | 4 +- apps/xml-demo/mainPage.ts | 2 +- data/observable-array/observable-array.d.ts | 22 ++++---- data/observable-array/observable-array.ts | 6 +-- data/observable/observable.d.ts | 26 ++++----- data/observable/observable.ts | 12 ++--- data/virtual-array/virtual-array.d.ts | 30 +++++++---- data/virtual-array/virtual-array.ts | 12 ++--- text/formatted-string-common.ts | 6 +-- ui/builder/component-builder.ts | 15 +++--- ui/button/button-common.ts | 7 ++- ui/button/button.android.ts | 2 +- ui/button/button.d.ts | 26 +++++---- ui/button/button.ios.ts | 2 +- ui/core/bindable.ts | 2 +- ui/core/dependency-observable.ts | 4 +- ui/core/proxy.ts | 2 +- ui/core/view-common.ts | 7 +-- ui/core/view.d.ts | 52 ++++++++++++------ ui/frame/frame-common.ts | 8 +-- ui/frame/frame.android.ts | 4 +- ui/frame/frame.d.ts | 33 ++++++------ ui/gestures/gestures.android.ts | 8 +-- ui/gestures/gestures.ios.ts | 8 +-- ui/image-cache/image-cache-common.ts | 10 ++-- ui/image-cache/image-cache.android.ts | 2 - ui/image-cache/image-cache.d.ts | 27 ++++++---- ui/image-cache/image-cache.ios.ts | 2 - ui/list-view/Readme.md | 2 +- ui/list-view/list-view-common.ts | 9 ++-- ui/list-view/list-view.android.ts | 6 +-- ui/list-view/list-view.d.ts | 47 ++++++++-------- ui/list-view/list-view.ios.ts | 6 +-- ui/page/page-common.ts | 12 ++--- ui/page/page.d.ts | 40 +++++++++----- ui/placeholder/placeholder-common.ts | 5 +- ui/placeholder/placeholder.android.ts | 2 +- ui/placeholder/placeholder.d.ts | 24 ++++++--- ui/placeholder/placeholder.ios.ts | 2 +- ui/search-bar/search-bar-common.ts | 8 ++- ui/search-bar/search-bar.android.ts | 6 +-- ui/search-bar/search-bar.d.ts | 37 ++++++------- ui/search-bar/search-bar.ios.ts | 6 +-- ui/slide-out/slide-out.android.ts | 4 +- ui/text-base/text-base.ts | 2 +- ui/web-view/web-view-common.ts | 10 ++-- ui/web-view/web-view.d.ts | 46 +++++++++------- 101 files changed, 520 insertions(+), 471 deletions(-) diff --git a/apps/TelerikNEXT/app-view-model.ts b/apps/TelerikNEXT/app-view-model.ts index da34fd8c5..12f4b0d2f 100644 --- a/apps/TelerikNEXT/app-view-model.ts +++ b/apps/TelerikNEXT/app-view-model.ts @@ -116,7 +116,7 @@ export class AppViewModel extends observable.Observable { set search(value: string) { if (this._search !== value) { this._search = value; - this.notify({ object: this, eventName: observable.knownEvents.propertyChange, propertyName: "search", value: value }); + this.notify({ object: this, eventName: observable.Observable.propertyChangeEvent, propertyName: "search", value: value }); this.filter(); } @@ -128,7 +128,7 @@ export class AppViewModel extends observable.Observable { set selectedIndex(value: number) { if (this._selectedIndex !== value) { this._selectedIndex = value; - this.notify({ object: this, eventName: observable.knownEvents.propertyChange, propertyName: "selectedIndex", value: value }); + this.notify({ object: this, eventName: observable.Observable.propertyChangeEvent, propertyName: "selectedIndex", value: value }); this.set("dayHeader", conferenceDays[value].title); @@ -150,7 +150,7 @@ export class AppViewModel extends observable.Observable { this._sessions = this._sessions.filter(i=> { return i.favorite }); } - this.notify({ object: this, eventName: observable.knownEvents.propertyChange, propertyName: "sessions", value: this._sessions }); + this.notify({ object: this, eventName: observable.Observable.propertyChangeEvent, propertyName: "sessions", value: this._sessions }); } public onDataLoaded() { @@ -171,7 +171,7 @@ export class AppViewModel extends observable.Observable { this.selectedViewIndex = 2; } - this.notify({ object: this, eventName: observable.knownEvents.propertyChange, propertyName: "selectedViewIndex", value: this.selectedViewIndex }); + this.notify({ object: this, eventName: observable.Observable.propertyChangeEvent, propertyName: "selectedViewIndex", value: this.selectedViewIndex }); } } @@ -242,7 +242,7 @@ export class SessionModel extends observable.Observable implements Session { set favorite(value: boolean) { if (this._favorite !== value) { this._favorite = value; - this.notify({ object: this, eventName: observable.knownEvents.propertyChange, propertyName: "favorite", value: this._favorite }); + this.notify({ object: this, eventName: observable.Observable.propertyChangeEvent, propertyName: "favorite", value: this._favorite }); } } diff --git a/apps/cuteness.io/reddit-app-view-model.ts b/apps/cuteness.io/reddit-app-view-model.ts index 54e8edf61..0d9db30b8 100644 --- a/apps/cuteness.io/reddit-app-view-model.ts +++ b/apps/cuteness.io/reddit-app-view-model.ts @@ -27,7 +27,7 @@ export class AppViewModel extends observable.Observable { if (!this._redditItems) { this._redditItems = new virtualArray.VirtualArray(1000); this._redditItems.loadSize = 50; - this._redditItems.on(virtualArray.knownEvents.itemsLoading, (args: virtualArray.ItemsLoading) => { + this._redditItems.on(virtualArray.VirtualArray.itemsLoadingEvent, (args: virtualArray.ItemsLoading) => { http.getJSON(redditUrl + args.count + (after ? "&after=" + after : "")).then(result => { @@ -69,7 +69,7 @@ export class AppViewModel extends observable.Observable { cache.enableDownload(); } - this.notify({ object: this, eventName: observable.knownEvents.propertyChange, propertyName: ISSCROLLING, value: value }); + this.notify({ object: this, eventName: observable.Observable.propertyChangeEvent, propertyName: ISSCROLLING, value: value }); } } diff --git a/apps/cuteness.io/reddit-item-view-model.ts b/apps/cuteness.io/reddit-item-view-model.ts index a4b5af2c4..8ea1dadae 100644 --- a/apps/cuteness.io/reddit-item-view-model.ts +++ b/apps/cuteness.io/reddit-item-view-model.ts @@ -38,7 +38,7 @@ export class RedditViewModel extends observable.Observable { set isLoading(value: boolean) { if (this._isLoading !== value) { this._isLoading = value; - this.notify({ object: this, eventName: observable.knownEvents.propertyChange, propertyName: ISLOADING, value: value }); + this.notify({ object: this, eventName: observable.Observable.propertyChangeEvent, propertyName: ISLOADING, value: value }); } } @@ -69,7 +69,7 @@ export class RedditViewModel extends observable.Observable { completed: (image: any, key: string) => { if (url === key) { this.isLoading = false; - this.notify({ object: this, eventName: observable.knownEvents.propertyChange, propertyName: THUMBNAIL_IMAGE, value: image }); + this.notify({ object: this, eventName: observable.Observable.propertyChangeEvent, propertyName: THUMBNAIL_IMAGE, value: image }); } } }); @@ -87,7 +87,7 @@ export class RedditViewModel extends observable.Observable { imageSource.fromUrl(url).then(result => { this.isLoading = false; - this.notify({ object: this, eventName: observable.knownEvents.propertyChange, propertyName: IMAGE_SOURCE, value: result }); + this.notify({ object: this, eventName: observable.Observable.propertyChangeEvent, propertyName: IMAGE_SOURCE, value: result }); }); } } diff --git a/apps/editable-text-demo/model.ts b/apps/editable-text-demo/model.ts index 2fbff0238..10073cbb1 100644 --- a/apps/editable-text-demo/model.ts +++ b/apps/editable-text-demo/model.ts @@ -12,6 +12,6 @@ export class WebViewModel extends observable.Observable { set text(value: string) { console.log(value); this._text = value; - this.notify({ object: this, eventName: observable.knownEvents.propertyChange, propertyName: "text", value: value }); + this.notify({ object: this, eventName: observable.Observable.propertyChangeEvent, propertyName: "text", value: value }); } } \ No newline at end of file diff --git a/apps/perf-tests/ApplicationLoadTimeAndFPS/mainPage.ts b/apps/perf-tests/ApplicationLoadTimeAndFPS/mainPage.ts index 34d9adba6..1fa60d8b5 100644 --- a/apps/perf-tests/ApplicationLoadTimeAndFPS/mainPage.ts +++ b/apps/perf-tests/ApplicationLoadTimeAndFPS/mainPage.ts @@ -29,7 +29,7 @@ export function createPage() { var listView = new listViewModule.ListView(); listView.items = new Array(100); - listView.on(listViewModule.knownEvents.itemLoading, (args: listViewModule.ItemEventData) => { + listView.on(listViewModule.ListView.itemLoadingEvent, (args: listViewModule.ItemEventData) => { var StackLayout = args.view; if (!StackLayout) { StackLayout = createListViewItemFunc(); diff --git a/apps/perf-tests/ComplexObjectGraphMemoryTest/mainPage.ts b/apps/perf-tests/ComplexObjectGraphMemoryTest/mainPage.ts index 8d3238478..c30a9e800 100644 --- a/apps/perf-tests/ComplexObjectGraphMemoryTest/mainPage.ts +++ b/apps/perf-tests/ComplexObjectGraphMemoryTest/mainPage.ts @@ -36,7 +36,7 @@ export function createPage() { mainStackLayout.addChild(childStackLayout); for (var j = 0; j < buttonsPerRow; j++) { button = new buttonModule.Button(); - button.on(buttonModule.knownEvents.tap, function (data) { + button.on(buttonModule.Button.tapEvent, function (data) { trace.write("eventName=" + data.eventName + " object=" + data.object, trace.categories.Test, trace.messageType.info); }); button.text = "" + i + j; diff --git a/apps/perf-tests/ControlCreationSpeedTest/mainPage.ts b/apps/perf-tests/ControlCreationSpeedTest/mainPage.ts index ea289879e..81d2e8e3a 100644 --- a/apps/perf-tests/ControlCreationSpeedTest/mainPage.ts +++ b/apps/perf-tests/ControlCreationSpeedTest/mainPage.ts @@ -27,7 +27,7 @@ export function createPage() { var button = new buttonModule.Button(); button.text = text; button.width = 40; - button.on(buttonModule.knownEvents.tap, function (eventData) { + button.on(buttonModule.Button.tapEvent, function (eventData) { count = ((eventData.object).text) * 1000; countLabel.text = "Create " + count + " objects of type:"; }); @@ -79,7 +79,7 @@ export function createPage() { var addControlButtonFunc = function (text) { var button = new buttonModule.Button(); button.text = text; - button.on(buttonModule.knownEvents.tap, onClickHandler); + button.on(buttonModule.Button.tapEvent, onClickHandler); mainLayout.addChild(button); }; diff --git a/apps/perf-tests/LargeObjectArrayMemoryLeakTest/mainPage.ts b/apps/perf-tests/LargeObjectArrayMemoryLeakTest/mainPage.ts index 3fb979b61..721186ff5 100644 --- a/apps/perf-tests/LargeObjectArrayMemoryLeakTest/mainPage.ts +++ b/apps/perf-tests/LargeObjectArrayMemoryLeakTest/mainPage.ts @@ -25,7 +25,7 @@ export function createPage() { var startButtonClickHandler = function () { allocateMemory(); }; - startButton.on(buttonModule.knownEvents.tap, startButtonClickHandler); + startButton.on(buttonModule.Button.tapEvent, startButtonClickHandler); var stopButton = new buttonModule.Button(); stopButton.height = 50; @@ -34,7 +34,7 @@ export function createPage() { var stopButtonClickHandler = function () { nativeCallsWrapper.forceGarbageCollection(); }; - stopButton.on(buttonModule.knownEvents.tap, stopButtonClickHandler); + stopButton.on(buttonModule.Button.tapEvent, stopButtonClickHandler); mainStackLayout.addChild(startButton); mainStackLayout.addChild(stopButton); diff --git a/apps/perf-tests/NavigationMemoryLeakTest/mainPage.ts b/apps/perf-tests/NavigationMemoryLeakTest/mainPage.ts index 09dbf394d..ac39b0b4f 100644 --- a/apps/perf-tests/NavigationMemoryLeakTest/mainPage.ts +++ b/apps/perf-tests/NavigationMemoryLeakTest/mainPage.ts @@ -16,7 +16,7 @@ export function createPage() { var forwardIntervalId; var backIntervalId; - startButton.on(buttonModule.knownEvents.tap, function () { + startButton.on(buttonModule.Button.tapEvent, function () { forwardIntervalId = setInterval(function () { console.log("Navigating to controls page..."); diff --git a/apps/perf-tests/NavigationTest/details-page.ts b/apps/perf-tests/NavigationTest/details-page.ts index ca2fdb388..72a296533 100644 --- a/apps/perf-tests/NavigationTest/details-page.ts +++ b/apps/perf-tests/NavigationTest/details-page.ts @@ -13,13 +13,13 @@ export function createPage() { var backButton = new buttonModule.Button(); backButton.text = "< back"; - backButton.on(buttonModule.knownEvents.tap, () => { page.frame.goBack(); }); + backButton.on(buttonModule.Button.tapEvent, () => { page.frame.goBack(); }); stackLayout.addChild(backButton); var label = new labelModule.Label(); stackLayout.addChild(label); - page.on(pagesModule.knownEvents.navigatedTo, () => { + page.on(pagesModule.Page.navigatedToEvent, () => { var item = page.navigationContext; label.text = "I am detail for " + item; }); @@ -30,7 +30,7 @@ export function createPage() { var actionButton = new buttonModule.Button(); actionButton.text = "Copy"; - actionButton.on(buttonModule.knownEvents.tap, () => { + actionButton.on(buttonModule.Button.tapEvent, () => { label.text = textField.text; }); stackLayout.addChild(actionButton); diff --git a/apps/perf-tests/NavigationTest/master-page.ts b/apps/perf-tests/NavigationTest/master-page.ts index d0c7b6789..e455b00c3 100644 --- a/apps/perf-tests/NavigationTest/master-page.ts +++ b/apps/perf-tests/NavigationTest/master-page.ts @@ -14,7 +14,7 @@ export function createPage() { listView.height = 200; var itemsSource = [1, 2, 3]; - listView.on(listViewModule.knownEvents.itemLoading, (args: listViewModule.ItemEventData) => { + listView.on(listViewModule.ListView.itemLoadingEvent, (args: listViewModule.ItemEventData) => { var label = args.view; if (!label) { label = new labelModule.Label(); @@ -28,7 +28,7 @@ export function createPage() { } }); - listView.on(listViewModule.knownEvents.itemTap, (args: listViewModule.ItemEventData) => { + listView.on(listViewModule.ListView.itemTapEvent, (args: listViewModule.ItemEventData) => { var navigationEntry = { moduleName: "NavigationTest/details-page", context: itemsSource[args.index] @@ -49,7 +49,7 @@ export function createPage() { var actionButton = new buttonModule.Button(); actionButton.text = "Copy"; - actionButton.on(buttonModule.knownEvents.tap, () => { + actionButton.on(buttonModule.Button.tapEvent, () => { label.text = textField.text; }); stackLayout.addChild(actionButton); diff --git a/apps/perf-tests/NavigationTest/page1.ts b/apps/perf-tests/NavigationTest/page1.ts index c5669501c..b33aa2cd6 100644 --- a/apps/perf-tests/NavigationTest/page1.ts +++ b/apps/perf-tests/NavigationTest/page1.ts @@ -14,14 +14,14 @@ export function createPage() { var changeStateButton = new buttonModule.Button(); changeStateButton.text = "CHANGE STATE"; - changeStateButton.on(buttonModule.knownEvents.tap, () => { + changeStateButton.on(buttonModule.Button.tapEvent, () => { stateLabel.text = "CHANGED STATE"; }); stackLayout.addChild(changeStateButton); var navigateButton = new buttonModule.Button(); navigateButton.text = "->"; - navigateButton.on(buttonModule.knownEvents.tap, () => { + navigateButton.on(buttonModule.Button.tapEvent, () => { page.frame.navigate("NavigationTest/page2"); }); stackLayout.addChild(navigateButton); diff --git a/apps/perf-tests/NavigationTest/page2.ts b/apps/perf-tests/NavigationTest/page2.ts index 2afe7835b..392edb24b 100644 --- a/apps/perf-tests/NavigationTest/page2.ts +++ b/apps/perf-tests/NavigationTest/page2.ts @@ -11,7 +11,7 @@ export function createPage() { var backButton = new buttonModule.Button(); backButton.text = "<-"; - backButton.on(buttonModule.knownEvents.tap, () => { page.frame.goBack(); }); + backButton.on(buttonModule.Button.tapEvent, () => { page.frame.goBack(); }); stackLayout.addChild(backButton); page.content = stackLayout; diff --git a/apps/perf-tests/SingleUIObjectMemoryLeakTest/mainPage.ts b/apps/perf-tests/SingleUIObjectMemoryLeakTest/mainPage.ts index fabbcedce..fb1eff19c 100644 --- a/apps/perf-tests/SingleUIObjectMemoryLeakTest/mainPage.ts +++ b/apps/perf-tests/SingleUIObjectMemoryLeakTest/mainPage.ts @@ -18,13 +18,13 @@ export function createPage() { var startButton = new buttonModule.Button(); startButton.text = "Start timer"; var intervalId; - startButton.addEventListener(buttonModule.knownEvents.tap, function () { + startButton.addEventListener(buttonModule.Button.tapEvent, function () { intervalId = timer.setInterval(intervalCallback, 100); }); var stopButton = new buttonModule.Button(); stopButton.text = "Stop timer"; - stopButton.addEventListener(buttonModule.knownEvents.tap, function () { + stopButton.addEventListener(buttonModule.Button.tapEvent, function () { timer.clearInterval(intervalId); }); diff --git a/apps/perf-tests/SpeedTests/mainPage.ts b/apps/perf-tests/SpeedTests/mainPage.ts index 57ffc7ff4..1f735b884 100644 --- a/apps/perf-tests/SpeedTests/mainPage.ts +++ b/apps/perf-tests/SpeedTests/mainPage.ts @@ -23,21 +23,21 @@ export function createPage() { var dataMarshallingButton0 = new buttonModule.Button(); dataMarshallingButton0.text = "Compare JavaScript dates 10000 times"; mainLayout.addChild(dataMarshallingButton0); - dataMarshallingButton0.on(buttonModule.knownEvents.tap, function () { + dataMarshallingButton0.on(buttonModule.Button.tapEvent, function () { resultsLabel.text = testsModule.compareJavaScriptDates(10000); }); var dataMarshallingButton1 = new buttonModule.Button(); dataMarshallingButton1.text = "Compare Native dates 10000 times"; mainLayout.addChild(dataMarshallingButton1); - dataMarshallingButton1.on(buttonModule.knownEvents.tap, function () { + dataMarshallingButton1.on(buttonModule.Button.tapEvent, function () { resultsLabel.text = testsModule.compareNativeDates(10000); }); var dataMarshallingButton2 = new buttonModule.Button(); dataMarshallingButton2.text = "Bitmap -> byte[] -> Bitmap 200 times"; mainLayout.addChild(dataMarshallingButton2); - dataMarshallingButton2.on(buttonModule.knownEvents.tap, function () { + dataMarshallingButton2.on(buttonModule.Button.tapEvent, function () { testsModule.decodeAndEncodeBitmap(200, function (message) { resultsLabel.text = message; }); diff --git a/apps/perf-tests/controls-page.ts b/apps/perf-tests/controls-page.ts index 2543cb2ba..d6bcdb298 100644 --- a/apps/perf-tests/controls-page.ts +++ b/apps/perf-tests/controls-page.ts @@ -31,7 +31,7 @@ export class ControlsPage extends pagesModule.Page implements definition.Control var goBackButton = new buttonModule.Button(); goBackButton.text = "Back"; - goBackButton.on(buttonModule.knownEvents.tap, function () { + goBackButton.on(buttonModule.Button.tapEvent, function () { frameModule.topmost().goBack(); }); this._mainLayout.addChild(goBackButton); diff --git a/apps/perf-tests/nav-page.ts b/apps/perf-tests/nav-page.ts index 2ad2303aa..7bc70a567 100644 --- a/apps/perf-tests/nav-page.ts +++ b/apps/perf-tests/nav-page.ts @@ -16,7 +16,7 @@ export class NavPage extends pagesModule.Page implements definition.ControlsPage var goBackButton = new buttonModule.Button(); goBackButton.text = "<-"; - goBackButton.on(buttonModule.knownEvents.tap, function () { + goBackButton.on(buttonModule.Button.tapEvent, function () { frameModule.topmost().goBack(); }); stackLayout.addChild(goBackButton); @@ -32,7 +32,7 @@ export class NavPage extends pagesModule.Page implements definition.ControlsPage var changeStateButton = new buttonModule.Button(); changeStateButton.text = "Click me!" var clickCount = 0; - changeStateButton.on(buttonModule.knownEvents.tap, () => { + changeStateButton.on(buttonModule.Button.tapEvent, () => { //stateLabel.text = "<<>>"; //textField.text = "<<>>"; changeStateButton.text = (clickCount++).toString(); @@ -41,7 +41,7 @@ export class NavPage extends pagesModule.Page implements definition.ControlsPage var forwardButton = new buttonModule.Button(); forwardButton.text = "->"; - forwardButton.on(buttonModule.knownEvents.tap, function () { + forwardButton.on(buttonModule.Button.tapEvent, function () { var pageFactory = function () { return new NavPage(id + 1); }; diff --git a/apps/pickers-demo/model.ts b/apps/pickers-demo/model.ts index b15c9edc1..53b743849 100644 --- a/apps/pickers-demo/model.ts +++ b/apps/pickers-demo/model.ts @@ -12,7 +12,7 @@ export class WebViewModel extends observable.Observable { set selectedIndex(value: number) { console.log("selectedIndex:" + value); this._selectedIndex = value; - this.notify({ object: this, eventName: observable.knownEvents.propertyChange, propertyName: "selectedIndex", value: value }); + this.notify({ object: this, eventName: observable.Observable.propertyChangeEvent, propertyName: "selectedIndex", value: value }); } private _items: Array @@ -22,7 +22,7 @@ export class WebViewModel extends observable.Observable { set items(value: Array) { console.log("items:" + value); this._items = value; - this.notify({ object: this, eventName: observable.knownEvents.propertyChange, propertyName: "items", value: value }); + this.notify({ object: this, eventName: observable.Observable.propertyChangeEvent, propertyName: "items", value: value }); } private _day: number; @@ -32,7 +32,7 @@ export class WebViewModel extends observable.Observable { set day(value: number) { console.log("day:" + value); this._day = value; - this.notify({ object: this, eventName: observable.knownEvents.propertyChange, propertyName: "day", value: value }); + this.notify({ object: this, eventName: observable.Observable.propertyChangeEvent, propertyName: "day", value: value }); } private _month: number; @@ -42,7 +42,7 @@ export class WebViewModel extends observable.Observable { set month(value: number) { console.log("month:" + value); this._month = value; - this.notify({ object: this, eventName: observable.knownEvents.propertyChange, propertyName: "month", value: value }); + this.notify({ object: this, eventName: observable.Observable.propertyChangeEvent, propertyName: "month", value: value }); } private _year: number; @@ -52,7 +52,7 @@ export class WebViewModel extends observable.Observable { set year(value: number) { console.log("year:" + value); this._year = value; - this.notify({ object: this, eventName: observable.knownEvents.propertyChange, propertyName: "year", value: value }); + this.notify({ object: this, eventName: observable.Observable.propertyChangeEvent, propertyName: "year", value: value }); } private _hour: number; @@ -62,7 +62,7 @@ export class WebViewModel extends observable.Observable { set hour(value: number) { console.log("hour:" + value); this._hour = value; - this.notify({ object: this, eventName: observable.knownEvents.propertyChange, propertyName: "hour", value: value }); + this.notify({ object: this, eventName: observable.Observable.propertyChangeEvent, propertyName: "hour", value: value }); } private _minute: number; @@ -72,6 +72,6 @@ export class WebViewModel extends observable.Observable { set minute(value: number) { console.log("minute:" + value); this._minute = value; - this.notify({ object: this, eventName: observable.knownEvents.propertyChange, propertyName: "minute", value: value }); + this.notify({ object: this, eventName: observable.Observable.propertyChangeEvent, propertyName: "minute", value: value }); } } \ No newline at end of file diff --git a/apps/tab-view-demo/mainPage.ts b/apps/tab-view-demo/mainPage.ts index d669f698d..c0d2a57fd 100644 --- a/apps/tab-view-demo/mainPage.ts +++ b/apps/tab-view-demo/mainPage.ts @@ -37,13 +37,13 @@ export function createPage() { } } var clickHandler = clickHandlerFactory(nextIndex, length); - goToNextTabButton.on(buttonModule.knownEvents.tap, clickHandler); + goToNextTabButton.on(buttonModule.Button.tapEvent, clickHandler); // Second button var navigateToAnotherPageButton = new buttonModule.Button(); navigateToAnotherPageButton.text = "Navigate to another page"; stackLayout.addChild(navigateToAnotherPageButton); - navigateToAnotherPageButton.on(buttonModule.knownEvents.tap, function () { + navigateToAnotherPageButton.on(buttonModule.Button.tapEvent, function () { var pageFactory = function () { return new navPageModule.NavPage(0); }; diff --git a/apps/tests/app/mainPage.ts b/apps/tests/app/mainPage.ts index f9d8b418c..e49d9b51b 100644 --- a/apps/tests/app/mainPage.ts +++ b/apps/tests/app/mainPage.ts @@ -29,7 +29,7 @@ textView.style.fontSize = 8; export function createPage() { var button = new bm.Button(); button.text = "Run Tests"; - button.on(bm.knownEvents.tap, function () { + button.on(bm.Button.tapEvent, function () { tests.runAll(); }); diff --git a/apps/tests/app/pageNavigation.ts b/apps/tests/app/pageNavigation.ts index 01df436a6..47b36030a 100644 --- a/apps/tests/app/pageNavigation.ts +++ b/apps/tests/app/pageNavigation.ts @@ -10,7 +10,7 @@ export function createPage() { var button = new buttonModule.Button(); button.text = "Test"; - button.on(buttonModule.knownEvents.tap, function () { + button.on(buttonModule.Button.tapEvent, function () { var topFrame = frame.topmost(); topFrame.goBack(); }); diff --git a/apps/tests/app/testRunnerPage.ts b/apps/tests/app/testRunnerPage.ts index 5e9986261..1ba7d4e97 100644 --- a/apps/tests/app/testRunnerPage.ts +++ b/apps/tests/app/testRunnerPage.ts @@ -14,10 +14,10 @@ export function createPage() { var listView = new listViewDef.ListView(); - listView.on(listViewDef.knownEvents.itemLoading, (args: listViewDef.ItemEventData) => { + listView.on(listViewDef.ListView.itemLoadingEvent, (args: listViewDef.ItemEventData) => { var btn = args.view; if (btn) { - btn.off(bm.knownEvents.tap); + btn.off(bm.Button.tapEvent); } else { btn = new bm.Button(); @@ -26,13 +26,13 @@ export function createPage() { if (!data[args.index]) { btn.text = "Run all"; - btn.on(bm.knownEvents.tap, function () { + btn.on(bm.Button.tapEvent, function () { tests.runAll(); }); } else { var testModule = data[args.index]; btn.text = testModule; - btn.on(bm.knownEvents.tap, function () { + btn.on(bm.Button.tapEvent, function () { tests.runAll(testModule); }); } diff --git a/apps/tests/observable-array-tests.ts b/apps/tests/observable-array-tests.ts index 2a647e542..d4ba7fd29 100644 --- a/apps/tests/observable-array-tests.ts +++ b/apps/tests/observable-array-tests.ts @@ -131,7 +131,7 @@ export var test_ObservableArray_popShouldRemoveTheLastElementAndRaiseChangeEvent var index = array.length - 1; // - array.on(observableArrayModule.knownEvents.change, (args: observableArrayModule.ChangedData) => { + array.on(observableArrayModule.ObservableArray.changeEvent, (args: observableArrayModule.ChangedData) => { //// Argument (args) is ChangedData. //// args.eventName is "change". //// args.action is "delete". @@ -148,7 +148,7 @@ export var test_ObservableArray_popShouldRemoveTheLastElementAndRaiseChangeEvent // ``` // - TKUnit.assert(result.eventName === observableArrayModule.knownEvents.change && result.action === observableArrayModule.ChangeType.Delete && + TKUnit.assert(result.eventName === observableArrayModule.ObservableArray.changeEvent && result.action === observableArrayModule.ChangeType.Delete && result.removed.length === 1 && result.index === index && result.addedCount === 0, "ObservableArray pop() should raise 'change' event with correct args!"); }; @@ -176,7 +176,7 @@ export var test_ObservableArray_pushShouldAppendNewElementAndRaiseChangeEventWit // ### Handle "change" event to know more info about the change after calling push() method with single element. // ``` JavaScript var array = new observableArrayModule.ObservableArray([1, 2, 3]); - array.on(observableArrayModule.knownEvents.change, (args: observableArrayModule.ChangedData) => { + array.on(observableArrayModule.ObservableArray.changeEvent, (args: observableArrayModule.ChangedData) => { //// Argument (args) is ChangedData. //// args.eventName is "change". //// args.action is "add". @@ -193,7 +193,7 @@ export var test_ObservableArray_pushShouldAppendNewElementAndRaiseChangeEventWit // ``` // - TKUnit.assert(result.eventName === observableArrayModule.knownEvents.change && result.action === observableArrayModule.ChangeType.Add && + TKUnit.assert(result.eventName === observableArrayModule.ObservableArray.changeEvent && result.action === observableArrayModule.ChangeType.Add && result.removed.length === 0 && result.index === 3 && result.addedCount === 1, "ObservableArray push() should raise 'change' event with correct args!"); }; @@ -221,7 +221,7 @@ export var test_ObservableArray_pushShouldAppendNewElementsAndRaiseChangeEventWi // ### Handle "change" event to know more info about the change after calling push() method with multiple elements. // ``` JavaScript var array = new observableArrayModule.ObservableArray([1, 2, 3]); - array.on(observableArrayModule.knownEvents.change, (args: observableArrayModule.ChangedData) => { + array.on(observableArrayModule.ObservableArray.changeEvent, (args: observableArrayModule.ChangedData) => { //// Argument (args) is ChangedData. //// args.eventName is "change". //// args.action is "add". @@ -238,7 +238,7 @@ export var test_ObservableArray_pushShouldAppendNewElementsAndRaiseChangeEventWi // ``` // - TKUnit.assert(result.eventName === observableArrayModule.knownEvents.change && result.action === observableArrayModule.ChangeType.Add && + TKUnit.assert(result.eventName === observableArrayModule.ObservableArray.changeEvent && result.action === observableArrayModule.ChangeType.Add && result.removed.length === 0 && result.index === 3 && result.addedCount === 3, "ObservableArray push() should raise 'change' event with correct args!"); }; @@ -266,7 +266,7 @@ export var test_ObservableArray_pushShouldAppendNewElementsFromSourceArrayAndRai // ### Handle "change" event to know more info about the change after calling push() method with multiple elements from source array. // ``` JavaScript var array = new observableArrayModule.ObservableArray([1, 2, 3]); - array.on(observableArrayModule.knownEvents.change, (args: observableArrayModule.ChangedData) => { + array.on(observableArrayModule.ObservableArray.changeEvent, (args: observableArrayModule.ChangedData) => { //// Argument (args) is ChangedData. //// args.eventName is "change". //// args.action is "add". @@ -283,7 +283,7 @@ export var test_ObservableArray_pushShouldAppendNewElementsFromSourceArrayAndRai // ``` // - TKUnit.assert(result.eventName === observableArrayModule.knownEvents.change && result.action === observableArrayModule.ChangeType.Add && + TKUnit.assert(result.eventName === observableArrayModule.ObservableArray.changeEvent && result.action === observableArrayModule.ChangeType.Add && result.removed.length === 0 && result.index === 3 && result.addedCount === 3, "ObservableArray push() should raise 'change' event with correct args!"); }; @@ -323,7 +323,7 @@ export var test_ObservableArray_shiftShouldRemoveTheFirstElementAndRaiseChangeEv // ``` JavaScript var array = new observableArrayModule.ObservableArray([1, 2, 3]); - array.on(observableArrayModule.knownEvents.change, (args: observableArrayModule.ChangedData) => { + array.on(observableArrayModule.ObservableArray.changeEvent, (args: observableArrayModule.ChangedData) => { //// Argument (args) is ChangedData. //// args.eventName is "change". //// args.action is "delete". @@ -340,7 +340,7 @@ export var test_ObservableArray_shiftShouldRemoveTheFirstElementAndRaiseChangeEv // ``` // - TKUnit.assert(result.eventName === observableArrayModule.knownEvents.change && result.action === observableArrayModule.ChangeType.Delete && + TKUnit.assert(result.eventName === observableArrayModule.ObservableArray.changeEvent && result.action === observableArrayModule.ChangeType.Delete && result.removed.length === 1 && result.index === 0 && result.addedCount === 0, "ObservableArray shift() should raise 'change' event with correct args!"); }; @@ -414,7 +414,7 @@ export var test_ObservableArray_spliceShouldRemoveSpecifiedNumberOfElementsStart // ``` JavaScript var array = new observableArrayModule.ObservableArray([1, 2, 3]); - array.on(observableArrayModule.knownEvents.change, (args: observableArrayModule.ChangedData) => { + array.on(observableArrayModule.ObservableArray.changeEvent, (args: observableArrayModule.ChangedData) => { //// Argument (args) is ChangedData. //// args.eventName is "change". //// args.action is "splice". @@ -431,7 +431,7 @@ export var test_ObservableArray_spliceShouldRemoveSpecifiedNumberOfElementsStart // ``` // - TKUnit.assert(result.eventName === observableArrayModule.knownEvents.change && result.action === observableArrayModule.ChangeType.Splice && + TKUnit.assert(result.eventName === observableArrayModule.ObservableArray.changeEvent && result.action === observableArrayModule.ChangeType.Splice && result.removed.length === 2 && result.index === 1 && result.addedCount === 0, "ObservableArray splice() should raise 'change' event with correct args!"); }; @@ -455,7 +455,7 @@ export var test_ObservableArray_spliceShouldRemoveAndInertSpecifiedNumberOfEleme // ``` JavaScript var array = new observableArrayModule.ObservableArray(["one", "two", "three"]); - array.on(observableArrayModule.knownEvents.change, (args: observableArrayModule.ChangedData) => { + array.on(observableArrayModule.ObservableArray.changeEvent, (args: observableArrayModule.ChangedData) => { //// Argument (args) is ChangedData. //// args.eventName is "change". //// args.action is "splice". @@ -472,7 +472,7 @@ export var test_ObservableArray_spliceShouldRemoveAndInertSpecifiedNumberOfEleme // ``` // - TKUnit.assert(result.eventName === observableArrayModule.knownEvents.change && result.action === observableArrayModule.ChangeType.Splice && + TKUnit.assert(result.eventName === observableArrayModule.ObservableArray.changeEvent && result.action === observableArrayModule.ChangeType.Splice && result.removed.length === 2 && result.index === 1 && result.addedCount === 1, "ObservableArray splice() should raise 'change' event with correct args!"); }; @@ -501,7 +501,7 @@ export var test_ObservableArray_unshiftShouldInsertNewElementsFromTheStartAndRai // ### Handle "change" event to know more info about the change after calling unshift(item1, item2... itemN) method. // ``` JavaScript var array = new observableArrayModule.ObservableArray([1, 2, 3]); - array.on(observableArrayModule.knownEvents.change, (args: observableArrayModule.ChangedData) => { + array.on(observableArrayModule.ObservableArray.changeEvent, (args: observableArrayModule.ChangedData) => { //// Argument (args) is ChangedData. //// args.eventName is "change". //// args.action is "add". @@ -518,7 +518,7 @@ export var test_ObservableArray_unshiftShouldInsertNewElementsFromTheStartAndRai // ``` // - TKUnit.assert(result.eventName === observableArrayModule.knownEvents.change && result.action === observableArrayModule.ChangeType.Add && + TKUnit.assert(result.eventName === observableArrayModule.ObservableArray.changeEvent && result.action === observableArrayModule.ChangeType.Add && result.removed.length === 0 && result.index === 0 && result.addedCount === 2, "ObservableArray unshift() should raise 'change' event with correct args!"); }; diff --git a/apps/tests/pages/navigation/pageA-new-activity.ts b/apps/tests/pages/navigation/pageA-new-activity.ts index c0d5af16a..dc8e42d6a 100644 --- a/apps/tests/pages/navigation/pageA-new-activity.ts +++ b/apps/tests/pages/navigation/pageA-new-activity.ts @@ -10,7 +10,7 @@ export function createPage() { var btn = new button.Button(); btn.text = "Page B new activity"; - btn.on(button.knownEvents.tap, function () { + btn.on(button.Button.tapEvent, function () { var nextPage = "tests/pages/navigation/pageB-new-activity"; frame.topmost().navigate(nextPage); }); diff --git a/apps/tests/pages/navigation/pageA.ts b/apps/tests/pages/navigation/pageA.ts index d50b4ed61..7beb7edd1 100644 --- a/apps/tests/pages/navigation/pageA.ts +++ b/apps/tests/pages/navigation/pageA.ts @@ -16,7 +16,7 @@ export function createPage() { var btn = new button.Button(); btn.text = "Page B"; - btn.on(button.knownEvents.tap, function () { + btn.on(button.Button.tapEvent, function () { var nextPage = "tests/pages/navigation/pageB"; frame.topmost().navigate(nextPage); }); @@ -24,7 +24,7 @@ export function createPage() { var btnActivity = new button.Button(); btnActivity.text = "start activity"; - btnActivity.on(button.knownEvents.tap, function () { + btnActivity.on(button.Button.tapEvent, function () { var newPage = "tests/pages/navigation/pageA-new-activity"; var newFrame = new frame.Frame(); @@ -43,7 +43,7 @@ export function createPage() { } lv.height = 200; lv.items = data; - lv.on(list.knownEvents.itemLoading, (args: list.ItemEventData) => { + lv.on(list.ListView.itemLoadingEvent, (args: list.ItemEventData) => { var btn = args.view; if (!btn) { btn = new button.Button(); diff --git a/apps/tests/pages/navigation/pageB-new-activity.ts b/apps/tests/pages/navigation/pageB-new-activity.ts index 3e534fd24..99d8bc318 100644 --- a/apps/tests/pages/navigation/pageB-new-activity.ts +++ b/apps/tests/pages/navigation/pageB-new-activity.ts @@ -10,7 +10,7 @@ export function createPage() { var btn = new button.Button(); btn.text = "Page C new activity"; - btn.on(button.knownEvents.tap, function () { + btn.on(button.Button.tapEvent, function () { var nextPage = "tests/pages/navigation/pageC-new-activity"; frame.topmost().navigate(nextPage); }); @@ -18,7 +18,7 @@ export function createPage() { var backBtn = new button.Button(); backBtn.text = "BACK"; - backBtn.on(button.knownEvents.tap, function () { + backBtn.on(button.Button.tapEvent, function () { frame.topmost().goBack(); }); stack.addChild(backBtn); diff --git a/apps/tests/pages/navigation/pageB.ts b/apps/tests/pages/navigation/pageB.ts index e6caa0610..d9af436c5 100644 --- a/apps/tests/pages/navigation/pageB.ts +++ b/apps/tests/pages/navigation/pageB.ts @@ -13,7 +13,7 @@ export function createPage() { var btn = new button.Button(); btn.text = "Page C"; - btn.on(button.knownEvents.tap, function () { + btn.on(button.Button.tapEvent, function () { var nextPage = "tests/pages/navigation/pageC"; frame.topmost().navigate(nextPage); }); @@ -21,7 +21,7 @@ export function createPage() { var btnActivity = new button.Button(); btnActivity.text = "start activity"; - btnActivity.on(button.knownEvents.tap, function () { + btnActivity.on(button.Button.tapEvent, function () { var newFrame = new frame.Frame(); var newPage = "tests/pages/navigation/pageA-new-activity"; newFrame.navigate(newPage); @@ -30,7 +30,7 @@ export function createPage() { var backBtn = new button.Button(); backBtn.text = "BACK"; - backBtn.on(button.knownEvents.tap, function () { + backBtn.on(button.Button.tapEvent, function () { frame.topmost().goBack(); }); stack.addChild(backBtn); diff --git a/apps/tests/pages/navigation/pageC-new-activity.ts b/apps/tests/pages/navigation/pageC-new-activity.ts index 42a5b8591..a64604b55 100644 --- a/apps/tests/pages/navigation/pageC-new-activity.ts +++ b/apps/tests/pages/navigation/pageC-new-activity.ts @@ -10,7 +10,7 @@ export function createPage() { var btn = new button.Button(); btn.text = "Page A ???"; - btn.on(button.knownEvents.tap, function () { + btn.on(button.Button.tapEvent, function () { var newPage = "tests/pages/navigation/pageA"; frame.topmost().navigate(newPage); }); @@ -18,7 +18,7 @@ export function createPage() { var backBtn = new button.Button(); backBtn.text = "BACK"; - backBtn.on(button.knownEvents.tap, function () { + backBtn.on(button.Button.tapEvent, function () { frame.topmost().goBack(); }); stack.addChild(backBtn); diff --git a/apps/tests/pages/navigation/pageC.ts b/apps/tests/pages/navigation/pageC.ts index 4b04762c8..76f331d1c 100644 --- a/apps/tests/pages/navigation/pageC.ts +++ b/apps/tests/pages/navigation/pageC.ts @@ -10,7 +10,7 @@ export function createPage() { var newActivity = new button.Button(); newActivity.text = "start activity"; - newActivity.on(button.knownEvents.tap, function () { + newActivity.on(button.Button.tapEvent, function () { var newFrame = new frame.Frame(); var newPage = "tests/pages/navigation/pageA-new-activity"; newFrame.navigate(newPage); @@ -19,7 +19,7 @@ export function createPage() { var btn = new button.Button(); btn.text = "Page A ???"; - btn.on(button.knownEvents.tap, function () { + btn.on(button.Button.tapEvent, function () { var nextPage = "tests/pages/navigation/pageA"; frame.topmost().navigate(nextPage); }); @@ -27,7 +27,7 @@ export function createPage() { var backBtn = new button.Button(); backBtn.text = "BACK"; - backBtn.on(button.knownEvents.tap, function () { + backBtn.on(button.Button.tapEvent, function () { frame.topmost().goBack(); }); stack.addChild(backBtn); diff --git a/apps/tests/pages/page11.ts b/apps/tests/pages/page11.ts index 238cae7a7..2ede06fda 100644 --- a/apps/tests/pages/page11.ts +++ b/apps/tests/pages/page11.ts @@ -52,7 +52,7 @@ export function createPage() { //page.content = GridLayout; page.content = StackLayout; var x = 1; - btn1.on(button.knownEvents.tap, function () { + btn1.on(button.Button.tapEvent, function () { x++; var gravity; //btn1.android.setLayoutParams(new android.view.ViewGroup.LayoutParams(android.view.ViewGroup.LayoutParams.FILL_PARENT, android.view.ViewGroup.LayoutParams.FILL_PARENT)); diff --git a/apps/tests/pages/page7.ts b/apps/tests/pages/page7.ts index 4d7054688..01217d9d5 100644 --- a/apps/tests/pages/page7.ts +++ b/apps/tests/pages/page7.ts @@ -12,7 +12,7 @@ export function createPage() { var vAligns = ["stretch", "top", "center", "bottom"]; //var hAligns = ["stretch", "left", "center", "right"]; var count = 0; - btn.on(buttons.knownEvents.tap, function () { + btn.on(buttons.Button.tapEvent, function () { //page.css = "button { vertical-align:" + vAligns[(count++) % 4] + " }"; btn.verticalAlignment = vAligns[(count++) % 4]; }) diff --git a/apps/tests/pages/page8.ts b/apps/tests/pages/page8.ts index bce264e40..866d26ab8 100644 --- a/apps/tests/pages/page8.ts +++ b/apps/tests/pages/page8.ts @@ -39,7 +39,7 @@ export function createPage() { var counter = 0; var btn = new btns.Button(); btn.text = "tap"; - btn.on(btns.knownEvents.tap, function () { + btn.on(btns.Button.tapEvent, function () { btn.text = "hi: " + counter++; }); btn.isEnabled = false; @@ -50,7 +50,7 @@ export function createPage() { var info = new btns.Button(); info.text = "info"; info.cssClass = "info"; - info.on(btns.knownEvents.tap, function () { + info.on(btns.Button.tapEvent, function () { info.text = "hi: " + counter++; btn.isEnabled = true; }); diff --git a/apps/tests/pages/property-bindings.ts b/apps/tests/pages/property-bindings.ts index c7b069745..745748083 100644 --- a/apps/tests/pages/property-bindings.ts +++ b/apps/tests/pages/property-bindings.ts @@ -41,7 +41,7 @@ export function createPage() { var count = 0; var control = new btns.Button(); control.text = "test control"; - control.on(btns.knownEvents.tap, (data) => { control.text = "count: " + count++; }); + control.on(btns.Button.tapEvent, (data) => { control.text = "count: " + count++; }); grid.addChild(control); var scrollView = new scroll.ScrollView(); diff --git a/apps/tests/text/formatted-string-tests.ts b/apps/tests/text/formatted-string-tests.ts index f897fc0fc..5c9ef10c6 100644 --- a/apps/tests/text/formatted-string-tests.ts +++ b/apps/tests/text/formatted-string-tests.ts @@ -26,15 +26,15 @@ export var test_FormattedString_RemovesEventListeners_for_spans = function () { // ``` // - TKUnit.assert(formattedString.spans.getItem(0).hasListeners(observable.knownEvents.propertyChange) === true, "Listener for spans collection change event is not attached!"); + TKUnit.assert(formattedString.spans.getItem(0).hasListeners(observable.Observable.propertyChangeEvent) === true, "Listener for spans collection change event is not attached!"); var removedSpan = formattedString.spans.pop(); - TKUnit.assert(removedSpan.hasListeners(observable.knownEvents.propertyChange) === false, "Listener for spans collection change event is not removed!"); + TKUnit.assert(removedSpan.hasListeners(observable.Observable.propertyChangeEvent) === false, "Listener for spans collection change event is not removed!"); } export var test_FormattedTextProperty_IsChanged_When_SpanIsAdded = function () { var formattedString = new formattedStringModule.FormattedString(); var formattedTextChanged = false; - formattedString.addEventListener(observable.knownEvents.propertyChange, () => { + formattedString.addEventListener(observable.Observable.propertyChangeEvent, () => { formattedTextChanged = true; }); @@ -56,7 +56,7 @@ export var test_FormattedTextProperty_IsChanged_When_SpanIsChanged = function () formattedString.spans.push(firstSpan); var formattedTextChanged = false; - formattedString.addEventListener(observable.knownEvents.propertyChange, () => { + formattedString.addEventListener(observable.Observable.propertyChangeEvent, () => { formattedTextChanged = true; }); diff --git a/apps/tests/ui/bindable-tests.ts b/apps/tests/ui/bindable-tests.ts index 8081cc365..9fe2f0407 100644 --- a/apps/tests/ui/bindable-tests.ts +++ b/apps/tests/ui/bindable-tests.ts @@ -190,7 +190,7 @@ export var test_WhenBindingIsSetToAnElement_AndElementIsRemoved_ShouldBeCollecte var sourcePropertyName = "testProperty"; var targetPropertyName = "text"; - page.on(viewModule.knownEvents.loaded, () => { + page.on(viewModule.View.loadedEvent, () => { var model = new observable.Observable(); model.set(sourcePropertyName, expectedValue); diff --git a/apps/tests/ui/button/button-tests.ts b/apps/tests/ui/button/button-tests.ts index f5ff60a1a..b86f57d32 100644 --- a/apps/tests/ui/button/button-tests.ts +++ b/apps/tests/ui/button/button-tests.ts @@ -120,7 +120,7 @@ var _testOnClick = function (views: Array) { // // ### Responding to the tap event // ``` JavaScript - button.on(buttonModule.knownEvents.tap, function (args: observable.EventData) { + button.on(buttonModule.Button.tapEvent, function (args: observable.EventData) { //// Do something // actualValue = true; diff --git a/apps/tests/ui/dependency-observable-tests.ts b/apps/tests/ui/dependency-observable-tests.ts index 7a1d250d2..cf8483610 100644 --- a/apps/tests/ui/dependency-observable-tests.ts +++ b/apps/tests/ui/dependency-observable-tests.ts @@ -31,7 +31,7 @@ function validateDOChangeData(obj: TestDO, property: dependencyObservableModule. TKUnit.assert(currentChangeData.property === property, "metadata.onValueChanged method called with wrong property member"); TKUnit.assert(currentChangeData.newValue === newValue, "metadata.onValueChanged method called with wrong newValue member"); TKUnit.assert(currentChangeData.oldValue === oldValue, "metadata.onValueChanged method called with wrong oldValue member"); - TKUnit.assert(currentChangeData.eventName === observableModule.knownEvents.propertyChange, "metadata.onValueChanged method called with wrong eventName member"); + TKUnit.assert(currentChangeData.eventName === observableModule.Observable.propertyChangeEvent, "metadata.onValueChanged method called with wrong eventName member"); } function validateChangeData(data: observableModule.PropertyChangeData, obj: observableModule.Observable, propertyName: string, newValue: any) { @@ -39,7 +39,7 @@ function validateChangeData(data: observableModule.PropertyChangeData, obj: obse TKUnit.assert(data.object === obj, "DependencyObservable.on called with wrong object member."); TKUnit.assert(data.propertyName === propertyName, "DependencyObservable.on called with wrong propertyName member"); TKUnit.assert(data.value === newValue, "DependencyObservable.on called with wrong value member"); - TKUnit.assert(data.eventName === observableModule.knownEvents.propertyChange, "DependencyObservable.on method called with wrong eventName member"); + TKUnit.assert(data.eventName === observableModule.Observable.propertyChangeEvent, "DependencyObservable.on method called with wrong eventName member"); } // @@ -342,7 +342,7 @@ export function test_Observable_on_propertyChange_IsRaised() { var dO1 = new TestDO(); var changeData: observableModule.PropertyChangeData; - dO1.on(observableModule.knownEvents.propertyChange, function (data: observableModule.PropertyChangeData) { + dO1.on(observableModule.Observable.propertyChangeEvent, function (data: observableModule.PropertyChangeData) { changeData = data; }); diff --git a/apps/tests/ui/list-view/list-view-tests.ts b/apps/tests/ui/list-view/list-view-tests.ts index 09cbc8cb2..5522104d9 100644 --- a/apps/tests/ui/list-view/list-view-tests.ts +++ b/apps/tests/ui/list-view/list-view-tests.ts @@ -105,7 +105,7 @@ export function test_set_items_to_array_loads_all_items() { // ``` JavaScript var colors = ["red", "green", "blue"]; listView.items = colors; - listView.on(listViewModule.knownEvents.itemLoading, function (args: listViewModule.ItemEventData) { + listView.on(listViewModule.ListView.itemLoadingEvent, function (args: listViewModule.ItemEventData) { if (!args.view) { //// Create label if it is not already created. args.view = new labelModule.Label(); @@ -130,7 +130,7 @@ export function test_set_items_to_array_loads_all_items() { export function test_set_items_to_array_creates_native_views() { var listView = new listViewModule.ListView(); - listView.on(listViewModule.knownEvents.itemLoading, loadViewWithItemNumber); + listView.on(listViewModule.ListView.itemLoadingEvent, loadViewWithItemNumber); function testAction(views: Array) { listView.items = FEW_ITEMS; @@ -145,7 +145,7 @@ export function test_set_items_to_array_creates_native_views() { export function test_refresh_after_adding_items_to_array_loads_new_items() { var listView = new listViewModule.ListView(); - listView.on(listViewModule.knownEvents.itemLoading, loadViewWithItemNumber); + listView.on(listViewModule.ListView.itemLoadingEvent, loadViewWithItemNumber); function testAction(views: Array) { var colors = ["red", "green", "blue"]; @@ -176,7 +176,7 @@ export function test_refresh_reloads_all_items() { var indexes = {}; var testStarted = false; listView.items = FEW_ITEMS; - listView.on(listViewModule.knownEvents.itemLoading, function (args: listViewModule.ItemEventData) { + listView.on(listViewModule.ListView.itemLoadingEvent, function (args: listViewModule.ItemEventData) { if (!args.view) { args.view = new labelModule.Label(); } @@ -202,7 +202,7 @@ export function test_refresh_reloads_all_items() { export function test_set_itmes_to_null_clears_native_items() { var listView = new listViewModule.ListView(); - listView.on(listViewModule.knownEvents.itemLoading, loadViewWithItemNumber); + listView.on(listViewModule.ListView.itemLoadingEvent, loadViewWithItemNumber); function testAction(views: Array) { listView.items = FEW_ITEMS; @@ -219,7 +219,7 @@ export function test_set_itmes_to_null_clears_native_items() { export function test_set_itmes_to_undefiend_clears_native_items() { var listView = new listViewModule.ListView(); - listView.on(listViewModule.knownEvents.itemLoading, loadViewWithItemNumber); + listView.on(listViewModule.ListView.itemLoadingEvent, loadViewWithItemNumber); function testAction(views: Array) { listView.items = FEW_ITEMS; @@ -236,7 +236,7 @@ export function test_set_itmes_to_undefiend_clears_native_items() { export function test_set_itmes_to_different_source_loads_new_items() { var listView = new listViewModule.ListView(); - listView.on(listViewModule.knownEvents.itemLoading, loadViewWithItemNumber); + listView.on(listViewModule.ListView.itemLoadingEvent, loadViewWithItemNumber); function testAction(views: Array) { listView.items = [1, 2, 3]; @@ -261,7 +261,7 @@ export function test_set_items_to_observable_array_loads_all_items() { // ``` JavaScript var colors = new observableArray.ObservableArray(["red", "green", "blue"]); listView.items = colors; - listView.on(listViewModule.knownEvents.itemLoading, function (args: listViewModule.ItemEventData) { + listView.on(listViewModule.ListView.itemLoadingEvent, function (args: listViewModule.ItemEventData) { if (!args.view) { //// Create label if it is not already created. args.view = new labelModule.Label(); @@ -284,7 +284,7 @@ export function test_set_items_to_observable_array_loads_all_items() { export function test_add_to_observable_array_refreshes_the_listview() { var listView = new listViewModule.ListView(); - listView.on(listViewModule.knownEvents.itemLoading, loadViewWithItemNumber); + listView.on(listViewModule.ListView.itemLoadingEvent, loadViewWithItemNumber); function testAction(views: Array) { var colors = new observableArray.ObservableArray(["red", "green", "blue"]); @@ -314,7 +314,7 @@ export function test_remove_from_observable_array_refreshes_the_listview() { function testAction(views: Array) { listView.items = data; - listView.on(listViewModule.knownEvents.itemLoading, loadViewWithItemNumber); + listView.on(listViewModule.ListView.itemLoadingEvent, loadViewWithItemNumber); TKUnit.wait(ASYNC); TKUnit.assertEqual(getNativeViewCount(listView), 3, "getNativeViewCount"); @@ -334,7 +334,7 @@ export function test_splice_observable_array_refreshes_the_listview() { function testAction(views: Array) { listView.items = data; - listView.on(listViewModule.knownEvents.itemLoading, loadViewWithItemNumber); + listView.on(listViewModule.ListView.itemLoadingEvent, loadViewWithItemNumber); TKUnit.wait(ASYNC); TKUnit.assertEqual(getNativeViewCount(listView), 3, "getNativeViewCount"); @@ -350,7 +350,7 @@ export function test_splice_observable_array_refreshes_the_listview() { } export function test_nativeTap_is_raised() { var listView = new listViewModule.ListView(); - listView.on(listViewModule.knownEvents.itemLoading, loadViewWithItemNumber); + listView.on(listViewModule.ListView.itemLoadingEvent, loadViewWithItemNumber); listView.items = FEW_ITEMS; function testAction(views: Array) { @@ -362,7 +362,7 @@ export function test_nativeTap_is_raised() { // ### ItemTap event // The event will be raise when an item inside the ListView is tapped. // ``` JavaScript - listView.on(listViewModule.knownEvents.itemTap, function (args: listViewModule.ItemEventData) { + listView.on(listViewModule.ListView.itemTapEvent, function (args: listViewModule.ItemEventData) { var tappedItemIndex = args.index; var tappedItemView = args.view; //// Do someting @@ -390,13 +390,13 @@ export function test_loadMoreItems_raised_when_showing_few_items() { function testAction(views: Array) { var loadMoreItemsCount = 0; listView.items = FEW_ITEMS; - listView.on(listViewModule.knownEvents.itemLoading, loadViewWithItemNumber); + listView.on(listViewModule.ListView.itemLoadingEvent, loadViewWithItemNumber); // // ### LoadMoreItems event // The event will be raised when the ListView is scrolled so that the last item is visible. // This even is intended to be used to add additional data in the ListView. // ``` JavaScript - listView.on(listViewModule.knownEvents.loadMoreItems, function (data: observable.EventData) { + listView.on(listViewModule.ListView.loadMoreItemsEvent, function (data: observable.EventData) { //// Do something. // loadMoreItemsCount++; @@ -413,12 +413,12 @@ export function test_loadMoreItems_raised_when_showing_few_items() { export function test_loadMoreItems_not_raised_when_showing_many_items() { var listView = new listViewModule.ListView(); - listView.on(listViewModule.knownEvents.itemLoading, loadViewWithItemNumber); + listView.on(listViewModule.ListView.itemLoadingEvent, loadViewWithItemNumber); function testAction(views: Array) { var loadMoreItemsCount = 0; listView.items = MANY_ITEMS; - listView.on(listViewModule.knownEvents.loadMoreItems, function (data: observable.EventData) { + listView.on(listViewModule.ListView.loadMoreItemsEvent, function (data: observable.EventData) { loadMoreItemsCount++; }); diff --git a/apps/tests/ui/observable-tests.ts b/apps/tests/ui/observable-tests.ts index 9f6cc36e8..a8b9f8440 100644 --- a/apps/tests/ui/observable-tests.ts +++ b/apps/tests/ui/observable-tests.ts @@ -47,7 +47,7 @@ export var tests_DummyTestForCodeSnippet = function () { person.set("Name", "John"); person.set("Age", 34); person.set("Married", true); - person.addEventListener(observable.knownEvents.propertyChange, function (pcd: observable.PropertyChangeData) { + person.addEventListener(observable.Observable.propertyChangeEvent, function (pcd: observable.PropertyChangeData) { //console.log(pcd.eventName.toString() + " " + pcd.propertyName.toString() + " " + pcd.value.toString()); }); person.set("Age", 35); @@ -83,7 +83,7 @@ export var test_Observable_UpdateAnotherPropertyWithinChangedCallback = function } } - obj.addEventListener(observable.knownEvents.propertyChange, changedCallback); + obj.addEventListener(observable.Observable.propertyChangeEvent, changedCallback); obj.set("name", "Initial name"); obj.set("test", "Initial test"); @@ -143,13 +143,13 @@ export var test_Observable_addEventListener_SingleEvent = function () { var receivedCount = 0; var callback = function (data: observable.PropertyChangeData) { receivedCount++; - TKUnit.assert(data.eventName === observable.knownEvents.propertyChange, "Expected event name " + observable.knownEvents.propertyChange); + TKUnit.assert(data.eventName === observable.Observable.propertyChangeEvent, "Expected event name " + observable.Observable.propertyChangeEvent); TKUnit.assert(data.object === obj, "PropertyChangeData.object value not valid."); TKUnit.assert(data.propertyName === "testName", "PropertyChangeData.propertyName value not valid."); TKUnit.assert(data.value === 1, "PropertyChangeData.value value not valid."); } - obj.addEventListener(observable.knownEvents.propertyChange, callback); + obj.addEventListener(observable.Observable.propertyChangeEvent, callback); obj.set("testName", 1); TKUnit.assert(receivedCount === 1, "PropertyChanged event not raised properly."); } @@ -162,9 +162,9 @@ export var test_Observable_addEventListener_MultipleEvents = function () { receivedCount++; TKUnit.assert(data.object === obj, "EventData.object value not valid."); - if (data.eventName === observable.knownEvents.propertyChange) { + if (data.eventName === observable.Observable.propertyChangeEvent) { var propertyData = data; - TKUnit.assert(propertyData.eventName === observable.knownEvents.propertyChange, "Expected event name " + observable.knownEvents.propertyChange); + TKUnit.assert(propertyData.eventName === observable.Observable.propertyChangeEvent, "Expected event name " + observable.Observable.propertyChangeEvent); TKUnit.assert(propertyData.propertyName === "testName", "PropertyChangeData.propertyName value not valid."); TKUnit.assert(propertyData.value === 1, "PropertyChangeData.value value not valid."); } else { @@ -172,7 +172,7 @@ export var test_Observable_addEventListener_MultipleEvents = function () { } } - var events = observable.knownEvents.propertyChange + "," + TESTED_NAME; + var events = observable.Observable.propertyChangeEvent + "," + TESTED_NAME; obj.addEventListener(events, callback); obj.set("testName", 1); obj.test(); @@ -187,9 +187,9 @@ export var test_Observable_addEventListener_MultipleEvents_ShouldTrim = function receivedCount++; } - var events = observable.knownEvents.propertyChange + " , " + TESTED_NAME; + var events = observable.Observable.propertyChangeEvent + " , " + TESTED_NAME; obj.addEventListener(events, callback); - TKUnit.assert(obj.hasListeners(observable.knownEvents.propertyChange), "Observable.addEventListener for multiple events should trim each event name."); + TKUnit.assert(obj.hasListeners(observable.Observable.propertyChangeEvent), "Observable.addEventListener for multiple events should trim each event name."); TKUnit.assert(obj.hasListeners(TESTED_NAME), "Observable.addEventListener for multiple events should trim each event name."); obj.set("testName", 1); @@ -210,8 +210,8 @@ export var test_Observable_addEventListener_MultipleCallbacks = function () { receivedCount++; } - obj.addEventListener(observable.knownEvents.propertyChange, callback1); - obj.addEventListener(observable.knownEvents.propertyChange, callback2); + obj.addEventListener(observable.Observable.propertyChangeEvent, callback1); + obj.addEventListener(observable.Observable.propertyChangeEvent, callback2); obj.set("testName", 1); TKUnit.assert(receivedCount === 2, "The propertyChanged notification should be raised twice."); @@ -229,7 +229,7 @@ export var test_Observable_addEventListener_MultipleCallbacks_MultipleEvents = f receivedCount++; } - var events = observable.knownEvents.propertyChange + " , " + TESTED_NAME; + var events = observable.Observable.propertyChangeEvent + " , " + TESTED_NAME; obj.addEventListener(events, callback1); obj.addEventListener(events, callback2); @@ -247,11 +247,11 @@ export var test_Observable_removeEventListener_SingleEvent_SingleCallback = func receivedCount++; } - obj.addEventListener(observable.knownEvents.propertyChange, callback); + obj.addEventListener(observable.Observable.propertyChangeEvent, callback); obj.set("testName", 1); - obj.removeEventListener(observable.knownEvents.propertyChange, callback); - TKUnit.assert(!obj.hasListeners(observable.knownEvents.propertyChange), "Observable.removeEventListener not working properly."); + obj.removeEventListener(observable.Observable.propertyChangeEvent, callback); + TKUnit.assert(!obj.hasListeners(observable.Observable.propertyChangeEvent), "Observable.removeEventListener not working properly."); obj.set("testName", 2); TKUnit.assert(receivedCount === 1, "Observable.removeEventListener not working properly."); @@ -269,18 +269,18 @@ export var test_Observable_removeEventListener_SingleEvent_MultipleCallbacks = f receivedCount++; } - obj.addEventListener(observable.knownEvents.propertyChange, callback1); - obj.addEventListener(observable.knownEvents.propertyChange, callback2); + obj.addEventListener(observable.Observable.propertyChangeEvent, callback1); + obj.addEventListener(observable.Observable.propertyChangeEvent, callback2); obj.set("testName", 1); - obj.removeEventListener(observable.knownEvents.propertyChange, callback1); - TKUnit.assert(obj.hasListeners(observable.knownEvents.propertyChange), "Observable.removeEventListener not working properly with multiple listeners."); + obj.removeEventListener(observable.Observable.propertyChangeEvent, callback1); + TKUnit.assert(obj.hasListeners(observable.Observable.propertyChangeEvent), "Observable.removeEventListener not working properly with multiple listeners."); obj.set("testName", 2); TKUnit.assert(receivedCount === 3, "Observable.removeEventListener not working properly with multiple listeners."); - obj.removeEventListener(observable.knownEvents.propertyChange, callback2); - TKUnit.assert(!obj.hasListeners(observable.knownEvents.propertyChange), "Observable.removeEventListener not working properly with multiple listeners."); + obj.removeEventListener(observable.Observable.propertyChangeEvent, callback2); + TKUnit.assert(!obj.hasListeners(observable.Observable.propertyChangeEvent), "Observable.removeEventListener not working properly with multiple listeners."); obj.set("testName", 3); TKUnit.assert(receivedCount === 3, "Observable.removeEventListener not working properly with multiple listeners."); @@ -294,7 +294,7 @@ export var test_Observable_removeEventListener_MutlipleEvents_SingleCallback = f receivedCount++; } - var events = observable.knownEvents.propertyChange + " , " + TESTED_NAME; + var events = observable.Observable.propertyChangeEvent + " , " + TESTED_NAME; obj.addEventListener(events, callback); obj.set("testName", 1); @@ -302,7 +302,7 @@ export var test_Observable_removeEventListener_MutlipleEvents_SingleCallback = f obj.removeEventListener(events, callback); - TKUnit.assert(!obj.hasListeners(observable.knownEvents.propertyChange), "Expected result for hasObservers is false"); + TKUnit.assert(!obj.hasListeners(observable.Observable.propertyChangeEvent), "Expected result for hasObservers is false"); TKUnit.assert(!obj.hasListeners(TESTED_NAME), "Expected result for hasObservers is false."); obj.set("testName", 2); @@ -323,13 +323,13 @@ export var test_Observable_removeEventListener_SingleEvent_NoCallbackSpecified = receivedCount++; } - obj.addEventListener(observable.knownEvents.propertyChange, callback1); - obj.addEventListener(observable.knownEvents.propertyChange, callback2); + obj.addEventListener(observable.Observable.propertyChangeEvent, callback1); + obj.addEventListener(observable.Observable.propertyChangeEvent, callback2); obj.set("testName", 1); - obj.removeEventListener(observable.knownEvents.propertyChange); + obj.removeEventListener(observable.Observable.propertyChangeEvent); - TKUnit.assert(!obj.hasListeners(observable.knownEvents.propertyChange), "Expected result for hasObservers is false."); + TKUnit.assert(!obj.hasListeners(observable.Observable.propertyChangeEvent), "Expected result for hasObservers is false."); obj.set("testName", 2); TKUnit.assert(receivedCount === 2, "Expected receive count is 2"); diff --git a/apps/tests/ui/page/page-tests-common.ts b/apps/tests/ui/page/page-tests-common.ts index a9f2cb0d1..0c667991f 100644 --- a/apps/tests/ui/page/page-tests-common.ts +++ b/apps/tests/ui/page/page-tests-common.ts @@ -125,7 +125,7 @@ export function test_AfterPageLoaded_is_called_NativeInstance_is_created() { var pageFactory = function (): PageModule.Page { page = new PageModule.Page(); - page.on(view.knownEvents.loaded, handler); + page.on(view.View.loadedEvent, handler); label = new LabelModule.Label(); label.text = "Text"; @@ -139,7 +139,7 @@ export function test_AfterPageLoaded_is_called_NativeInstance_is_created() { TKUnit.assert(nativeInstanceCreated, "Expected: true, Actual: " + nativeInstanceCreated); } finally { - page.off(view.knownEvents.loaded, handler); + page.off(view.View.loadedEvent, handler); helper.goBack(); } } @@ -166,7 +166,7 @@ export function test_PageLoaded_is_called_once() { var pageFactory2 = function (): PageModule.Page { page2 = new PageModule.Page(); addLabelToPage(page2, "Page 2"); - page2.on(view.knownEvents.loaded, handler); + page2.on(view.View.loadedEvent, handler); return page2; }; @@ -176,7 +176,7 @@ export function test_PageLoaded_is_called_once() { TKUnit.assert(loaded === 1, "Expected: 1, Actual: " + loaded); } finally { - page2.off(view.knownEvents.loaded, handler); + page2.off(view.View.loadedEvent, handler); helper.goBack(); helper.goBack(); } diff --git a/apps/tests/ui/page/page-tests.ios.ts b/apps/tests/ui/page/page-tests.ios.ts index 8c035dafe..795900dfb 100644 --- a/apps/tests/ui/page/page-tests.ios.ts +++ b/apps/tests/ui/page/page-tests.ios.ts @@ -33,13 +33,13 @@ export function test_NavBar_isVisible_when_MenuItems_areSet() { var navBarIsVisible = false; var handler = function (data) { - page.off(view.knownEvents.loaded, handler); + page.off(view.View.loadedEvent, handler); navBarIsVisible = (page.frame.ios).showNavigationBar; } var pageFactory = function (): PageModule.Page { page = new PageModule.Page(); - page.on(view.knownEvents.loaded, handler); + page.on(view.View.loadedEvent, handler); var mi = new PageModule.MenuItem(); mi.text = "B"; @@ -56,7 +56,7 @@ export function test_NavBar_isVisible_when_MenuItems_areSet() { TKUnit.assert(navBarIsVisible, "Expected: true, Actual: " + navBarIsVisible); } finally { - page.off(view.knownEvents.loaded, handler); + page.off(view.View.loadedEvent, handler); helper.goBack(); } } \ No newline at end of file diff --git a/apps/tests/ui/progress/progress-tests.ts b/apps/tests/ui/progress/progress-tests.ts index f06a91f5b..9924edbf8 100644 --- a/apps/tests/ui/progress/progress-tests.ts +++ b/apps/tests/ui/progress/progress-tests.ts @@ -99,14 +99,14 @@ export function test_property_changed_event_when_setting_maxValue_with_adjust() function testAction(views: Array) { var changedProperties = {}; var allChanges = 0; - progress.on(observable.knownEvents.propertyChange, function (data: observable.EventData) { + progress.on(observable.Observable.propertyChangeEvent, function (data: observable.EventData) { allChanges++; changedProperties[(data).propertyName] = true; }); // Act progress.maxValue = 40; - progress.off(observable.knownEvents.propertyChange); + progress.off(observable.Observable.propertyChangeEvent); // Assert TKUnit.assert(changedProperties["value"], "Property changed for 'value' not called."); diff --git a/apps/tests/ui/search-bar/search-bar-tests.ts b/apps/tests/ui/search-bar/search-bar-tests.ts index 0c6c4bbb6..876711e07 100644 --- a/apps/tests/ui/search-bar/search-bar-tests.ts +++ b/apps/tests/ui/search-bar/search-bar-tests.ts @@ -20,10 +20,10 @@ export function test_DummyTestForSnippetOnly() { // ### Searching // ``` JavaScript var searchBar = new searchBarModule.SearchBar(); - searchBar.on(searchBarModule.knownEvents.submit, function (args: observable.EventData) { + searchBar.on(searchBarModule.SearchBar.submitEvent, function (args: observable.EventData) { console.log("Search for " + (args.object).text); }); - searchBar.on(searchBarModule.knownEvents.clear, function (args: observable.EventData) { + searchBar.on(searchBarModule.SearchBar.clearEvent, function (args: observable.EventData) { console.log("Clear"); }); // ``` diff --git a/apps/tests/ui/slider/slider-tests.ts b/apps/tests/ui/slider/slider-tests.ts index 79ee3a4fe..ab3b117a8 100644 --- a/apps/tests/ui/slider/slider-tests.ts +++ b/apps/tests/ui/slider/slider-tests.ts @@ -65,7 +65,7 @@ export function test_set_native_value_triggers_propertyChanged() { function testAction(views: Array) { var valueChanged = false; var allChanges = 0; - slider.on(observable.knownEvents.propertyChange, function (data: observable.EventData) { + slider.on(observable.Observable.propertyChangeEvent, function (data: observable.EventData) { allChanges++; var propertyData = data; if (propertyData && propertyData.propertyName === "value" && propertyData.value === TEST_VALUE) { @@ -75,7 +75,7 @@ export function test_set_native_value_triggers_propertyChanged() { setNativeValue(slider, TEST_VALUE); - slider.off(observable.knownEvents.propertyChange); + slider.off(observable.Observable.propertyChangeEvent); TKUnit.assert(valueChanged, "Property changed for value not called."); TKUnit.assertEqual(allChanges, 1, "Property changed callbacks."); @@ -206,14 +206,14 @@ export function test_property_changed_event_when_setting_minValue_no_adjust() { function testAction(views: Array) { var changedProperties = {}; var allChanges = 0; - slider.on(observable.knownEvents.propertyChange, function (data: observable.EventData) { + slider.on(observable.Observable.propertyChangeEvent, function (data: observable.EventData) { allChanges++; changedProperties[(data).propertyName] = true; }); // Act slider.minValue = 10; - slider.off(observable.knownEvents.propertyChange); + slider.off(observable.Observable.propertyChangeEvent); // Assert TKUnit.assert(changedProperties["minValue"], "Property changed for minValue not called."); @@ -232,14 +232,14 @@ export function test_property_changed_event_when_setting_minValue_with_adjust() function testAction(views: Array) { var changedProperties = {}; var allChanges = 0; - slider.on(observable.knownEvents.propertyChange, function (data: observable.EventData) { + slider.on(observable.Observable.propertyChangeEvent, function (data: observable.EventData) { allChanges++; changedProperties[(data).propertyName] = true; }); // Act slider.minValue = 60; - slider.off(observable.knownEvents.propertyChange); + slider.off(observable.Observable.propertyChangeEvent); // Assert TKUnit.assert(changedProperties["value"], "Property changed for 'value' not called."); @@ -259,14 +259,14 @@ export function test_property_changed_event_when_setting_maxValue_no_adjust() { function testAction(views: Array) { var changedProperties = {}; var allChanges = 0; - slider.on(observable.knownEvents.propertyChange, function (data: observable.EventData) { + slider.on(observable.Observable.propertyChangeEvent, function (data: observable.EventData) { allChanges++; changedProperties[(data).propertyName] = true; }); // Act slider.maxValue = 200; - slider.off(observable.knownEvents.propertyChange); + slider.off(observable.Observable.propertyChangeEvent); // Assert TKUnit.assert(changedProperties["maxValue"], "Property changed for maxValue not called."); @@ -285,14 +285,14 @@ export function test_property_changed_event_when_setting_maxValue_with_adjust() function testAction(views: Array) { var changedProperties = {}; var allChanges = 0; - slider.on(observable.knownEvents.propertyChange, function (data: observable.EventData) { + slider.on(observable.Observable.propertyChangeEvent, function (data: observable.EventData) { allChanges++; changedProperties[(data).propertyName] = true; }); // Act slider.maxValue = 40; - slider.off(observable.knownEvents.propertyChange); + slider.off(observable.Observable.propertyChangeEvent); // Assert TKUnit.assert(changedProperties["value"], "Property changed for 'value' not called."); diff --git a/apps/tests/ui/style/style-properties-tests.ts b/apps/tests/ui/style/style-properties-tests.ts index 21513469d..688d1efd6 100644 --- a/apps/tests/ui/style/style-properties-tests.ts +++ b/apps/tests/ui/style/style-properties-tests.ts @@ -178,7 +178,7 @@ export function test_setting_same_color_does_not_trigger_property_change() { testView.style.color = new color.Color("#FF0000"); var changed = false; - testView.style.on(observable.knownEvents.propertyChange, (data) => { + testView.style.on(observable.Observable.propertyChangeEvent, (data) => { changed = true; }); @@ -191,7 +191,7 @@ export function test_setting_different_color_triggers_property_change() { testView.style.color = new color.Color("#FF0000"); var changed = false; - testView.style.on(observable.knownEvents.propertyChange, (data) => { + testView.style.on(observable.Observable.propertyChangeEvent, (data) => { changed = true; }); @@ -204,7 +204,7 @@ export function test_setting_same_backgroundColor_does_not_trigger_property_chan testView.style.backgroundColor = new color.Color("#FF0000"); var changed = false; - testView.style.on(observable.knownEvents.propertyChange, (data) => { + testView.style.on(observable.Observable.propertyChangeEvent, (data) => { changed = true; }); @@ -217,7 +217,7 @@ export function test_setting_different_backgroundColor_triggers_property_change( testView.style.backgroundColor = new color.Color("#FF0000"); var changed = false; - testView.style.on(observable.knownEvents.propertyChange, (data) => { + testView.style.on(observable.Observable.propertyChangeEvent, (data) => { changed = true; }); diff --git a/apps/tests/ui/switch/switch-tests.ts b/apps/tests/ui/switch/switch-tests.ts index 1d8d1819e..efeb8ba71 100644 --- a/apps/tests/ui/switch/switch-tests.ts +++ b/apps/tests/ui/switch/switch-tests.ts @@ -81,7 +81,7 @@ export function test_set_native_checked_triggers_propertyChanged() { function testAction(views: Array) { var checkedChanged = false; var allChanges = 0; - mySwitch.on(observable.knownEvents.propertyChange, function (data: observable.EventData) { + mySwitch.on(observable.Observable.propertyChangeEvent, function (data: observable.EventData) { allChanges++; var propertyData = data; if (propertyData && propertyData.propertyName === "checked" && propertyData.value === true) { @@ -91,7 +91,7 @@ export function test_set_native_checked_triggers_propertyChanged() { setNativeValue(mySwitch, true); - mySwitch.off(observable.knownEvents.propertyChange); + mySwitch.off(observable.Observable.propertyChangeEvent); TKUnit.assert(checkedChanged, "Property changed for checked not called."); TKUnit.assertEqual(allChanges, 1, "Property changed callbacks."); diff --git a/apps/tests/ui/tab-view/tab-view-tests.ts b/apps/tests/ui/tab-view/tab-view-tests.ts index 5d06b2826..f33c34290 100644 --- a/apps/tests/ui/tab-view/tab-view-tests.ts +++ b/apps/tests/ui/tab-view/tab-view-tests.ts @@ -71,7 +71,7 @@ function _createListView(): listViewModule.ListView { listView.id = "ListView"; var items = Array.apply(null, Array(10)).map(function (_, i) { return i; }); - listView.on(listViewModule.knownEvents.itemLoading, function (args: listViewModule.ItemEventData) { + listView.on(listViewModule.ListView.itemLoadingEvent, function (args: listViewModule.ItemEventData) { var button = args.view; if (!button) { button = new buttonModule.Button(); @@ -80,7 +80,7 @@ function _createListView(): listViewModule.ListView { button.text = "Button" + args.index; button.id = button.text; - button.on(buttonModule.knownEvents.tap, _clickHandlerFactory(args.index)); + button.on(buttonModule.Button.tapEvent, _clickHandlerFactory(args.index)); }); listView.items = items; diff --git a/apps/tests/ui/view/view-tests-common.ts b/apps/tests/ui/view/view-tests-common.ts index 48130cab5..bed9c0501 100644 --- a/apps/tests/ui/view/view-tests-common.ts +++ b/apps/tests/ui/view/view-tests-common.ts @@ -123,18 +123,18 @@ export var test_event_LoadedUnloaded_IsRaised = function () { var layoutUnloaded = false, buttonUnloaded = false; - views[1].on(viewModule.knownEvents.unloaded, (data) => { + views[1].on(viewModule.View.unloadedEvent, (data) => { layoutUnloaded = true; }); - views[2].on(viewModule.knownEvents.unloaded, (data) => { + views[2].on(viewModule.View.unloadedEvent, (data) => { buttonUnloaded = true; }); var newButton = new button.Button(), buttonLoaded = false; - newButton.on(viewModule.knownEvents.loaded, (data) => { + newButton.on(viewModule.View.loadedEvent, (data) => { buttonLoaded = true; }); diff --git a/apps/tests/ui/web-view/web-view-tests.ts b/apps/tests/ui/web-view/web-view-tests.ts index ee597cf0d..bb861a7c6 100644 --- a/apps/tests/ui/web-view/web-view-tests.ts +++ b/apps/tests/ui/web-view/web-view-tests.ts @@ -46,7 +46,7 @@ export var testLoadExistingUrl = function () { // // ### Using WebView // ``` JavaScript - webView.on(webViewModule.knownEvents.loadFinished, function (args: webViewModule.LoadEventData) { + webView.on(webViewModule.WebView.loadFinishedEvent, function (args: webViewModule.LoadEventData) { // actualUrl = args.url; actualError = args.error; @@ -89,7 +89,7 @@ export var testLoadInvalidUrl = function () { var testFinished = false; var actualError; - webView.on(webViewModule.knownEvents.loadFinished, function (args: webViewModule.LoadEventData) { + webView.on(webViewModule.WebView.loadFinishedEvent, function (args: webViewModule.LoadEventData) { if (actualError) { // Android call this twice -- the second time args.error is undefined. return; diff --git a/apps/tests/virtual-array-tests.ts b/apps/tests/virtual-array-tests.ts index 6be877d5a..c583e033b 100644 --- a/apps/tests/virtual-array-tests.ts +++ b/apps/tests/virtual-array-tests.ts @@ -38,7 +38,7 @@ export var test_VirtualArray_setItemShouldRaiseChangeEventWhenYouSetDifferentIte var result: virtualArrayModule.ChangedData; var index = 0; - array.on(virtualArrayModule.knownEvents.change, (args: virtualArrayModule.ChangedData) => { + array.on(virtualArrayModule.VirtualArray.changeEvent, (args: virtualArrayModule.ChangedData) => { result = args; }); @@ -55,7 +55,7 @@ export var test_VirtualArray_setItemShouldRaiseChangeEventWhenYouSetDifferentIte result.removed.length === 1 && result.index === index && result.addedCount === 1, "VirtualArray setItem() should raise 'change' event with correct args!"); // - array.on(virtualArrayModule.knownEvents.itemsLoading, (args: virtualArrayModule.ItemsLoading) => { + array.on(virtualArrayModule.VirtualArray.itemsLoadingEvent, (args: virtualArrayModule.ItemsLoading) => { //// Argument (args) is ItemsLoading. //// args.index is start index of the page where the requested index is located. //// args.count number of requested items. @@ -90,7 +90,7 @@ export var test_VirtualArray_loadShouldRaiseChangeEventWithCorrectArgs = functio var index = 0; // - array.on(virtualArrayModule.knownEvents.change, (args: virtualArrayModule.ChangedData) => { + array.on(virtualArrayModule.VirtualArray.changeEvent, (args: virtualArrayModule.ChangedData) => { //// Argument (args) is ChangedData. //// args.eventName is "change". //// args.action is "update". @@ -124,7 +124,7 @@ export var test_VirtualArray_lengthIncreaseShouldRaiseChangeEventWithCorrectArgs var index = array.length; // - array.on(virtualArrayModule.knownEvents.change, (args: virtualArrayModule.ChangedData) => { + array.on(virtualArrayModule.VirtualArray.changeEvent, (args: virtualArrayModule.ChangedData) => { //// Argument (args) is ChangedData. //// args.eventName is "change". //// args.action is "add". @@ -156,7 +156,7 @@ export var test_VirtualArray_lengthDecreaseShouldRaiseChangeEventWithCorrectArgs var index = array.length; // - array.on(virtualArrayModule.knownEvents.change, (args: virtualArrayModule.ChangedData) => { + array.on(virtualArrayModule.VirtualArray.changeEvent, (args: virtualArrayModule.ChangedData) => { //// Argument (args) is ChangedData. //// args.eventName is "change". //// args.action is "remove". @@ -180,13 +180,13 @@ export var test_VirtualArray_shouldRaiseItemsLoadingIfIndexIsNotLoadedAndGetItem var result: virtualArrayModule.ItemsLoading; - array.on(virtualArrayModule.knownEvents.itemsLoading, (args: virtualArrayModule.ItemsLoading) => { + array.on(virtualArrayModule.VirtualArray.itemsLoadingEvent, (args: virtualArrayModule.ItemsLoading) => { result = args; }); array.getItem(0); - TKUnit.assert(result.eventName === virtualArrayModule.knownEvents.itemsLoading && result.index === 0 && + TKUnit.assert(result.eventName === virtualArrayModule.VirtualArray.itemsLoadingEvent && result.index === 0 && result.count === array.loadSize, "VirtualArray getItem() should raise 'itemsLoading' event with correct args if item is not loaded!"); }; @@ -197,7 +197,7 @@ export var test_VirtualArray_shouldNotRaiseItemsLoadingIfIndexIsLoadedAndGetItem var result: virtualArrayModule.ItemsLoading; - array.on(virtualArrayModule.knownEvents.itemsLoading, (args: virtualArrayModule.ItemsLoading) => { + array.on(virtualArrayModule.VirtualArray.itemsLoadingEvent, (args: virtualArrayModule.ItemsLoading) => { result = args; }); @@ -216,14 +216,14 @@ export var test_VirtualArray_shouldRaiseItemsLoadingIfIndexIsNotLoadedAndGetItem var result = new Array(); - array.on(virtualArrayModule.knownEvents.itemsLoading, (args: virtualArrayModule.ItemsLoading) => { + array.on(virtualArrayModule.VirtualArray.itemsLoadingEvent, (args: virtualArrayModule.ItemsLoading) => { result.push(args); }); array.getItem(1); TKUnit.assert(result.length === 2 && - result[0].eventName === virtualArrayModule.knownEvents.itemsLoading && result[0].index === 1 && result[0].count === 4 && - result[1].eventName === virtualArrayModule.knownEvents.itemsLoading && result[1].index === 6 && result[1].count === 9, + result[0].eventName === virtualArrayModule.VirtualArray.itemsLoadingEvent && result[0].index === 1 && result[0].count === 4 && + result[1].eventName === virtualArrayModule.VirtualArray.itemsLoadingEvent && result[1].index === 6 && result[1].count === 9, "VirtualArray getItem() should raise 'itemsLoading' event with correct args!"); }; diff --git a/apps/tests/xml-declaration/mymodule/MyControl.ts b/apps/tests/xml-declaration/mymodule/MyControl.ts index 8bdb33d61..53ba3b697 100644 --- a/apps/tests/xml-declaration/mymodule/MyControl.ts +++ b/apps/tests/xml-declaration/mymodule/MyControl.ts @@ -12,7 +12,7 @@ export class MyControl extends stackLayoutModule.StackLayout { var lbl = new label.Label(); var btn = new button.Button(); btn.text = "Tap me!"; - btn.on(button.knownEvents.tap, (args: observable.EventData) => { + btn.on(button.Button.tapEvent, (args: observable.EventData) => { lbl.text = "Tap " + counter++; }); diff --git a/apps/ui-tests-app/mainPage.ts b/apps/ui-tests-app/mainPage.ts index b267d7a2a..7c228e5c8 100644 --- a/apps/ui-tests-app/mainPage.ts +++ b/apps/ui-tests-app/mainPage.ts @@ -15,7 +15,7 @@ export function createPage() { var btn = new button.Button(); btn.text = "Run"; - btn.on(button.knownEvents.tap, function () { + btn.on(button.Button.tapEvent, function () { var pagePath = basePath + txtInput.text; var fileName = fs.path.join(__dirname, "pages", txtInput.text); diff --git a/apps/ui-tests-app/pages/gestures.ts b/apps/ui-tests-app/pages/gestures.ts index 47c1cb334..2907d95d0 100644 --- a/apps/ui-tests-app/pages/gestures.ts +++ b/apps/ui-tests-app/pages/gestures.ts @@ -45,7 +45,7 @@ export function createPage() { rotaionLabel.text = "Rotate here"; stack.addChild(rotaionLabel); - stopButton.on(button.knownEvents.tap, function () { + stopButton.on(button.Button.tapEvent, function () { observer1.disconnect(); observer2.disconnect(); observer3.disconnect(); diff --git a/apps/ui-tests-app/pages/i73.ts b/apps/ui-tests-app/pages/i73.ts index 98fb0e929..19a4647f7 100644 --- a/apps/ui-tests-app/pages/i73.ts +++ b/apps/ui-tests-app/pages/i73.ts @@ -8,7 +8,7 @@ export function createPage() { var btn = new button.Button(); btn.text = "Alert"; - btn.on(button.knownEvents.tap, function () { + btn.on(button.Button.tapEvent, function () { alert("Alert is global"); }); diff --git a/apps/web-view-demo/model.ts b/apps/web-view-demo/model.ts index 591908d8e..996d09a70 100644 --- a/apps/web-view-demo/model.ts +++ b/apps/web-view-demo/model.ts @@ -16,7 +16,7 @@ export class WebViewModel extends observable.Observable { } set url(value: string) { this._url = value; - this.notify({ object: this, eventName: observable.knownEvents.propertyChange, propertyName: "url", value: value }); + this.notify({ object: this, eventName: observable.Observable.propertyChangeEvent, propertyName: "url", value: value }); } //private _text: string; @@ -25,7 +25,7 @@ export class WebViewModel extends observable.Observable { //} //set text(value: string) { // this._text = value; - // this.notify({ object: this, eventName: observable.knownEvents.propertyChange, propertyName: "text", value: value }); + // this.notify({ object: this, eventName: observable.Observable.propertyChangeEvent, propertyName: "text", value: value }); // if (application.ios) { // this.url = this.text; diff --git a/apps/xml-demo/mainPage.ts b/apps/xml-demo/mainPage.ts index ddcf776de..11d763e2d 100644 --- a/apps/xml-demo/mainPage.ts +++ b/apps/xml-demo/mainPage.ts @@ -18,7 +18,7 @@ export function createPage() { }; var button = new bm.Button(); - button.on(bm.knownEvents.tap, function () { + button.on(bm.Button.tapEvent, function () { fs.File.fromPath(__dirname + "/xml.xml").readText().then(input => { // I am a change made in master. console.log("EasySax JavaScript XmlParser (without namespace processing) running..."); diff --git a/data/observable-array/observable-array.d.ts b/data/observable-array/observable-array.d.ts index aaf200d81..86820886f 100644 --- a/data/observable-array/observable-array.d.ts +++ b/data/observable-array/observable-array.d.ts @@ -6,13 +6,6 @@ declare module "data/observable-array" { import observable = require("data/observable"); - /** - * Known event names. - */ - module knownEvents { - export var change: string; - } - /** * Event args for "changed" event. */ @@ -52,12 +45,23 @@ declare module "data/observable-array" { * Advanced array like class used when you want to be notified when a change occurs. */ class ObservableArray extends observable.Observable { - on(event: string, callback: (data: observable.EventData) => void); + /** + * String value used when hooking to change event. + */ + public static changeEvent: string; + + /** + * 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 change occurs. */ - on(event: "change", callback: (args: ChangedData) => void); + on(event: "change", callback: (args: ChangedData) => void, thisArg?: any); /** * Create ObservableArray with specified length. diff --git a/data/observable-array/observable-array.ts b/data/observable-array/observable-array.ts index 1bed9ea06..babdbd849 100644 --- a/data/observable-array/observable-array.ts +++ b/data/observable-array/observable-array.ts @@ -10,13 +10,9 @@ export class ChangeType implements observableArrayDef.ChangeType { var CHANGE = "change"; -export module knownEvents { - export var change = CHANGE; -} - export class ObservableArray extends observable.Observable implements observableArrayDef.ObservableArray { // implements Array { - //[n: number]: T; + public static changeEvent = CHANGE; private _array: Array; private _addArgs: observableArrayDef.ChangedData; diff --git a/data/observable/observable.d.ts b/data/observable/observable.d.ts index aec400c75..45c2c33e0 100644 --- a/data/observable/observable.d.ts +++ b/data/observable/observable.d.ts @@ -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. diff --git a/data/observable/observable.ts b/data/observable/observable.ts index e9da614e6..f63cb76e6 100644 --- a/data/observable/observable.ts +++ b/data/observable/observable.ts @@ -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 diff --git a/data/virtual-array/virtual-array.d.ts b/data/virtual-array/virtual-array.d.ts index 79fe1453e..92e032212 100644 --- a/data/virtual-array/virtual-array.d.ts +++ b/data/virtual-array/virtual-array.d.ts @@ -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 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) => void); + on(event: "change", callback: (args: ChangedData) => void, thisArg?: any); } /** diff --git a/data/virtual-array/virtual-array.ts b/data/virtual-array/virtual-array.ts index 5c85a51f5..b69660c32 100644 --- a/data/virtual-array/virtual-array.ts +++ b/data/virtual-array/virtual-array.ts @@ -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 extends observable.Observable { + public static changeEvent = CHANGE; + public static itemsLoadingEvent = "itemsLoading"; + private _requestedIndexes: Array; private _loadedIndexes: Array; private _length: number; @@ -139,7 +137,7 @@ export class VirtualArray 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 extends observable.Observable { if (start >= 0 && count > 0) { this.notify({ - eventName: knownEvents.itemsLoading, object: this, + eventName: VirtualArray.itemsLoadingEvent, object: this, index: start, count: count }); diff --git a/text/formatted-string-common.ts b/text/formatted-string-common.ts index c57ecf861..f185e0482 100644 --- a/text/formatted-string-common.ts +++ b/text/formatted-string-common.ts @@ -138,7 +138,7 @@ export class FormattedString extends observable.Observable implements definition constructor() { super(); this._spans = new observableArray.ObservableArray(); - this._spans.addEventListener(observableArray.knownEvents.change, this.onSpansCollectionChanged, this); + this._spans.addEventListener(observableArray.ObservableArray.changeEvent, this.onSpansCollectionChanged, this); this._isDirty = true; } @@ -155,14 +155,14 @@ export class FormattedString extends observable.Observable implements definition for (i = 0; i < eventData.addedCount; i++) { var addedSpan: spanModule.Span = (>eventData.object).getItem(eventData.index + i); addedSpan.parentFormattedString = this; - addedSpan.addEventListener(observable.knownEvents.propertyChange, this.onSpanChanged, this); + addedSpan.addEventListener(observable.Observable.propertyChangeEvent, this.onSpanChanged, this); } } if (eventData.removed && eventData.removed.length > 0) { var p; for (p = 0; p < eventData.removed.length; p++) { var removedSpan = eventData.removed[p]; - removedSpan.removeEventListener(observable.knownEvents.propertyChange, this.onSpanChanged, this); + removedSpan.removeEventListener(observable.Observable.propertyChangeEvent, this.onSpanChanged, this); } } this.updateFormattedText(true); diff --git a/ui/builder/component-builder.ts b/ui/builder/component-builder.ts index 90abe69b2..b6d189b74 100644 --- a/ui/builder/component-builder.ts +++ b/ui/builder/component-builder.ts @@ -10,7 +10,7 @@ import fs = require("file-system"); import gestures = require("ui/gestures"); import bindingBuilder = require("ui/builder/binding-builder"); -var KNOWNEVENTS = "knownEvents"; +var EVENT = "Event"; var UI_PATH = "ui/"; var MODULES = { "ActivityIndicator": "ui/activity-indicator", @@ -104,7 +104,7 @@ export function getComponentModule(elementName: string, namespace: string, attri export function setPropertyValue(instance: view.View, instanceModule: Object, exports: Object, propertyName: string, propertyValue: string) { if (isBinding(propertyValue) && instance.bind) { - if (isKnownEvent(propertyName, instanceModule)) { + if (isKnownEvent(propertyName, instanceModule[instance.typeName])) { attachEventBinding(instance, propertyName, propertyValue); } else { var bindOptions = bindingBuilder.getBindingOptions(propertyName, getBindingExpressionFromAttribute(propertyValue)); @@ -115,7 +115,7 @@ export function setPropertyValue(instance: view.View, instanceModule: Object, ex twoWay: bindOptions[bindingBuilder.bindingConstants.twoWay] }, bindOptions[bindingBuilder.bindingConstants.source]); } - } else if (isKnownEvent(propertyName, instanceModule)) { + } else if (isKnownEvent(propertyName, instanceModule[instance.typeName])) { // Get the event handler from page module exports. var handler = exports && exports[propertyValue]; @@ -175,11 +175,11 @@ function attachEventBinding(instance: view.View, eventName: string, value: strin if (types.isFunction(handler)) { instance.on(eventName, handler, instance.bindingContext); } - instance.off(observable.knownEvents.propertyChange, propertyChangeHandler); + instance.off(observable.Observable.propertyChangeEvent, propertyChangeHandler); } }; - instance.on(observable.knownEvents.propertyChange, propertyChangeHandler); + instance.on(observable.Observable.propertyChangeEvent, propertyChangeHandler); } function isGesture(name: string, instance: any): boolean { @@ -187,8 +187,9 @@ function isGesture(name: string, instance: any): boolean { } function isKnownEvent(name: string, exports: any): boolean { - return (KNOWNEVENTS in exports && name in exports[KNOWNEVENTS]) || - (KNOWNEVENTS in view && name in view[KNOWNEVENTS]); + var nameEvent = name + EVENT; + var result = !types.isNullOrUndefined(exports) ? nameEvent in exports : false; + return result; } function getBindingExpressionFromAttribute(value: string): string { diff --git a/ui/button/button-common.ts b/ui/button/button-common.ts index 4c4cf291d..222ba14ed 100644 --- a/ui/button/button-common.ts +++ b/ui/button/button-common.ts @@ -6,9 +6,6 @@ import formattedString = require("text/formatted-string"); import observable = require("data/observable"); import weakEventListener = require("ui/core/weak-event-listener"); -export module knownEvents { - export var tap = "tap"; -} var textProperty = new dependencyObservable.Property( "text", "Button", @@ -37,6 +34,8 @@ function onFormattedTextPropertyChanged(data: dependencyObservable.PropertyChang export class Button extends view.View implements definition.Button { + public static tapEvent = "tap"; + public static textProperty = textProperty; public static formattedTextProperty = formattedTextProperty; @@ -63,7 +62,7 @@ export class Button extends view.View implements definition.Button { if (this.formattedText !== value) { var weakEventOptions: weakEventListener.WeakEventListenerOptions = { targetWeakRef: new WeakRef(this), - eventName: observable.knownEvents.propertyChange, + eventName: observable.Observable.propertyChangeEvent, sourceWeakRef: new WeakRef(value), handler: this.onFormattedTextChanged, handlerContext: this, diff --git a/ui/button/button.android.ts b/ui/button/button.android.ts index 71f65abcf..1ab30e586 100644 --- a/ui/button/button.android.ts +++ b/ui/button/button.android.ts @@ -33,7 +33,7 @@ export class Button extends common.Button { onClick: function (v) { if (this.owner) { - this.owner._emit(common.knownEvents.tap); + this.owner._emit(common.Button.tapEvent); } } })); diff --git a/ui/button/button.d.ts b/ui/button/button.d.ts index 32d2d5fae..82763f106 100644 --- a/ui/button/button.d.ts +++ b/ui/button/button.d.ts @@ -7,13 +7,6 @@ declare module "ui/button" { import view = require("ui/core/view"); import formattedString = require("text/formatted-string"); - /** - * Known event names. - */ - export module knownEvents { - export var tap: string; - } - /** * Represents a standard Button widget. */ @@ -23,6 +16,11 @@ declare module "ui/button" { */ public static textProperty: dependencyObservable.Property; + /** + * String value used when hooking to tap event. + */ + public static tapEvent: string; + /** * Gets the native [android widget](http://developer.android.com/reference/android/widget/Button.html) that represents the user interface for this component. Valid only when running on Android OS. */ @@ -43,7 +41,17 @@ declare module "ui/button" { */ formattedText: formattedString.FormattedString; - on(event: string, callback: (data: observable.EventData) => void); - on(event: "tap", callback: (args: 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 a tap event occurs. + */ + on(event: "tap", callback: (args: observable.EventData) => void, thisArg?: any); } } \ No newline at end of file diff --git a/ui/button/button.ios.ts b/ui/button/button.ios.ts index e0d8df868..980f094c1 100644 --- a/ui/button/button.ios.ts +++ b/ui/button/button.ios.ts @@ -14,7 +14,7 @@ class TapHandlerImpl extends NSObject { } public tap(args) { - this._owner._emit(common.knownEvents.tap); + this._owner._emit(common.Button.tapEvent); } public static ObjCExposedMethods = { diff --git a/ui/core/bindable.ts b/ui/core/bindable.ts index 58bb9cb84..894608083 100644 --- a/ui/core/bindable.ts +++ b/ui/core/bindable.ts @@ -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 diff --git a/ui/core/dependency-observable.ts b/ui/core/dependency-observable.ts index 16f09bf30..dbd301aa1 100644 --- a/ui/core/dependency-observable.ts +++ b/ui/core/dependency-observable.ts @@ -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); } diff --git a/ui/core/proxy.ts b/ui/core/proxy.ts index 3410d1bf3..401b23459 100644 --- a/ui/core/proxy.ts +++ b/ui/core/proxy.ts @@ -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 }); diff --git a/ui/core/view-common.ts b/ui/core/view-common.ts index eb8daf405..87b778088 100644 --- a/ui/core/view-common.ts +++ b/ui/core/view-common.ts @@ -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; diff --git a/ui/core/view.d.ts b/ui/core/view.d.ts index c4995e081..85f00d75c 100644 --- a/ui/core/view.d.ts +++ b/ui/core/view.d.ts @@ -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; diff --git a/ui/frame/frame-common.ts b/ui/frame/frame-common.ts index cf448ef3f..9e08bdca4 100644 --- a/ui/frame/frame-common.ts +++ b/ui/frame/frame-common.ts @@ -110,18 +110,14 @@ function pageFromBuilder(moduleNamePath: string, moduleExports: any): pages.Page return page; } -export module knownEvents { - export module android { - export var optionSelected = "optionSelected"; - } -} - interface NavigationContext { entry: definition.BackstackEntry; isBackNavigation: boolean; } export class Frame extends view.CustomLayoutView implements definition.Frame { + public static androidOptionSelectedEvent = "optionSelected"; + private _navigationQueue: Array; private _backStack: Array; public _currentEntry: definition.BackstackEntry; diff --git a/ui/frame/frame.android.ts b/ui/frame/frame.android.ts index 6f8f62468..d223d0d99 100644 --- a/ui/frame/frame.android.ts +++ b/ui/frame/frame.android.ts @@ -481,13 +481,13 @@ class NativeActivity extends com.tns.NativeScriptActivity { } onOptionsItemSelected(menuItem: android.view.IMenuItem) { - if (!this.androidFrame.hasListeners(frameCommon.knownEvents.android.optionSelected)) { + if (!this.androidFrame.hasListeners(frameCommon.Frame.androidOptionSelectedEvent)) { return false; } var data: definition.AndroidOptionEventData = { handled: false, - eventName: frameCommon.knownEvents.android.optionSelected, + eventName: frameCommon.Frame.androidOptionSelectedEvent, item: menuItem, object: this.androidFrame } diff --git a/ui/frame/frame.d.ts b/ui/frame/frame.d.ts index 9ddf69a6f..436981d5d 100644 --- a/ui/frame/frame.d.ts +++ b/ui/frame/frame.d.ts @@ -12,6 +12,11 @@ declare module "ui/frame" { * Nested frames are supported, enabling hierarchical navigation scenarios. */ export class Frame extends view.View { + /** + * String value used when hooking to androidOptionSelected event (prefix `android` states that this event is available only in Android). + */ + public static androidOptionSelectedEvent: string; + /** * Navigates to the previous entry (if any) in the back stack. */ @@ -86,6 +91,19 @@ declare module "ui/frame" { _processNavigationQueue(page: pages.Page); _invalidateOptionsMenu(); //@endprivate + + /** + * 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: (args: observable.EventData) => void, thisArg?: any); + + /** + * Raised when native android [onOptionsItemSelected method](http://developer.android.com/reference/android/app/Activity.html#onOptionsItemSelected(android.view.MenuItem)) is called. + */ + on(event: "optionSelected", callback: (args: observable.EventData) => void, thisArg?: any); } /** @@ -214,19 +232,4 @@ declare module "ui/frame" { */ navBarVisibility: string; } - - /** - * Encapsulates the events raised by the Frame object. - */ - module knownEvents { - /** - * Encapsulates the events raised by the android part of the Frame. - */ - module android { - /** - * Raised when the native [onOptionsItemSelected method](http://developer.android.com/reference/android/app/Activity.html#onOptionsItemSelected(android.view.MenuItem)) is called. - */ - export var optionSelected: string; - } - } } \ No newline at end of file diff --git a/ui/gestures/gestures.android.ts b/ui/gestures/gestures.android.ts index 3d2fdc28c..587c81f4b 100644 --- a/ui/gestures/gestures.android.ts +++ b/ui/gestures/gestures.android.ts @@ -44,8 +44,8 @@ export class GesturesObserver implements definition.GesturesObserver { this._dettach(); }; - target.on(view.knownEvents.loaded, this._onTargetLoaded); - target.on(view.knownEvents.unloaded, this._onTargetUnloaded); + target.on(view.View.loadedEvent, this._onTargetLoaded); + target.on(view.View.unloadedEvent, this._onTargetUnloaded); if (target.isLoaded) { this._attach(target, type); @@ -57,8 +57,8 @@ export class GesturesObserver implements definition.GesturesObserver { this._dettach(); if (this._target) { - this._target.off(view.knownEvents.loaded, this._onTargetLoaded); - this._target.off(view.knownEvents.unloaded, this._onTargetUnloaded); + this._target.off(view.View.loadedEvent, this._onTargetLoaded); + this._target.off(view.View.unloadedEvent, this._onTargetUnloaded); this._onTargetLoaded = null; this._onTargetUnloaded = null; diff --git a/ui/gestures/gestures.ios.ts b/ui/gestures/gestures.ios.ts index 9b2db4a88..ca4b7a872 100644 --- a/ui/gestures/gestures.ios.ts +++ b/ui/gestures/gestures.ios.ts @@ -74,8 +74,8 @@ export class GesturesObserver implements definition.GesturesObserver { this._dettach(); }; - target.on(view.knownEvents.loaded, this._onTargetLoaded); - target.on(view.knownEvents.unloaded, this._onTargetUnloaded); + target.on(view.View.loadedEvent, this._onTargetLoaded); + target.on(view.View.unloadedEvent, this._onTargetUnloaded); if (target.isLoaded) { this._attach(target, type); @@ -164,8 +164,8 @@ export class GesturesObserver implements definition.GesturesObserver { this._dettach(); if (this._target) { - this._target.off(view.knownEvents.loaded, this._onTargetLoaded); - this._target.off(view.knownEvents.unloaded, this._onTargetUnloaded); + this._target.off(view.View.loadedEvent, this._onTargetLoaded); + this._target.off(view.View.unloadedEvent, this._onTargetUnloaded); this._onTargetLoaded = null; this._onTargetUnloaded = null; diff --git a/ui/image-cache/image-cache-common.ts b/ui/image-cache/image-cache-common.ts index 45ba2414b..ac907b5ee 100644 --- a/ui/image-cache/image-cache-common.ts +++ b/ui/image-cache/image-cache-common.ts @@ -2,10 +2,6 @@ import observable = require("data/observable"); import imageSource = require("image-source"); -export module knownEvents { - export var downloaded = "downloaded"; -} - export interface DownloadRequest { url: string; key: string; @@ -13,6 +9,8 @@ export interface DownloadRequest { } export class Cache extends observable.Observable implements definition.Cache { + public static downloadedEvent = "downloaded"; + public placeholder: imageSource.ImageSource; public maxRequests = 5; private _enabled = true; @@ -135,9 +133,9 @@ export class Cache extends observable.Observable implements definition.Cache { request.completed(image, request.key); } - if (this.hasListeners(knownEvents.downloaded)) { + if (this.hasListeners(Cache.downloadedEvent)) { this.notify({ - eventName: knownEvents.downloaded, + eventName: Cache.downloadedEvent, object: this, key: key, image: image diff --git a/ui/image-cache/image-cache.android.ts b/ui/image-cache/image-cache.android.ts index 58680e723..3fe96444d 100644 --- a/ui/image-cache/image-cache.android.ts +++ b/ui/image-cache/image-cache.android.ts @@ -1,7 +1,5 @@ import common = require("ui/image-cache/image-cache-common"); -module.exports.knownEvents = common.knownEvents; - class LruBitmapCache extends android.util.LruCache { constructor(cacheSize: number) { super(cacheSize); diff --git a/ui/image-cache/image-cache.d.ts b/ui/image-cache/image-cache.d.ts index 0ed9bff65..14dc599da 100644 --- a/ui/image-cache/image-cache.d.ts +++ b/ui/image-cache/image-cache.d.ts @@ -27,6 +27,10 @@ declare module "ui/image-cache" { * Represents a class that stores handles image download requests and caches the already downloaded images. */ export class Cache extends observable.Observable { + /** + * String value used when hooking to downloaded event. + */ + public static downloadedEvent: string; /** * The image to be used to notify for a pending download request - e.g. loading indicator. */ @@ -71,22 +75,25 @@ declare module "ui/image-cache" { */ clear(): 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: (args: observable.EventData) => void , thisArg?: any); + + /** + * Raised when the image has been downloaded. + */ + on(event: "downloaded", callback: (args: DownloadedData) => void , thisArg?: any); + //@private _downloadCore(request: DownloadRequest); _onDownloadCompleted(key: string, image: any); //@endprivate } - /** - * Defines an enum with events specific for image-cache class. - */ - export module knownEvents { - /** - * Raised when the image has been downloaded. - */ - export var downloaded: string; - } - /** * Provides data for downloaded event. */ diff --git a/ui/image-cache/image-cache.ios.ts b/ui/image-cache/image-cache.ios.ts index c7ffefbbc..76de2792d 100644 --- a/ui/image-cache/image-cache.ios.ts +++ b/ui/image-cache/image-cache.ios.ts @@ -3,8 +3,6 @@ import httpRequest = require("http/http-request"); import utils = require("utils/utils"); import trace = require("trace"); -module.exports.knownEvents = common.knownEvents; - //class NSCacheDelegateImpl extends NSObject implements NSCacheDelegate { // public static ObjCProtocols = [NSCacheDelegate]; diff --git a/ui/list-view/Readme.md b/ui/list-view/Readme.md index e9568a7a8..0e404479b 100644 --- a/ui/list-view/Readme.md +++ b/ui/list-view/Readme.md @@ -10,7 +10,7 @@ var lv = new lvm.ListView(); lv.items = data; - lv.on(lvm.knownEvents.itemLoading, function(args){ + lv.on(lvm.ListView.itemLoadingEvent, function(args){ var label = args.view; if(!label) { label = new lm.Label(); diff --git a/ui/list-view/list-view-common.ts b/ui/list-view/list-view-common.ts index 0f73eb403..7700f03e9 100644 --- a/ui/list-view/list-view-common.ts +++ b/ui/list-view/list-view-common.ts @@ -15,12 +15,6 @@ var ITEMSCHANGED = "_itemsChanged"; var CHANGE = "change"; var SEPARATORCOLOR = "separatorColor"; -export module knownEvents { - export var itemLoading = "itemLoading"; - export var itemTap = "itemTap"; - export var loadMoreItems = "loadMoreItems"; -} - export module knownTemplates { export var itemTemplate = "itemTemplate"; } @@ -46,6 +40,9 @@ function onItemTemplatePropertyChanged(data: dependencyObservable.PropertyChange } export class ListView extends view.View implements definition.ListView { + public static itemLoadingEvent = "itemLoading"; + public static itemTapEvent = "itemTap"; + public static loadMoreItemsEvent = "loadMoreItems"; public static separatorColorProperty = new dependencyObservable.Property( SEPARATORCOLOR, diff --git a/ui/list-view/list-view.android.ts b/ui/list-view/list-view.android.ts index e60b6affd..3f215b4bd 100644 --- a/ui/list-view/list-view.android.ts +++ b/ui/list-view/list-view.android.ts @@ -7,9 +7,9 @@ import proxy = require("ui/core/proxy"); import dependencyObservable = require("ui/core/dependency-observable"); import color = require("color"); -var ITEMLOADING = common.knownEvents.itemLoading; -var LOADMOREITEMS = common.knownEvents.loadMoreItems; -var ITEMTAP = common.knownEvents.itemTap; +var ITEMLOADING = common.ListView.itemLoadingEvent; +var LOADMOREITEMS = common.ListView.loadMoreItemsEvent; +var ITEMTAP = common.ListView.itemTapEvent; var REALIZED_INDEX = "realizedIndex"; // merge the exports of the common file with the exports of this file diff --git a/ui/list-view/list-view.d.ts b/ui/list-view/list-view.d.ts index c66a56be8..393dd0894 100644 --- a/ui/list-view/list-view.d.ts +++ b/ui/list-view/list-view.d.ts @@ -7,26 +7,6 @@ declare module "ui/list-view" { import view = require("ui/core/view"); import color = require("color"); - /** - * Known event names. - */ - export module knownEvents { - /** - * The name of event raised when item is loading inside the ListView. - */ - export var itemLoading: string; - - /** - * The name of event raised when ListView item is tapped. - */ - export var itemTap: string; - - /** - * The name of event raised when the ListView is scrolled so that its last item is visible. - */ - export var loadMoreItems: string; - } - /** * Known template names. */ @@ -41,6 +21,19 @@ declare module "ui/list-view" { * Represents a view that shows items in a vertically scrolling list. */ export class ListView extends view.View { + /** + * String value used when hooking to itemLoading event. + */ + public static itemLoadingEvent: string; + /** + * String value used when hooking to itemTap event. + */ + public static itemTapEvent: string; + /** + * String value used when hooking to loadMoreItems event. + */ + public static loadMoreItemsEvent: string; + /** * Represents the observable property backing the items property of each ListView instance. */ @@ -92,7 +85,13 @@ declare module "ui/list-view" { */ refresh(); - 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 a View for the data at the specified index should be created. @@ -100,17 +99,17 @@ declare module "ui/list-view" { * Note, that the view property of the event data can be pre-initialized with * an old instance of a view, so that it can be reused. */ - on(event: "itemLoading", callback: (args: ItemEventData) => void); + on(event: "itemLoading", callback: (args: ItemEventData) => void, thisArg?: any); /** * Raised when an item inside the ListView is tapped. */ - on(event: "itemTap", callback: (args: ItemEventData) => void); + on(event: "itemTap", callback: (args: ItemEventData) => void, thisArg?: any); /** * Raised when the ListView is scrolled so that its last item is visible. */ - on(event: "loadMoreItems", callback: (args: observable.EventData) => void); + on(event: "loadMoreItems", callback: (args: observable.EventData) => void, thisArg?: any); } /** diff --git a/ui/list-view/list-view.ios.ts b/ui/list-view/list-view.ios.ts index 4d022cc28..ec73bd716 100644 --- a/ui/list-view/list-view.ios.ts +++ b/ui/list-view/list-view.ios.ts @@ -8,9 +8,9 @@ import dependencyObservable = require("ui/core/dependency-observable"); import color = require("color"); var CELLIDENTIFIER = "cell"; -var ITEMLOADING = common.knownEvents.itemLoading; -var LOADMOREITEMS = common.knownEvents.loadMoreItems; -var ITEMTAP = common.knownEvents.itemTap; +var ITEMLOADING = common.ListView.itemLoadingEvent; +var LOADMOREITEMS = common.ListView.loadMoreItemsEvent; +var ITEMTAP = common.ListView.itemTapEvent; var DEFAULT_HEIGHT = 80; // merge the exports of the common file with the exports of this file diff --git a/ui/page/page-common.ts b/ui/page/page-common.ts index 63ca4f54f..94564cdd8 100644 --- a/ui/page/page-common.ts +++ b/ui/page/page-common.ts @@ -11,16 +11,13 @@ import enums = require("ui/enums"); var OPTIONS_MENU = "optionsMenu"; -export module knownEvents { - export var navigatedTo = "navigatedTo"; - export var tap = "tap"; -} - export module knownCollections { export var optionsMenu = "optionsMenu"; } export class Page extends contentView.ContentView implements dts.Page, view.AddArrayFromBuilder { + public static navigatedToEvent = "navigatedTo"; + private _navigationContext: any; private _cssApplied: boolean; @@ -102,7 +99,7 @@ export class Page extends contentView.ContentView implements dts.Page, view.AddA public onNavigatedTo(context: any) { this._navigationContext = context; this.notify({ - eventName: knownEvents.navigatedTo, + eventName: Page.navigatedToEvent, object: this, context: context }); @@ -227,6 +224,7 @@ export class OptionsMenu implements dts.OptionsMenu { } export class MenuItem extends bindable.Bindable implements dts.MenuItem { + public static tapEvent = "tap"; public static textProperty = new dependencyObservable.Property( "text", "MenuItem", new dependencyObservable.PropertyMetadata("", null, MenuItem.onItemChanged)); @@ -271,7 +269,7 @@ export class MenuItem extends bindable.Bindable implements dts.MenuItem { } public _raiseTap() { - this._emit(knownEvents.tap); + this._emit(MenuItem.tapEvent); } menu: OptionsMenu; diff --git a/ui/page/page.d.ts b/ui/page/page.d.ts index 92f273c04..9458e688d 100644 --- a/ui/page/page.d.ts +++ b/ui/page/page.d.ts @@ -23,16 +23,6 @@ declare module "ui/page" { context: any; } - /** - * Encapsulates the known event names for the page module. - */ - export module knownEvents { - /** - * The event raised when the Page.onNavigatedTo method is called. - */ - export var navigatedTo: string; - } - export module knownCollections { export var optionsMenu: string; } @@ -41,6 +31,10 @@ declare module "ui/page" { * Represents a logical unit for navigation (inside Frame). */ export class Page extends contentView.ContentView implements view.AddArrayFromBuilder { + /** + * String value used when hooking to navigatedTo event. + */ + public static navigatedToEvent: string; constructor(options?: Options) @@ -100,14 +94,17 @@ declare module "ui/page" { onNavigatedFrom(isBackNavigation: boolean): void; /** - * Raised when navigation to the page is finished. + * 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(event: string, callback: (data: observable.EventData) => void); + on(eventNames: string, callback: (data: observable.EventData) => void, thisArg?: any); /** * Raised when navigation to the page is finished. */ - on(event: "navigatedTo", callback: (args: NavigatedData) => void); + on(event: "navigatedTo", callback: (args: NavigatedData) => void, thisArg?: any); _addArrayFromBuilder(name: string, value: Array): void; @@ -144,6 +141,10 @@ declare module "ui/page" { } export class MenuItem extends bindable.Bindable { + /** + * String value used when hooking to tap event. + */ + public static tapEvent: string; /** * Represents the observable property backing the text property. @@ -158,7 +159,18 @@ declare module "ui/page" { text: string; icon: string; android: AndroidMenuItemOptions; - 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); + + /** + * Raised when a tap event occurs. + */ on(event: "tap", callback: (args: observable.EventData) => void); //@private diff --git a/ui/placeholder/placeholder-common.ts b/ui/placeholder/placeholder-common.ts index 5c261a08c..12611ca84 100644 --- a/ui/placeholder/placeholder-common.ts +++ b/ui/placeholder/placeholder-common.ts @@ -1,9 +1,6 @@ import definition = require("ui/placeholder"); import view = require("ui/core/view"); -export module knownEvents { - export var creatingView = "creatingView"; -} - export class Placeholder extends view.View implements definition.Placeholder { + public static creatingViewEvent = "creatingView"; } \ No newline at end of file diff --git a/ui/placeholder/placeholder.android.ts b/ui/placeholder/placeholder.android.ts index 41118fa48..c2791b457 100644 --- a/ui/placeholder/placeholder.android.ts +++ b/ui/placeholder/placeholder.android.ts @@ -9,7 +9,7 @@ export class Placeholder extends common.Placeholder { private _android: android.view.View; public _createUI() { - var args = { eventName: common.knownEvents.creatingView, object: this, view: undefined, context: this._context }; + var args = { eventName: common.Placeholder.creatingViewEvent, object: this, view: undefined, context: this._context }; this.notify(args); this._android = args.view; } diff --git a/ui/placeholder/placeholder.d.ts b/ui/placeholder/placeholder.d.ts index b603b22f4..d3567497f 100644 --- a/ui/placeholder/placeholder.d.ts +++ b/ui/placeholder/placeholder.d.ts @@ -5,18 +5,26 @@ declare module "ui/placeholder" { import view = require("ui/core/view"); import observable = require("data/observable"); - /** - * Known event names. - */ - export module knownEvents { - export var creatingView: string; - } - /** * Represents a Placeholder, which is used to add a native view to the visual tree. */ export class Placeholder extends view.View { - on(event: string, callback: (args: CreateViewEventData) => void); + /** + * String value used when hooking to creatingView event. + */ + public static creatingViewEvent: string; + + /** + * 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: (args: observable.EventData) => void); + + /** + * Raised when a creatingView event occurs. + */ on(event: "creatingView", callback: (args: CreateViewEventData) => void); } diff --git a/ui/placeholder/placeholder.ios.ts b/ui/placeholder/placeholder.ios.ts index 3dd323987..cc1e6d088 100644 --- a/ui/placeholder/placeholder.ios.ts +++ b/ui/placeholder/placeholder.ios.ts @@ -11,7 +11,7 @@ export class Placeholder extends common.Placeholder { get ios(): UIView { if (!this._ios) { console.trace(); - var args = { eventName: common.knownEvents.creatingView, object: this, view: undefined, context: undefined }; + var args = { eventName: common.Placeholder.creatingViewEvent, object: this, view: undefined, context: undefined }; super.notify(args); this._ios = args.view; } diff --git a/ui/search-bar/search-bar-common.ts b/ui/search-bar/search-bar-common.ts index ea1ab350d..c8c3489ad 100644 --- a/ui/search-bar/search-bar-common.ts +++ b/ui/search-bar/search-bar-common.ts @@ -4,12 +4,10 @@ import dependencyObservable = require("ui/core/dependency-observable"); import proxy = require("ui/core/proxy"); import color = require("color"); -export module knownEvents { - export var submit = "submit"; - export var clear = "clear"; -} - export class SearchBar extends view.View implements definition.SearchBar { + public static submitEvent = "submit"; + public static clearEvent = "clear"; + public static textFieldBackgroundColorProperty = new dependencyObservable.Property("textFieldBackgroundColor", "SearchBar", new proxy.PropertyMetadata(undefined)) public static hintProperty = new dependencyObservable.Property("hint", "SearchBar", new proxy.PropertyMetadata("")) diff --git a/ui/search-bar/search-bar.android.ts b/ui/search-bar/search-bar.android.ts index 0e358c953..c79bb078a 100644 --- a/ui/search-bar/search-bar.android.ts +++ b/ui/search-bar/search-bar.android.ts @@ -92,7 +92,7 @@ export class SearchBar extends common.SearchBar { // This code is needed since sometimes OnCloseListener is not called! if (newText === EMPTY && this[SEARCHTEXT] !== newText) { - this.owner._emit(common.knownEvents.clear); + this.owner._emit(common.SearchBar.clearEvent); } this[SEARCHTEXT] = newText; @@ -104,7 +104,7 @@ export class SearchBar extends common.SearchBar { if (this.owner) { // This code is needed since onQueryTextSubmit is called twice with same query! if (query !== EMPTY && this[QUERY] !== query) { - this.owner._emit(common.knownEvents.submit); + this.owner._emit(common.SearchBar.submitEvent); } this[QUERY] = query; } @@ -119,7 +119,7 @@ export class SearchBar extends common.SearchBar { onClose: function () { if (this.owner) { - this.owner._emit(common.knownEvents.clear); + this.owner._emit(common.SearchBar.clearEvent); } return true; } diff --git a/ui/search-bar/search-bar.d.ts b/ui/search-bar/search-bar.d.ts index faebfe103..4b1783d52 100644 --- a/ui/search-bar/search-bar.d.ts +++ b/ui/search-bar/search-bar.d.ts @@ -7,25 +7,20 @@ declare module "ui/search-bar" { import dependencyObservable = require("ui/core/dependency-observable"); import color = require("color"); - /** - * Known event names. - */ - module knownEvents { - /** - * Raised when search request has been submitted. - */ - export var submit: string; - - /** - * Raised when search critea has been cleared. - */ - export var clear: string; - } - /** * Represents a search bar component. */ export class SearchBar extends view.View { + /** + * String value used when hooking to submit event. + */ + public static submitEvent: string; + + /** + * String value used when hooking to clear event. + */ + public static clearEvent: string; + /** * Dependency property used to support binding operations related to search-bar text. */ @@ -61,16 +56,22 @@ declare module "ui/search-bar" { */ textFieldBackgroundColor: color.Color; - 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 a search bar search is submitted. */ - on(event: "submit", callback: (args: observable.EventData) => void); + on(event: "submit", callback: (args: observable.EventData) => void, thisArg?: any); /** * Raised when a search bar search is closed. */ - on(event: "close", callback: (args: observable.EventData) => void); + on(event: "close", callback: (args: observable.EventData) => void, thisArg?: any); } } \ No newline at end of file diff --git a/ui/search-bar/search-bar.ios.ts b/ui/search-bar/search-bar.ios.ts index 0960f6052..1519a6222 100644 --- a/ui/search-bar/search-bar.ios.ts +++ b/ui/search-bar/search-bar.ios.ts @@ -70,7 +70,7 @@ class UISearchBarDelegateImpl extends NSObject implements UISearchBarDelegate { // This code is needed since sometimes searchBarCancelButtonClicked is not called! if (searchText === "" && this._searchText !== searchText) { - this._owner._emit(common.knownEvents.clear); + this._owner._emit(common.SearchBar.clearEvent); } this._searchText = searchText; @@ -78,12 +78,12 @@ class UISearchBarDelegateImpl extends NSObject implements UISearchBarDelegate { public searchBarCancelButtonClicked(searchBar: UISearchBar) { searchBar.resignFirstResponder(); - this._owner._emit(common.knownEvents.clear); + this._owner._emit(common.SearchBar.clearEvent); } public searchBarSearchButtonClicked(searchBar: UISearchBar) { searchBar.resignFirstResponder(); - this._owner._emit(common.knownEvents.submit); + this._owner._emit(common.SearchBar.submitEvent); } } diff --git a/ui/slide-out/slide-out.android.ts b/ui/slide-out/slide-out.android.ts index 78cfd2eb0..e4155c8a2 100644 --- a/ui/slide-out/slide-out.android.ts +++ b/ui/slide-out/slide-out.android.ts @@ -86,7 +86,7 @@ export class SlideOutControl extends common.SlideOutControl { var owningFrame: frame.Frame = view.getAncestor(this, "Frame"); if (owningFrame) { - owningFrame.android.removeEventListener(frame.knownEvents.android.optionSelected, this._optionSelectedCallback); + owningFrame.android.removeEventListener(frame.Frame.androidOptionSelectedEvent, this._optionSelectedCallback); this._optionsCallbackAdded = false; } } @@ -176,7 +176,7 @@ export class SlideOutControl extends common.SlideOutControl { var owningFrame: frame.Frame = view.getAncestor(this, "Frame"); if (owningFrame) { - owningFrame.android.addEventListener(frame.knownEvents.android.optionSelected, this._optionSelectedCallback); + owningFrame.android.addEventListener(frame.Frame.androidOptionSelectedEvent, this._optionSelectedCallback); this._optionsCallbackAdded = true; } } diff --git a/ui/text-base/text-base.ts b/ui/text-base/text-base.ts index 210f87235..92ab9a124 100644 --- a/ui/text-base/text-base.ts +++ b/ui/text-base/text-base.ts @@ -79,7 +79,7 @@ export class TextBase extends view.View implements definition.TextBase { if (this.formattedText !== value) { var weakEventOptions: weakEventListener.WeakEventListenerOptions = { targetWeakRef: new WeakRef(this), - eventName: observable.knownEvents.propertyChange, + eventName: observable.Observable.propertyChangeEvent, sourceWeakRef: new WeakRef(value), handler: this.onFormattedTextChanged, handlerContext: this, diff --git a/ui/web-view/web-view-common.ts b/ui/web-view/web-view-common.ts index b99665264..8ee40e8bb 100644 --- a/ui/web-view/web-view-common.ts +++ b/ui/web-view/web-view-common.ts @@ -3,10 +3,6 @@ import view = require("ui/core/view"); import dependencyObservable = require("ui/core/dependency-observable"); import proxy = require("ui/core/proxy"); -export module knownEvents { - export var loadFinished: string = "loadFinished"; - export var loadStarted: string = "loadStarted"; -} var urlProperty = new dependencyObservable.Property( "url", "WebView", @@ -27,6 +23,8 @@ function onUrlPropertyChanged(data: dependencyObservable.PropertyChangeData) { (urlProperty.metadata).onSetNativeValue = onUrlPropertyChanged; export class WebView extends view.View implements definition.WebView { + public static loadStartedEvent = "loadStarted"; + public static loadFinishedEvent = "loadFinished"; public static urlProperty = urlProperty; @@ -51,7 +49,7 @@ export class WebView extends view.View implements definition.WebView { this._suspendLoading = false; var args = { - eventName: knownEvents.loadFinished, + eventName: WebView.loadFinishedEvent, object: this, url: url, error: error @@ -62,7 +60,7 @@ export class WebView extends view.View implements definition.WebView { public _onLoadStarted(url: string) { var args = { - eventName: knownEvents.loadStarted, + eventName: WebView.loadStartedEvent, object: this, url: url, error: undefined diff --git a/ui/web-view/web-view.d.ts b/ui/web-view/web-view.d.ts index 76e0762d5..29956a8ec 100644 --- a/ui/web-view/web-view.d.ts +++ b/ui/web-view/web-view.d.ts @@ -6,25 +6,19 @@ declare module "ui/web-view" { import dependencyObservable = require("ui/core/dependency-observable"); import observable = require("data/observable"); - /** - * Known event names. - */ - export module knownEvents { - /** - * Raised when the web-view has completely loaded an url. - */ - export var loadFinished: string; - - /** - * Raised when the web-view starts loading an url. - */ - export var loadStarted: string; - } - /** * Represents a standard WebView widget. */ export class WebView extends view.View { + /** + * String value used when hooking to loadStarted event. + */ + public static loadStartedEvent: string; + + /** + * String value used when hooking to loadFinished event. + */ + public static loadFinishedEvent: string; /** * Represents the observable property backing the Url property of each WebView instance. @@ -71,9 +65,23 @@ declare module "ui/web-view" { */ reload(); - on(event: string, callback: (data: observable.EventData) => void); - on(event: "loadFinished", callback: (args: LoadEventData) => void); - on(event: "loadStarted", callback: (args: LoadEventData) => 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 a loadFinished event occurs. + */ + on(event: "loadFinished", callback: (args: LoadEventData) => void, thisArg?: any); + + /** + * Raised when a loadStarted event occurs. + */ + on(event: "loadStarted", callback: (args: LoadEventData) => void, thisArg?: any); } /** @@ -89,4 +97,4 @@ declare module "ui/web-view" { */ error: string; } -} +} \ No newline at end of file