-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #80 from smacker/use_initial_uast_prop
Use initial uast prop
- Loading branch information
Showing
7 changed files
with
150 additions
and
67 deletions.
There are no files selected for viewing
This file contains 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 |
---|---|---|
@@ -1,5 +1,5 @@ | ||
Just pass a UAST to the component and it will be rendered. | ||
|
||
```js | ||
<UASTViewer uast={smallUast} /> | ||
<UASTViewer initialUast={smallUast} /> | ||
``` |
This file contains 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 |
---|---|---|
@@ -1,29 +1,33 @@ | ||
Low-level component. Renders flat UAST. | ||
|
||
You might need it if you need control over the tree. | ||
Check [controlled example](#/Use cases?id=controlled) for more information. | ||
Check [controlled example](#/Use%20cases?id=controlled) for more information. | ||
|
||
If you need only render raw UAST without external control, consider using [UASTViewer](#/UI Components?id=uastviewer) component instead. | ||
If you need only render raw UAST without external control, consider using [UASTViewer](#/UI%20Components?id=uastviewer) component instead. | ||
|
||
```js | ||
const someUast = { | ||
1: { | ||
"InternalType": "CompilationUnit", | ||
"StartPosition": { "Offset": 0, "Line": 1, "Col": 1 }, | ||
"EndPosition": { "Offset": 446, "Line": 0, "Col": 0 }, | ||
"Roles": ["File"], | ||
"Children": [2], | ||
n: { | ||
"InternalType": "CompilationUnit", | ||
"StartPosition": { "Offset": 0, "Line": 1, "Col": 1 }, | ||
"EndPosition": { "Offset": 446, "Line": 0, "Col": 0 }, | ||
"Roles": ["File"], | ||
"Children": [{ id: 2, "_uast_node_type": true }], | ||
}, | ||
expanded: true | ||
}, | ||
2: { | ||
"InternalType": "LineComment", | ||
"Properties": { "internalRole": "comments", "text": " hello.java" }, | ||
"StartPosition": { "Offset": 0, "Line": 1, "Col": 1 }, | ||
"EndPosition": { "Offset": 13, "Line": 1, "Col": 14 }, | ||
"Roles": ["Comment"], | ||
"Children": [] | ||
n: { | ||
"InternalType": "LineComment", | ||
"Properties": { "internalRole": "comments", "text": " hello.java" }, | ||
"StartPosition": { "Offset": 0, "Line": 1, "Col": 1 }, | ||
"EndPosition": { "Offset": 13, "Line": 1, "Col": 14 }, | ||
"Roles": ["Comment"], | ||
"Children": [] | ||
} | ||
} | ||
}; | ||
|
||
<FlatUASTViewer flatUast={someUast} /> | ||
<FlatUASTViewer initialFlatUast={someUast} /> | ||
``` |
This file contains 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
This file contains 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
This file contains 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
This file contains 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 |
---|---|---|
@@ -0,0 +1,47 @@ | ||
import React from 'react'; | ||
import renderer from 'react-test-renderer'; | ||
import FlatUASTViewer from './FlatUASTViewer'; | ||
|
||
const flatUast2 = { | ||
1: { n: { name: 'original-node' }, expanded: true } | ||
}; | ||
|
||
const flatUast2Changed = { | ||
1: { n: { name: 'changed-node' }, expanded: true } | ||
}; | ||
|
||
describe('FlatUASTViewer', () => { | ||
it('uncontrolled', () => { | ||
const testRenderer = renderer.create( | ||
<FlatUASTViewer initialFlatUast={flatUast2} /> | ||
); | ||
|
||
const originalTree = testRenderer.toJSON(); | ||
|
||
testRenderer.update(<FlatUASTViewer initialFlatUast={flatUast2Changed} />); | ||
|
||
const updatedTree = testRenderer.toJSON(); | ||
|
||
expect(originalTree).toEqual(updatedTree); | ||
}); | ||
|
||
it('controlled', () => { | ||
const testRenderer = renderer.create( | ||
<FlatUASTViewer flatUast={flatUast2} /> | ||
); | ||
|
||
const originalTree = testRenderer.toJSON(); | ||
expect( | ||
testRenderer.root.findByProps({ className: 'uast-value string' }).children | ||
).toEqual(['original-node']); | ||
|
||
testRenderer.update(<FlatUASTViewer flatUast={flatUast2Changed} />); | ||
|
||
const updatedTree = testRenderer.toJSON(); | ||
|
||
expect(originalTree).not.toEqual(updatedTree); | ||
expect( | ||
testRenderer.root.findByProps({ className: 'uast-value string' }).children | ||
).toEqual(['changed-node']); | ||
}); | ||
}); |
This file contains 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