Skip to content

Commit

Permalink
fix: #122 only unmutable writeable data types are now considered pare…
Browse files Browse the repository at this point in the history
…nt parcel types
  • Loading branch information
dxinteractive committed Oct 23, 2018
1 parent 2f19ad5 commit c33b39e
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 4 deletions.
21 changes: 19 additions & 2 deletions packages/dataparcels/src/parcel/__test__/ParcelTypes-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,12 @@ test('ParcelTypes should correctly identify date', () => {
var data = {
value: new Date()
};
expect(new Parcel(data).isParent()).toBe(true);
expect(new Parcel(data).isParent()).toBe(false);
expect(new Parcel(data).isIndexed()).toBe(false);
expect(new Parcel(data).isChild()).toBe(false);
expect(new Parcel(data).isElement()).toBe(false);
expect(new Parcel(data).isTopLevel()).toBe(true);
expect(new Parcel(data)._parcelTypes.toTypeCode()).toBe("ceiPT");
expect(new Parcel(data)._parcelTypes.toTypeCode()).toBe("ceipT");
});

test('ParcelTypes should correctly identify object values', () => {
Expand All @@ -47,6 +47,22 @@ test('ParcelTypes should correctly identify class instance values', () => {
var data = {
value: new Thing()
};
expect(new Parcel(data).isParent()).toBe(false);
expect(new Parcel(data).isIndexed()).toBe(false);
expect(new Parcel(data).isChild()).toBe(false);
expect(new Parcel(data).isElement()).toBe(false);
expect(new Parcel(data).isTopLevel()).toBe(true);
expect(new Parcel(data)._parcelTypes.toTypeCode()).toBe("ceipT");
});

test('ParcelTypes should correctly identify unmutable compatible class instance values', () => {
class UnmutableCompatible {
__UNMUTABLE_COMPATIBLE__ = true;
foo = "123";
}
var data = {
value: new UnmutableCompatible()
};
expect(new Parcel(data).isParent()).toBe(true);
expect(new Parcel(data).isIndexed()).toBe(false);
expect(new Parcel(data).isChild()).toBe(false);
Expand All @@ -55,6 +71,7 @@ test('ParcelTypes should correctly identify class instance values', () => {
expect(new Parcel(data)._parcelTypes.toTypeCode()).toBe("ceiPT");
});


test('ParcelTypes should correctly identify Immutable.js Map values', () => {
var data = {
value: Map({
Expand Down
3 changes: 2 additions & 1 deletion packages/dataparcels/src/parcelData/isIndexedValue.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// @flow
import isIndexed from 'unmutable/lib/util/isIndexed';
import isWriteable from 'unmutable/lib/util/isWriteable';

export default (value: *): boolean => {
return isIndexed(value);
return isIndexed(value) && isWriteable(value);
};
3 changes: 2 additions & 1 deletion packages/dataparcels/src/parcelData/isParentValue.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// @flow
import isValueObject from 'unmutable/lib/util/isValueObject';
import isWriteable from 'unmutable/lib/util/isWriteable';

export default (value: *): boolean => {
return isValueObject(value);
return isValueObject(value) && isWriteable(value);
};

0 comments on commit c33b39e

Please sign in to comment.