Skip to content

Commit

Permalink
fix(gatsby-theme-docz): hot reload
Browse files Browse the repository at this point in the history
  • Loading branch information
pedronauck committed Feb 19, 2019
1 parent bc1303d commit bf4e440
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 6 deletions.
3 changes: 0 additions & 3 deletions core/docz/src/utils/createState.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,6 @@ export function create<T = any>(initial: T): State<T> {
public componentWillUnmount(): void {
listeners.clear()
}
public shouldComponentUpdate(nextProps: any, nextState: any): boolean {
return !equal(this.state, nextState)
}
public render(): React.ReactNode {
return (
<ctx.Provider value={this.state}>{this.props.children}</ctx.Provider>
Expand Down
1 change: 1 addition & 0 deletions core/gatsby-theme-docz/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
"gatsby-plugin-compile-es6-packages": "^1.0.6",
"gatsby-plugin-manifest": "^2.0.17",
"gatsby-plugin-react-helmet": "^3.0.6",
"lodash": "^4.17.11",
"prop-types": "^15.7.2",
"react": "^16.8.2",
"react-dom": "^16.8.2",
Expand Down
13 changes: 10 additions & 3 deletions core/gatsby-theme-docz/src/node/createPagesStatefully.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@ const path = require('path')
const chokidar = require('chokidar')
const { Entries } = require('docz-core')
const { parseConfig } = require('../utils/parseConfig')
const { get } = require('lodash/fp')

const getEntry = async (filepath, entries) => {
const map = await entries.get()
return map[filepath]
return get(filepath, map)
}

const mountRoute = (base = '/', route) => {
Expand All @@ -25,8 +26,8 @@ module.exports = async ({ store, actions }, opts) => {
})

const handleCreatePage = async filepath => {
const component = path.join(paths.root, filepath)
const entry = await getEntry(filepath, entries)
const component = path.join(paths.root, filepath)

if (entry) {
createPage({
Expand All @@ -50,10 +51,16 @@ module.exports = async ({ store, actions }, opts) => {
}
}

const allEntries = await entries.get()
await Promise.all(
Object.values(allEntries).map(async value => {
handleCreatePage(value.filepath)
})
)

return new Promise((resolve, reject) => {
watcher
.on('add', handleCreatePage)
.on('change', handleCreatePage)
.on('unlink', handleDeletePage)
.on('ready', () => resolve())
.on('error', err => reject(err))
Expand Down

0 comments on commit bf4e440

Please sign in to comment.