Formatting updates.

This commit is contained in:
2020-10-06 07:55:41 -07:00
parent 7e64bbc9e3
commit b470727093
3 changed files with 78 additions and 78 deletions
+39 -39
View File
@@ -134,7 +134,7 @@ complete picture of the entire process. The more black-boxes we have
in our mental model the harder it will be for us to diagnose
performance problems.
* Markup in JavaScript: ~JSX~
* Markup in JavaScript: JSX
:PROPERTIES:
:EXPORT_FILE_NAME: manuscript/markup-in-javascript---jsx-.markua
:END:
@@ -170,8 +170,8 @@ parts do you see here?
#+BEGIN_SRC html
<div class="header">
<h1>Hello</h1>
<input type="submit" disabled />
<h1>Hello</h1>
<input type="submit" disabled />
</div>
#+END_SRC
@@ -195,9 +195,9 @@ This is what I'm thinking:
#+CAPTION: JSM - JavaScript Markup
#+BEGIN_SRC javascript
['div', { 'className': 'header' },
[['h1', {}, ['Hello']],
['input', { 'type': 'submit', 'disabled': 'disabled' }, []]
]
[['h1', {}, ['Hello']],
['input', { 'type': 'submit', 'disabled': 'disabled' }, []]
]
]
#+END_SRC
@@ -238,12 +238,12 @@ looks like:
# #+attr_leanpub: :line-numbers true
#+BEGIN_SRC javascript
React.createElement(
'div',
{ className: 'header' },
React.createElement('h1', {}, 'Hello'),
React.createElement(
'input',
{ type: 'submit', 'disabled': 'disabled' })
'div',
{ className: 'header' },
React.createElement('h1', {}, 'Hello'),
React.createElement(
'input',
{ type: 'submit', 'disabled': 'disabled' })
);
#+END_SRC
@@ -257,7 +257,7 @@ by leaving those aspects of the JSX compiler out.
So now that we've worked through JSX we're ready to tackle
~createElement~, the next item on our way to building our own React.
* Getting Ready to Render with ~createElement~
* Getting Ready to Render with createElement
:PROPERTIES:
:EXPORT_FILE_NAME: manuscript/getting-ready-to-render-with--createelement-.markua
:END:
@@ -271,13 +271,13 @@ React expects nodes defined as JavaScript objects that look like this:
#+BEGIN_SRC javascript
{
type: NODE_TYPE,
props: {
propA: VALUE,
propB: VALUE,
...
children: STRING | ARRAY
}
type: NODE_TYPE,
props: {
propA: VALUE,
propB: VALUE,
...
children: STRING | ARRAY
}
}
#+END_SRC
@@ -289,26 +289,26 @@ are not relevant to our study here.
#+BEGIN_SRC javascript
function createElement(node) {
// if array (not text, number, or other primitive)
if (typeof node === 'object') {
const [ tag, props, children ] = node;
return {
type: tag,
props: {
...props,
children: children.map(createElement)
}
};
}
// if array (not text, number, or other primitive)
if (typeof node === 'object') {
const [ tag, props, children ] = node;
return {
type: tag,
props: {
...props,
children: children.map(createElement)
}
};
}
// primitives like text or number
return {
type: 'TEXT',
props: {
nodeValue: node,
children: []
}
};
// primitives like text or number
return {
type: 'TEXT',
props: {
nodeValue: node,
children: []
}
};
}
#+END_SRC