Skip to content

Commit 6bb533d

Browse files
author
Nedyalko Nikolov
committed
Fixed issue with binding when binding to a falsy object (also added types.isNullOrundefined function).
1 parent 9550ebc commit 6bb533d

7 files changed

Lines changed: 25 additions & 10 deletions

File tree

camera/camera.android.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
import appModule = require("application");
33
import fileSystem = require("file-system");
44
import utils = require("utils/utils");
5+
import types = require("utils/types");
56
import definition = require("camera");
67
import common = require("./camera-common");
78

@@ -14,7 +15,7 @@ export var takePicture = function (options?: definition.CameraOptions): Promise<
1415
if (options) {
1516
var reqWidth = options.width ? options.width * density : 0;
1617
var reqHeight = options.height ? options.height * density : reqWidth;
17-
var shouldKeepAspectRatio = (options.keepAspectRatio === null || options.keepAspectRatio === undefined) ? true : options.keepAspectRatio;
18+
var shouldKeepAspectRatio = types.isNullOrUndefined(options.keepAspectRatio) ? true : options.keepAspectRatio;
1819
}
1920
var takePictureIntent = new android.content.Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
2021
var dateStamp = createDateTimeStamp();

camera/camera.ios.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
import frame = require("ui/frame");
33
import definition = require("camera");
44
import common = require("./camera-common");
5+
import types = require("utils/types");
56

67
class UIImagePickerControllerDelegateImpl extends NSObject implements UIImagePickerControllerDelegate {
78
public static ObjCProtocols = [UIImagePickerControllerDelegate];
@@ -26,7 +27,7 @@ class UIImagePickerControllerDelegateImpl extends NSObject implements UIImagePic
2627
if (options) {
2728
this._width = options.width;
2829
this._height = options.height;
29-
this._keepAspectRatio = (options.keepAspectRatio === null || options.keepAspectRatio === undefined) ? true : options.keepAspectRatio;
30+
this._keepAspectRatio = types.isNullOrUndefined(options.keepAspectRatio) ? true : options.keepAspectRatio;
3031
}
3132
return this;
3233
}
@@ -76,7 +77,7 @@ export var takePicture = function (options?: definition.CameraOptions): Promise<
7677
if (options) {
7778
reqWidth = options.width || 0;
7879
reqHeight = options.height || reqWidth;
79-
keepAspectRatio = (options.keepAspectRatio === null || options.keepAspectRatio === undefined) ? true : options.keepAspectRatio;
80+
keepAspectRatio = types.isNullOrUndefined(options.keepAspectRatio) ? true : options.keepAspectRatio;
8081
}
8182
if (reqWidth && reqHeight) {
8283
listener = UIImagePickerControllerDelegateImpl.new().initWithCallbackAndOptions(resolve, { width: reqWidth, height: reqHeight, keepAspectRatio: keepAspectRatio });

ui/core/bindable.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ export class Bindable extends dependencyObservable.DependencyObservable implemen
4444
if (!bindingSource) {
4545
bindingSource = this.bindingContext;
4646
}
47-
if (bindingSource) {
47+
if (!types.isNullOrUndefined(bindingSource)) {
4848
binding.bind(bindingSource);
4949
}
5050
}
@@ -109,7 +109,7 @@ export class Bindable extends dependencyObservable.DependencyObservable implemen
109109
" targetProperty: " + binding.options.targetProperty +
110110
" to the changed context: " + newValue, trace.categories.Binding);
111111
binding.unbind();
112-
if (newValue) {
112+
if (!types.isNullOrUndefined(newValue)) {
113113
binding.bind(newValue);
114114
}
115115
}
@@ -134,7 +134,7 @@ export class Binding {
134134
}
135135

136136
public bind(obj: Object) {
137-
if (!obj) {
137+
if (types.isNullOrUndefined(obj)) {
138138
throw new Error("Expected valid object reference as a source in the Binding.bind method.");
139139
}
140140

@@ -344,7 +344,7 @@ export class Binding {
344344
currentObject = currentObject[properties[i]];
345345
}
346346

347-
if (currentObject !== undefined && currentObject !== null) {
347+
if (!types.isNullOrUndefined(currentObject)) {
348348
options = {
349349
instance: new WeakRef(currentObject),
350350
property: properties[properties.length - 1]

ui/tab-view/tab-view.android.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import dependencyObservable = require("ui/core/dependency-observable");
44
import view = require("ui/core/view");
55
import trace = require("trace");
66
import imageSource = require("image-source");
7+
import types = require("utils/types");
78

89
var VIEWS_STATES = "_viewStates";
910

@@ -436,7 +437,7 @@ export class TabView extends common.TabView {
436437
}
437438

438439
private _setNativeSelectedIndex(index: number) {
439-
if (index === undefined || index === null) {
440+
if (types.isNullOrUndefined(index)) {
440441
return;
441442
}
442443

ui/tab-view/tab-view.ios.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import trace = require("trace");
66
import utils = require("utils/utils");
77
import view = require("ui/core/view");
88
import imageSource = require("image-source");
9+
import types = require("utils/types");
910

1011
// merge the exports of the common file with the exports of this file
1112
declare var exports;
@@ -206,7 +207,7 @@ export class TabView extends common.TabView {
206207

207208
var newIndex = data.newValue;
208209
trace.write("TabView._onSelectedIndexPropertyChangedSetNativeValue(" + newIndex + ")", trace.categories.Debug);
209-
if (newIndex === undefined || newIndex === null) {
210+
if (types.isNullOrUndefined(newIndex)) {
210211
return;
211212
}
212213

utils/types.d.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,19 @@
2828
export function isUndefined(value: any): boolean;
2929

3030
/**
31-
* A function that checks if something is defined (not null and not undefined).
31+
* A function that checks if something is defined (not undefined).
3232
* @param value The value which will be checked.
3333
* Returns true if value is defined.
3434
*/
3535
export function isDefined(value: any): boolean;
3636

37+
/**
38+
* A function that checks if something is not defined (null or undefined).
39+
* @param value The value which will be checked.
40+
* Returns true if value is null or undefined.
41+
*/
42+
export function isNullOrUndefined(value: any): boolean;
43+
3744
/**
3845
* A function that checks if something is a valid function.
3946
* @param value The value which will be checked.

utils/types.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,10 @@ export function isDefined(value: any): boolean {
2121
return typeof value !== "undefined";
2222
}
2323

24+
export function isNullOrUndefined(value: any): boolean {
25+
return (typeof value === "undefined") || (value === null);
26+
}
27+
2428
export function verifyCallback(value: any) {
2529
if (value && !isFunction(value)) {
2630
throw new TypeError("Callback must be a valid function.");

0 commit comments

Comments
 (0)