Skip to content

Commit f25dc72

Browse files
author
Ives van Hoorne
committed
Adjust editor size
1 parent 4b1ec7a commit f25dc72

File tree

4 files changed

+13
-16
lines changed

4 files changed

+13
-16
lines changed

content/docs/state-and-lifecycle.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,13 @@ So far we have only learned one way to update the UI.
1313

1414
We call `ReactDOM.render()` to change the rendered output:
1515

16-
[Run example.](source:examples/single-file-examples/src/state-and-lifecycle/state-and-lifecycle-1.js{11})
16+
[Run example.](source:examples/single-file-examples/src/state-and-lifecycle/state-and-lifecycle-1.js{11}?editorsize=70)
1717

1818
In this section, we will learn how to make the `Clock` component truly reusable and encapsulated. It will set up its own timer and update itself every second.
1919

2020
We can start by encapsulating how the clock looks:
2121

22-
[Run example.](source:examples/single-file-examples/src/state-and-lifecycle/state-and-lifecycle-2.js{6,7,8,9,14})
22+
[Run example.](source:examples/single-file-examples/src/state-and-lifecycle/state-and-lifecycle-2.js{6,7,8,9,14}?editorsize=70)
2323

2424
However, it misses a crucial requirement: the fact that the `Clock` sets up a timer and updates the UI every second should be an implementation detail of the `Clock`.
2525

@@ -52,7 +52,7 @@ You can convert a functional component like `Clock` to a class in five steps:
5252

5353
5. Delete the remaining empty function declaration.
5454

55-
[Run example.](source:examples/single-file-examples/src/state-and-lifecycle/state-and-lifecycle-3.js)
55+
[Run example.](source:examples/single-file-examples/src/state-and-lifecycle/state-and-lifecycle-3.js?editorsize=70)
5656

5757
`Clock` is now defined as a class rather than a function.
5858

@@ -121,7 +121,7 @@ We will later add the timer code back to the component itself.
121121

122122
The result looks like this:
123123

124-
[Run example.](source:examples/single-file-examples/src/state-and-lifecycle/state-and-lifecycle-4.js{5,6,7,8,14,20})
124+
[Run example.](source:examples/single-file-examples/src/state-and-lifecycle/state-and-lifecycle-4.js{5,6,7,8,14,20}?editorsize=70)
125125

126126
Next, we'll make the `Clock` set up its own timer and update itself every second.
127127

@@ -192,7 +192,7 @@ Finally, we will implement a method called `tick()` that the `Clock` component w
192192

193193
It will use `this.setState()` to schedule updates to the component local state:
194194

195-
[Run example.](source:examples/single-file-examples/src/state-and-lifecycle/state-and-lifecycle-5.js{18,19,20,21,22})
195+
[Run example.](source:examples/single-file-examples/src/state-and-lifecycle/state-and-lifecycle-5.js{18,19,20,21,22}?editorsize=70)
196196

197197
Now the clock ticks every second.
198198

@@ -321,15 +321,15 @@ This also works for user-defined components:
321321

322322
The `FormattedDate` component would receive the `date` in its props and wouldn't know whether it came from the `Clock`'s state, from the `Clock`'s props, or was typed by hand:
323323

324-
[Run example.](source:examples/single-file-examples/src/state-and-lifecycle/state-and-lifecycle-6.js{4,5,6})
324+
[Run example.](source:examples/single-file-examples/src/state-and-lifecycle/state-and-lifecycle-6.js{4,5,6}?editorsize=70)
325325

326326
This is commonly called a "top-down" or "unidirectional" data flow. Any state is always owned by some specific component, and any data or UI derived from that state can only affect components "below" them in the tree.
327327

328328
If you imagine a component tree as a waterfall of props, each component's state is like an additional water source that joins it at an arbitrary point but also flows down.
329329

330330
To show that all components are truly isolated, we can create an `App` component that renders three `<Clock>`s:
331331

332-
[Run example.](source:examples/single-file-examples/src/state-and-lifecycle/state-and-lifecycle-7/index.js{9,10,11})
332+
[Run example.](source:examples/single-file-examples/src/state-and-lifecycle/state-and-lifecycle-7/index.js{9,10,11}?editorsize=70)
333333

334334
Each `Clock` sets up its own timer and updates independently.
335335

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838
"gatsby-plugin-sharp": "^1.6.2",
3939
"gatsby-plugin-twitter": "^1.0.10",
4040
"gatsby-remark-autolink-headers": "^1.4.4",
41-
"gatsby-remark-codesandbox": "^1.2.21",
41+
"gatsby-remark-codesandbox": "^1.2.23",
4242
"gatsby-remark-copy-linked-files": "^1.5.2",
4343
"gatsby-remark-images": "^1.5.11",
4444
"gatsby-remark-prismjs": "^1.2.1",

src/components/MarkdownPage/MarkdownPage.js

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,9 @@ class MarkdownPage extends React.Component {
2727

2828
codeSandboxLinks.forEach(link => {
2929
link.onclick = e => {
30-
const [codeBlock] = Array.prototype.filter.call(
31-
link.parentNode.children,
32-
node => node.className === 'gatsby-highlight',
33-
);
30+
const codeBlock = link.previousSibling;
3431

35-
if (codeBlock) {
32+
if (codeBlock && codeBlock.className === 'gatsby-highlight') {
3633
const [child] = codeBlock.children;
3734
if (child && child.tagName !== 'IFRAME') {
3835
e.preventDefault();

yarn.lock

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3934,9 +3934,9 @@ gatsby-remark-autolink-headers@^1.4.4:
39343934
mdast-util-to-string "^1.0.2"
39353935
unist-util-visit "^1.1.1"
39363936

3937-
gatsby-remark-codesandbox@^1.2.21:
3938-
version "1.2.21"
3939-
resolved "https://registry.yarnpkg.com/gatsby-remark-codesandbox/-/gatsby-remark-codesandbox-1.2.21.tgz#2a14bc7c97d296a03f4e7bd16f7f46a00ee62ca4"
3937+
gatsby-remark-codesandbox@^1.2.23:
3938+
version "1.2.23"
3939+
resolved "https://registry.yarnpkg.com/gatsby-remark-codesandbox/-/gatsby-remark-codesandbox-1.2.23.tgz#7da743b0160bf6ef0a8518f9fab4de5881e98741"
39403940
dependencies:
39413941
babel-runtime "^6.26.0"
39423942
git-branch "^1.0.0"

0 commit comments

Comments
 (0)