Skip to content

Commit

Permalink
fix: WrappedValue.unwrap empty string behavior (#6900)
Browse files Browse the repository at this point in the history
  • Loading branch information
speigg authored and manoldonev committed Mar 14, 2019
1 parent 3c2c1d9 commit 0482460
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
13 changes: 12 additions & 1 deletion tests/app/data/observable-tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -521,7 +521,18 @@ export function test_CorrectPropertyValueAfterUsingWrappedValue() {

testObservable.set("property1", wrappedArray);

TKUnit.assertEqual(testObservable.get("property1"), testArray, "WrappedValue is used only to execute property change logic and unwrapped value should be used as proeprty value.");
TKUnit.assertEqual(testObservable.get("property1"), testArray, "WrappedValue is used only to execute property change logic and unwrapped value should be used as property value.");
}

export function test_CorrectPropertyValueAfterUsingStringEmptyWrappedValue() {
const emptyString = "";
let testObservable = fromObject({ "property1": emptyString });

let wrappedEmptyString = WrappedValue.wrap(emptyString);

testObservable.set("property1", wrappedEmptyString);

TKUnit.assertEqual(testObservable.get("property1"), emptyString, "WrappedValue is used only to execute property change logic and unwrapped value should be used as property value.");
}

export function test_NestedObservablesWithObservableArrayShouldNotCrash() {
Expand Down
4 changes: 2 additions & 2 deletions tns-core-modules/data/observable/observable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export class WrappedValue implements WrappedValueDefinition {
}

public static unwrap(value: any) {
return (value && value.wrapped) ? value.wrapped : value;
return (value instanceof WrappedValue) ? value.wrapped : value;
}

public static wrap(value: any) {
Expand Down Expand Up @@ -249,4 +249,4 @@ export function fromObjectRecursive(source: any): Observable {
let observable = new ObservableFromObject();
addPropertiesFromObject(observable, source, true);
return observable;
}
}

0 comments on commit 0482460

Please sign in to comment.