Browse Source

feat: get hot reloading working for js code snippets

main
Dustin Schau 6 years ago
parent
commit
d83238caf0
  1. 3
      plugins/gatsby-transformer-home-example-code/gatsby-node.js
  2. 4
      src/components/CodeEditor/CodeEditor.js

3
plugins/gatsby-transformer-home-example-code/gatsby-node.js

@ -1,6 +1,5 @@
const crypto = require(`crypto`); const crypto = require(`crypto`);
// docblock goes here
const createContentDigest = obj => const createContentDigest = obj =>
crypto crypto
.createHash(`md5`) .createHash(`md5`)
@ -9,7 +8,7 @@ const createContentDigest = obj =>
// Store code snippets in GraphQL for the home page examples. // Store code snippets in GraphQL for the home page examples.
// Snippets will be matched with markdown templates of the same name. // Snippets will be matched with markdown templates of the same name.
exports.onCreateNode = async ({node, loadNodeContent, actions}) => { exports.onCreateNode = async ({actions, node, loadNodeContent}) => {
const {createNode} = actions; const {createNode} = actions;
const {absolutePath, ext, name, relativeDirectory, sourceInstanceName} = node; const {absolutePath, ext, name, relativeDirectory, sourceInstanceName} = node;

4
src/components/CodeEditor/CodeEditor.js

@ -35,6 +35,10 @@ class CodeEditor extends Component {
componentDidUpdate(prevProps, prevState) { componentDidUpdate(prevProps, prevState) {
if (prevState.compiled !== this.state.compiled) { if (prevState.compiled !== this.state.compiled) {
this._render(); this._render();
} else if (this.props.code !== prevProps.code) {
this.setState({
code: this.props.code,
});
} }
} }

Loading…
Cancel
Save