FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Binding to ViewBase as source now works by hshristov · Pull Request #4195 · NativeScript/NativeScript · GitHub

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension .ts  (8) All 1 file type selected
Viewed files
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Unified
Split
Hide whitespace
Diff view
Unified
Split
Hide whitespace
4 changes: 1 addition & 3 deletions tests/app/app/mainPage.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,7 @@ page.id = "mainPage";
page.on(Page.navigatedToEvent, onNavigatedTo);

function runTests() {
setTimeout(function () {
tests.runAll();
}, 10);
setTimeout(() => tests.runAll(), 10);
}

function onNavigatedTo(args) {
Expand Down
9 changes: 9 additions & 0 deletions tests/app/ui/core/bindable/bindable-tests.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,15 @@ export function test_Bindable_Members() {
TKUnit.assert(types.isDefined(obj.unbind), "Bindable.unbind not defined");
};

export function test_Binding_to_bindingContext_of_View() {
const target = new Button();
const source = new Button();

target.bind({ targetProperty: "bindingContext", sourceProperty: "text" }, source);
source.text = 'a';
TKUnit.assertEqual(target.bindingContext, 'a');
};

export function test_Bindable_Bind_ToTarget_OneWay() {
const model = new Observable();
model.set("name", "John");
Expand Down
7 changes: 7 additions & 0 deletions tns-core-modules/data/observable/observable.d.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,13 @@ export class Observable {
*/
_createPropertyChangeData(name: string, value: any, oldValue?: any): PropertyChangeData;

//@private
/**
* Filed to use instead of instanceof ViewBase.
* @private
*/
public _isViewBase: boolean;

/**
* @private
*/
Expand Down
4 changes: 3 additions & 1 deletion tns-core-modules/data/observable/observable.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ let _wrappedValues = [

export class Observable implements ObservableDefinition {
public static propertyChangeEvent = "propertyChange";
public _isViewBase: boolean;

private _observers = {};

public get(name: string): any {
Expand Down Expand Up @@ -233,4 +235,4 @@ export function fromObjectRecursive(source: any): Observable {
let observable = new ObservableFromObject();
addPropertiesFromObject(observable, source, true);
return observable;
}
}
2 changes: 1 addition & 1 deletion tns-core-modules/ui/core/bindable/bindable.d.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -59,4 +59,4 @@ export class Binding {
}

export function getEventOrGestureName(name: string): string;
export function isEventOrGesture(name: string, view: ViewBase): boolean;
export function isEventOrGesture(name: string, view: ViewBase): boolean;
28 changes: 15 additions & 13 deletions tns-core-modules/ui/core/bindable/bindable.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,9 @@ const contextKey = "context";
// from $parents['ListView'] will return 'ListView'
// from $parents[1] will return 1
const paramsRegex = /\[\s*(['"])*(\w*)\1\s*\]/;

const bc = bindingConstants;

const emptyArray = [];

function getProperties(property: string): Array<string> {
let result: Array<string> = emptyArray;
if (property) {
Expand Down Expand Up @@ -55,7 +54,7 @@ export function getEventOrGestureName(name: string): string {
// NOTE: method fromString from "ui/gestures";
export function isGesture(eventOrGestureName: string): boolean {
let t = eventOrGestureName.trim().toLowerCase();
return t === "tap"
return t === "tap"
|| t === "doubletap"
|| t === "pinch"
|| t === "pan"
Expand Down Expand Up @@ -169,8 +168,9 @@ export class Binding {
return;
}

if (data.value) {
this.update(data.value);
const value = data.value;
if (value !== null && value !== undefined) {
this.update(value);
} else {
// TODO: Is this correct?
// What should happen when bindingContext is null/undefined?
Expand Down Expand Up @@ -279,14 +279,16 @@ export class Binding {
let prop = parentProperies || "";

for (let i = 0, length = objectsAndProperties.length; i < length; i++) {
prop += "$" + objectsAndProperties[i].property;
const propName = objectsAndProperties[i].property;
prop += "$" + propName;
let currentObject = objectsAndProperties[i].instance;
if (!this.propertyChangeListeners.has(prop) && currentObject instanceof Observable) {
addWeakEventListener(
currentObject,
Observable.propertyChangeEvent,
this.onSourcePropertyChanged,
this);
if (!this.propertyChangeListeners.has(prop) && currentObject instanceof Observable && currentObject._isViewBase) {
// Add listener for properties created with after 3.0 version
addWeakEventListener(currentObject, `${propName}Change`, this.onSourcePropertyChanged, this);
addWeakEventListener(currentObject, Observable.propertyChangeEvent, this.onSourcePropertyChanged, this);
this.propertyChangeListeners.set(prop, currentObject);
} else if (!this.propertyChangeListeners.has(prop) && currentObject instanceof Observable) {
addWeakEventListener(currentObject, Observable.propertyChangeEvent, this.onSourcePropertyChanged, this);
this.propertyChangeListeners.set(prop, currentObject);
}
}
Expand Down Expand Up @@ -601,4 +603,4 @@ export class Binding {

this.updating = false;
}
}
}
9 changes: 8 additions & 1 deletion tns-core-modules/ui/core/view-base/view-base.d.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import { Order, FlexGrow, FlexShrink, FlexWrapBefore, AlignSelf } from "../../la
import { Length } from "../../styling/style-properties";

export { isIOS, isAndroid, layout, Color };

export * from "../properties";
export * from "../bindable";

Expand Down Expand Up @@ -291,6 +292,12 @@ export abstract class ViewBase extends Observable {
//@endprivate
}

export class Binding {
constructor(target: ViewBase, options: BindingOptions);
public bind(source: Object): void;
public unbind();
}

export const idProperty: Property<ViewBase, string>;
export const classNameProperty: Property<ViewBase, string>;
export const bindingContextProperty: InheritedProperty<ViewBase, any>;
Expand All @@ -299,4 +306,4 @@ export const bindingContextProperty: InheritedProperty<ViewBase, any>;
* Converts string into boolean value.
* Throws error if value is not 'true' or 'false'.
*/
export function booleanConverter(v: string): boolean;
export function booleanConverter(v: string): boolean;
1 change: 1 addition & 0 deletions tns-core-modules/ui/core/view-base/view-base.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -863,6 +863,7 @@ ViewBase.prototype._defaultPaddingTop = 0;
ViewBase.prototype._defaultPaddingRight = 0;
ViewBase.prototype._defaultPaddingBottom = 0;
ViewBase.prototype._defaultPaddingLeft = 0;
ViewBase.prototype._isViewBase = true;

ViewBase.prototype._batchUpdateScope = 0;

Expand Down

Back | FazBrowse Home | New Git URL