feat(plugins): improve plugins load#639
Merged
Merged
Conversation
Member
ogustavo-pereira
left a comment
There was a problem hiding this comment.
A big pr will help the project a lot
| import getExternalPlugins from './externalPlugins' | ||
|
|
||
| export default Object.assign(externalPlugins, core) | ||
| class PluginsService { |
Member
There was a problem hiding this comment.
Migrate to functonal component
| } | ||
| } | ||
|
|
||
| export default new PluginsService() |
Member
There was a problem hiding this comment.
Suggested change
| export default new PluginsService() | |
| export { getAllPlugins, getExternalPlugins, getCorePlugins } |
| const plugins = {} | ||
|
|
||
| const pluginsWatcher = chokidar.watch(modulesDirectory, { depth: 1 }) | ||
| function setupPluginsWatcher() { |
Member
There was a problem hiding this comment.
you can use
Suggested change
| function setupPluginsWatcher() { | |
| (() => {...})() |
| global.React = React | ||
| global.ReactDOM = ReactDOM | ||
| global.isBackground = true | ||
|
|
Member
There was a problem hiding this comment.
const corePlugins = getCorePlugins()|
|
||
| try { | ||
| const plugin = plugins[name] || window.require(`${modulesDirectory}/${name}`) | ||
| const plugin = PluginsService.getCorePlugins()[name] || window.require(`${modulesDirectory}/${name}`) |
Member
There was a problem hiding this comment.
const plugin = corePlugins[name] || window.require(`${modulesDirectory}/${name}`)| map(pluginToResult(actions)), | ||
| display | ||
| )(plugins) | ||
| )(PluginsService.getAllPlugins()) |
| const plugin = plugins[name] | ||
| if (plugin.onMessage) plugin.onMessage(data) | ||
| }) | ||
| listenToAsyncMessages() |
Member
There was a problem hiding this comment.
I think this function is not necessary
| }) | ||
| listenToAsyncMessages() | ||
|
|
||
| const allPlugins = PluginsService.getAllPlugins() |
Member
There was a problem hiding this comment.
const allPlugins = PluginsService.getAllPlugins()
on('plugin.message', ({ name, data }) => {
const plugin = allPlugins[name]
if (plugin.onMessage) plugin.onMessage(data)
})4907c74 to
d3f0247
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR should make Cerebro more performant.
The idea of the double renderer process was to make the second take care of the heavier tasks.
However, it was doing too much work by duplicating tasks that are already done in the main renderer.
The loading of plugins and the control over the addition of new plugins was being done in both renderers, which led to an unnecessary waste of resources (duplicated chockidar instances watching folders, double loading of plugins)
With this PR, we make the second renderer do what it is supposed to do: take care of the async loads of plugins
ref #118