chore: cleanup

This commit is contained in:
Nathan Walker
2020-07-04 01:12:55 -07:00
parent 9341cd9554
commit 1525c89733
274 changed files with 1755 additions and 2733 deletions

View File

@@ -1,71 +0,0 @@
/**
* @module "ui/core/bindable"
*/ /** */
import { ViewBase } from "../view-base";
import { Observable, WrappedValue, PropertyChangeData, EventData } from "../../../data/observable";
import {
isEnabled as traceEnabled,
write as traceWrite,
error as traceError,
categories as traceCategories,
notifyEvent as traceNotifyEvent,
messageType as traceMessageType,
isCategorySet
} from "../../../trace";
export {
Observable, WrappedValue, PropertyChangeData, EventData,
traceEnabled, traceWrite, traceError, traceCategories, traceNotifyEvent,
traceMessageType, isCategorySet
};
/**
* The options object used in the Bindable.bind method.
*/
export interface BindingOptions {
/**
* The property name of the source object (typically the ViewModel) to bind to.
*/
sourceProperty: string;
/**
* The property name of the target object (that is the Bindable instance) to bind the source property to.
*/
targetProperty: string;
/**
* True to establish a two-way binding, false otherwise. A two-way binding will synchronize both the source and the target property values regardless of which one initiated the change.
*/
twoWay?: boolean;
/**
* An expression used for calculations (convertions) based on the value of the property.
*/
expression?: string;
}
/**
* An interface which defines methods need to create binding value converter.
*/
export interface ValueConverter {
/**
* A method that will be executed when a value (of the binding property) should be converted to the observable model.
* For example: user types in a text field, but our business logic requires to store data in a different manner (e.g. in lower case).
* @param params - An array of parameters where first element is the value of the property and next elements are parameters send to converter.
*/
toModel: (...params: any[]) => any;
/**
* A method that will be executed when a value should be converted to the UI view. For example we have a date object which should be displayed to the end user in a specific date format.
* @param params - An array of parameters where first element is the value of the property and next elements are parameters send to converter.
*/
toView: (...params: any[]) => any;
}
export class Binding {
constructor(target: ViewBase, options: BindingOptions);
public bind(source: Object): void;
public unbind();
public sourceIsBindingContext: boolean;
public updateTwoWay(value: any);
}
export function getEventOrGestureName(name: string): string;
export function isEventOrGesture(name: string, view: ViewBase): boolean;

View File

@@ -1,5 +1,4 @@
// Types
import { BindingOptions } from ".";
import { ViewBase } from "../view-base";
// Requires
@@ -9,13 +8,7 @@ import { addWeakEventListener, removeWeakEventListener } from "../weak-event-lis
import { bindingConstants, parentsRegex } from "../../builder/binding-builder";
import { escapeRegexSymbols } from "../../../utils/utils";
import {
isEnabled as traceEnabled,
write as traceWrite,
error as traceError,
categories as traceCategories,
notifyEvent as traceNotifyEvent,
isCategorySet,
messageType as traceMessageType
Trace
} from "../../../trace";
import * as types from "../../../utils/types";
import * as bindableResources from "./bindable-resources";
@@ -59,6 +52,45 @@ function getProperties(property: string): Array<string> {
return result;
}
/**
* The options object used in the Bindable.bind method.
*/
export interface BindingOptions {
/**
* The property name of the source object (typically the ViewModel) to bind to.
*/
sourceProperty: string;
/**
* The property name of the target object (that is the Bindable instance) to bind the source property to.
*/
targetProperty: string;
/**
* True to establish a two-way binding, false otherwise. A two-way binding will synchronize both the source and the target property values regardless of which one initiated the change.
*/
twoWay?: boolean;
/**
* An expression used for calculations (convertions) based on the value of the property.
*/
expression?: string;
}
/**
* An interface which defines methods need to create binding value converter.
*/
export interface ValueConverter {
/**
* A method that will be executed when a value (of the binding property) should be converted to the observable model.
* For example: user types in a text field, but our business logic requires to store data in a different manner (e.g. in lower case).
* @param params - An array of parameters where first element is the value of the property and next elements are parameters send to converter.
*/
toModel: (...params: any[]) => any;
/**
* A method that will be executed when a value should be converted to the UI view. For example we have a date object which should be displayed to the end user in a specific date format.
* @param params - An array of parameters where first element is the value of the property and next elements are parameters send to converter.
*/
toView: (...params: any[]) => any;
}
export function getEventOrGestureName(name: string): string {
return name.indexOf("on") === 0 ? name.substr(2, name.length - 2) : name;
}
@@ -348,7 +380,7 @@ export class Binding {
let expressionValue = this._getExpressionValue(updateExpression, true, changedModel);
if (expressionValue instanceof Error) {
traceWrite((<Error>expressionValue).message, traceCategories.Binding, traceMessageType.error);
Trace.write((<Error>expressionValue).message, Trace.categories.Binding, Trace.messageType.error);
}
newValue = expressionValue;
@@ -410,7 +442,7 @@ export class Binding {
if (this.options.expression) {
const expressionValue = this._getExpressionValue(this.options.expression, false, undefined);
if (expressionValue instanceof Error) {
traceWrite(expressionValue.message, traceCategories.Binding, traceMessageType.error);
Trace.write(expressionValue.message, Trace.categories.Binding, Trace.messageType.error);
} else {
this.updateTarget(expressionValue);
}
@@ -517,7 +549,7 @@ export class Binding {
changedModel[bc.bindingValueKey] = this.source ? this.source.get() : undefined;
let expressionValue = this._getExpressionValue(this.options.expression, false, changedModel);
if (expressionValue instanceof Error) {
traceWrite((<Error>expressionValue).message, traceCategories.Binding, traceMessageType.error);
Trace.write((<Error>expressionValue).message, Trace.categories.Binding, Trace.messageType.error);
}
else {
return expressionValue;
@@ -534,7 +566,7 @@ export class Binding {
this.sourceOptions.property in sourceOptionsInstance) {
return sourceOptionsInstance[this.sourceOptions.property];
} else {
traceWrite("Property: '" + this.sourceOptions.property + "' is invalid or does not exist. SourceProperty: '" + this.options.sourceProperty + "'", traceCategories.Binding, traceMessageType.error);
Trace.write("Property: '" + this.sourceOptions.property + "' is invalid or does not exist. SourceProperty: '" + this.options.sourceProperty + "'", Trace.categories.Binding, Trace.messageType.error);
}
}
@@ -635,9 +667,9 @@ export class Binding {
optionsInstance[options.property] = value;
}
} catch (ex) {
traceWrite("Binding error while setting property " + options.property + " of " + optionsInstance + ": " + ex,
traceCategories.Binding,
traceMessageType.error);
Trace.write("Binding error while setting property " + options.property + " of " + optionsInstance + ": " + ex,
Trace.categories.Binding,
Trace.messageType.error);
}
this.updating = false;

View File

@@ -1,5 +0,0 @@
{
"name": "bindable",
"main": "bindable",
"types": "bindable.d.ts"
}