Skip to content

Commit

Permalink
Merge pull request #126 from blueflag/feature/logging
Browse files Browse the repository at this point in the history
Unmutable upgrade and logging
  • Loading branch information
dxinteractive authored Oct 23, 2018
2 parents 5988cfd + 3348305 commit 200f9a8
Show file tree
Hide file tree
Showing 24 changed files with 152 additions and 20 deletions.
19 changes: 14 additions & 5 deletions packages/dataparcels-docs/src/component/ApiPage.jsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// @flow
import type {Node} from 'react';
import React from 'react';
import {Fragment} from 'react';
import {Box, Grid, GridItem, NavigationList, NavigationListItem, Text, Typography} from 'dcme-style';
import Link from 'component/Link';
import SiteNavigation from 'component/SiteNavigation';
Expand Down Expand Up @@ -64,10 +65,18 @@ export default ({name, api, md, after}: Props) => {
{renderDoclets({api, md})}
{After && <Typography><After /></Typography>}
</Box>}
nav={() => <NavigationList>
<NavigationListItem><Link to="/api">Api</Link></NavigationListItem>
<NavigationListItem>{name}</NavigationListItem>
{renderApi(api)}
</NavigationList>}
nav={() => <Fragment>
<NavigationList>
<NavigationListItem><Link to="/api">Api</Link></NavigationListItem>
<NavigationListItem><Link to="/api/Parcel">Parcel</Link></NavigationListItem>
<NavigationListItem><Link to="/api/ParcelHoc">ParcelHoc</Link></NavigationListItem>
<NavigationListItem><Link to="/api/ParcelBoundary">ParcelBoundary</Link></NavigationListItem>
<NavigationListItem><Link to="/api/ParcelBoundaryHoc">ParcelBoundaryHoc</Link></NavigationListItem>
</NavigationList>
<NavigationList>
<NavigationListItem>{name}</NavigationListItem>
{renderApi(api)}
</NavigationList>
</Fragment>}
/>;
};
2 changes: 2 additions & 0 deletions packages/dataparcels-docs/src/docs/api/parcel/log.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
```flow
log(name: string?): Parcel
```

Output's the parcel's data to the console each time data flows downward, and outputs the ChangeRequest each time a change has propagated upward.
5 changes: 5 additions & 0 deletions packages/dataparcels-docs/src/docs/api/parcel/toConsole.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
```flow
toConsole(): void
```

Outputs the parcel's data to the console.
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import {ParcelBoundary} from 'react-dataparcels';
forceUpdate={?Array<*>}
hold={?boolean}
debugBuffer={?boolean}
debugParcel={?boolean}
>
{(parcel, actions) => Node}
</ParcelBoundary>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
```flow
debugParcel?: boolean = false // optional
```

Wehn `debugParcel` is true, ParcelBoundary will log out changes to its current parcel state.
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ ParcelBoundaryHoc({
originalParcelProp?: string | (props: *) => string,
// debugging options
debugBuffer?: boolean
debugParcel?: boolean
});
```

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
```flow
debugParcel?: boolean = false // optional
```

Wehn `debugParcel` is true, ParcelBoundaryHoc will log out changes to its current parcel state.
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ ParcelHoc({
delayUntil?: Function,
pipe?: Function
// debugging options
debugParcel?: boolean
debugRender?: boolean
});
```
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import Link from 'component/Link';

```flow
debugParcel?: boolean = false // optional
```

For debugging purposes. When set to `true` this logs the ParcelHoc's parcel each time it changes.
9 changes: 7 additions & 2 deletions packages/dataparcels-docs/src/pages/api/Parcel.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ import Markdown_spy from 'docs/api/parcel/spy.md';
import Markdown_spyChange from 'docs/api/parcel/spyChange.md';
import Markdown_pipe from 'docs/api/parcel/pipe.md';
import Markdown_matchPipe from 'docs/api/parcel/matchPipe.md';
import Markdown_toConsole from 'docs/api/parcel/toConsole.md';

