Skip to content

Commit

Permalink
fix(docz-core): add watcher outside of update method scope
Browse files Browse the repository at this point in the history
  • Loading branch information
pedronauck committed Sep 11, 2018
1 parent ea88841 commit 18c744d
Showing 1 changed file with 19 additions and 16 deletions.
35 changes: 19 additions & 16 deletions packages/docz-core/src/states/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,19 +41,22 @@ const updateConfig = (config: Config) => async (p: Params) => {
}
}

export const state = (config: Config): State => ({
init: updateConfig(config),
update: async params => {
const update = updateConfig(config)
const watcher = chokidar.watch(finds('docz'), {
cwd: paths.root,
persistent: true,
})

watcher.on('add', async () => update(params))
watcher.on('change', async () => update(params))
watcher.on('unlink', async () => update(params))

return () => watcher.close()
},
})
export const state = (config: Config): State => {
const watcher = chokidar.watch(finds('docz'), {
cwd: paths.root,
persistent: true,
})

return {
init: updateConfig(config),
update: async params => {
const update = updateConfig(config)

watcher.on('add', async () => update(params))
watcher.on('change', async () => update(params))
watcher.on('unlink', async () => update(params))

return () => watcher.close()
},
}
}

0 comments on commit 18c744d

Please sign in to comment.