Skip to content

Commit

Permalink
cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
nitin42 committed Jun 11, 2018
1 parent cea88de commit d0f7568
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 33 deletions.
33 changes: 9 additions & 24 deletions faq.md
Expand Up @@ -7,41 +7,26 @@ Let's say we have a class component `MyDocument` -
```jsx
class MyDocument extends React.Component {
render() {
return (
<Document>
<Text>Hello World!</Text>
</Document>
)
return <Text>Hello World!</Text>
}
}
```

Now this will be transpiled to

```js
_createClass(MyDocument, [{
key: 'render',
value: function render() {
return _react2.default.createElement(
_src.Document,
null,
_react2.default.createElement(
_src.Text,
null,
'Hello World!'
)
);
}
}]);
_createClass(MyDocument, [
{
key: 'render',
value: function render() {
return _react2.default.createElement(_src.Text, null, 'Hello World!');
},
},
]);
```

Thus we can use the above data to create an instance depending upon the type of an element. For eg - If the type of an element is 'TEXT', we create an instance `new Text(root, props)` and then render the component.

#### What role does the `parse` function plays?

The job of `parse` function is to call the render method on our document property (remember this was in our host config `parentInstance.document = child`) and render
all the children and props.

#### How can I create my own components i.e component API?

Well, it totally depends on you to structure the component API. But some things will remain unchanged if you create your own, `appendChild`
Expand Down
13 changes: 5 additions & 8 deletions part-three.md
@@ -1,7 +1,7 @@
# Part-IV
# Part-III

This is the last section of our tutorial. We've done all the heavy work, created a React reconciler, created a public interface to
our reconciler, designed the component API and also created a function to parse the input component.
our reconciler, designed the component API.

Now we just need to create a `render` method to flush everything to the host environment.

Expand All @@ -12,7 +12,6 @@ Now we just need to create a `render` method to flush everything to the host env
import fs from 'fs';
import { createElement } from '../utils/createElement';
import { WordRenderer } from './renderer';
import parse from './parse';

// renders the component
async function render(element, filePath) {
Expand All @@ -22,12 +21,10 @@ async function render(element, filePath) {

WordRenderer.updateContainer(element, node, null);

const output = parse(container).toBuffer();

const stream = fs.createWriteStream(filePath);

await new Promise((resolve, reject) => {
output.doc.generate(stream, Events(filePath, resolve, reject));
container.doc.generate(stream, Events(filePath, resolve, reject));
});
}

Expand Down Expand Up @@ -64,13 +61,13 @@ that contains information about a component, it's input and output.
This function takes an element, a root container, a parent component, a callback function and schedules a top level update.
This is done by scheduling an update with the current fiber and a priority level (depends on the context)

Finally we parse our input component to render all the children and props and generate the word document by creating a write stream.
Finally, we render all the children and generate the word document by creating a write stream.

Still having some doubts? Check out the [FAQs](./faq.md).

Congrats! You've have successfully completed the tutorial. Full source code for the tutorial is already available in this repository ([src](./src)). If you want to read the whole source code then follow this order -

[`reconciler`](./src/reconciler/index.js) => [`components`](./src/components/) => [`createElement`](./src/utils/createElement) => [`parse the input component`](./src/parse/index.js) => [`render method`](./src/render/index.js)
[`reconciler`](./src/reconciler/index.js) => [`components`](./src/components/) => [`createElement`](./src/utils/createElement) => [`render method`](./src/render/index.js)

If you've enjoyed reading the tutorial then watch/star this repo and follow me on [Twitter](http://twitter.com/NTulswani) for updates.

Expand Down
2 changes: 1 addition & 1 deletion part-two.md
Expand Up @@ -9,7 +9,7 @@ of `createElement` method.

For our example, we'll only implement one component `Text`. A `Text` component is the main component for adding the text to our document.

> Text component, however, doesn't create specific text node. It works differently when compared to the DOM APIs.
> Text component, however, doesn't create specific text node. It has different semantics when compared to the DOM APIs.
We will first create a root container (remember `rootContainerInstance` in our reconciler ?) for our components. This is responsible
for creating a document instance for [officegen](https://github.com/Ziv-Barber/officegen).
Expand Down

0 comments on commit d0f7568

Please sign in to comment.