const md = {
_desc: Markdown_Parcel,
Expand Down Expand Up @@ -117,7 +118,8 @@ const md = {
spy: Markdown_spy,
spyChange: Markdown_spyChange,
pipe: Markdown_pipe,
matchPipe: Markdown_matchPipe
matchPipe: Markdown_matchPipe,
toConsole: Markdown_toConsole
}

const api = `
Expand Down Expand Up @@ -191,14 +193,17 @@ isTopLevel()
hasDispatched()
# Side-effect methods
log()
spy()
spyChange()
# Composition methods
pipe()
matchPipe()
# Debug methods
log()
toConsole()
`;

export default () => <ApiPage
Expand Down
5 changes: 4 additions & 1 deletion packages/dataparcels-docs/src/pages/api/ParcelBoundary.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import Markdown_debounce from 'docs/api/parcelBoundary/debounce.md';
import Markdown_hold from 'docs/api/parcelBoundary/hold.md';
import Markdown_pure from 'docs/api/parcelBoundary/pure.md';
import Markdown_debugBuffer from 'docs/api/parcelBoundary/debugBuffer.md';
import Markdown_debugParcel from 'docs/api/parcelBoundary/debugParcel.md';

const md = {
_desc: Markdown_ParcelBoundary,
Expand All @@ -21,7 +22,8 @@ const md = {
debounce: Markdown_debounce,
hold: Markdown_hold,
pure: Markdown_pure,
debugBuffer: Markdown_debugBuffer
debugBuffer: Markdown_debugBuffer,
debugParcel: Markdown_debugParcel
}

const api = `
Expand All @@ -35,6 +37,7 @@ pure
forceUpdate
hold
debugBuffer
debugParcel
`;

export default () => <ApiPage
Expand Down
3 changes: 3 additions & 0 deletions packages/dataparcels-docs/src/pages/api/ParcelBoundaryHoc.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import Markdown_originalParcelProp from 'docs/api/parcelBoundaryHoc/originalParc
import Markdown_debounce from 'docs/api/parcelBoundaryHoc/debounce.md';
import Markdown_hold from 'docs/api/parcelBoundaryHoc/hold.md';
import Markdown_debugBuffer from 'docs/api/parcelBoundaryHoc/debugBuffer.md';
import Markdown_debugParcel from 'docs/api/parcelBoundaryHoc/debugParcel.md';
import Markdown_childName from 'docs/api/parcelBoundaryHoc/childName.md';
import Markdown_childNameActions from 'docs/api/parcelBoundaryHoc/childNameActions.md';
import Markdown_childOriginalParcelProp from 'docs/api/parcelBoundaryHoc/childOriginalParcelProp.md';
Expand All @@ -19,6 +20,7 @@ const md = {
debounce: Markdown_debounce,
hold: Markdown_hold,
debugBuffer: Markdown_debugBuffer,
debugParcel: Markdown_debugParcel,
['${name}']: Markdown_childName,
['${name}Actions']: Markdown_childNameActions,
['${originalParcelProp}']: Markdown_childOriginalParcelProp
Expand All @@ -31,6 +33,7 @@ originalParcelProp
debounce
hold
debugBuffer
debugParcel
# Child props
$\{name\}
Expand Down
3 changes: 3 additions & 0 deletions packages/dataparcels-docs/src/pages/api/ParcelHoc.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import Markdown_valueFromProps from 'docs/api/parcelHoc/valueFromProps.md';
import Markdown_delayUntil from 'docs/api/parcelHoc/delayUntil.md';
import Markdown_onChange from 'docs/api/parcelHoc/onChange.md';
import Markdown_pipe from 'docs/api/parcelHoc/pipe.md';
import Markdown_debugParcel from 'docs/api/parcelHoc/debugParcel.md';
import Markdown_debugRender from 'docs/api/parcelHoc/debugRender.md';
import Markdown_childName from 'docs/api/parcelHoc/childName.md';

Expand All @@ -22,6 +23,7 @@ const md = {
delayUntil: Markdown_delayUntil,
onChange: Markdown_onChange,
pipe: Markdown_pipe,
debugParcel: Markdown_debugParcel,
debugRender: Markdown_debugRender,
['${name}']: Markdown_childName
}
Expand All @@ -34,6 +36,7 @@ onChange
shouldParcelUpdateFromProps
delayUntil
pipe
debugParcel
debugRender
# Child props
Expand Down
2 changes: 1 addition & 1 deletion packages/dataparcels/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,6 @@
},
"dependencies": {
"escape-string-regexp": "^1.0.5",
"unmutable": "^0.34.0"
"unmutable": "^0.37.0"
}
}
3 changes: 3 additions & 0 deletions packages/dataparcels/src/parcel/Parcel.js
Original file line number Diff line number Diff line change
Expand Up @@ -365,4 +365,7 @@ export default class Parcel {
// Advanced methods
getInternalLocationShareData = (): * => this._methods.getInternalLocationShareData();
setInternalLocationShareData = (partialData: Object): * => this._methods.setInternalLocationShareData(partialData);

// Debug methods
toConsole = () => this._methods.toConsole();
}
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
8 changes: 7 additions & 1 deletion packages/dataparcels/src/parcel/methods/ParcelGetMethods.js
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ export default (_this: Parcel) => ({
_this._log = true;
_this._logName = name;
console.log(`Parcel data: ${name} `);
console.log(JSON.parse(JSON.stringify(_this.data)));
_this.toConsole();
return _this;
},

Expand All @@ -111,5 +111,11 @@ export default (_this: Parcel) => ({
_this.dispatch(changeRequest);
}
});
},

// Debug methods

toConsole: () => {
console.log(JSON.parse(JSON.stringify(_this.data)));
}
});
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);
};
2 changes: 1 addition & 1 deletion packages/react-dataparcels/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,6 @@
},
"dependencies": {
"dataparcels": "^0.16.0-0",
"unmutable": "^0.34.0"
"unmutable": "^0.37.0"
}
}
Loading

0 comments on commit 200f9a8

Please sign in to comment.