-
Notifications
You must be signed in to change notification settings - Fork 456
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(plugins): improve plugins load #639
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A big pr will help the project a lot
app/plugins/index.js
Outdated
|
||
export default Object.assign(externalPlugins, core) | ||
class PluginsService { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Migrate to functonal component
app/plugins/index.js
Outdated
} | ||
} | ||
|
||
export default new PluginsService() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
export default new PluginsService() | |
export { getAllPlugins, getExternalPlugins, getCorePlugins } |
app/plugins/externalPlugins.js
Outdated
@@ -50,59 +50,64 @@ const getPluginName = (pluginPath) => { | |||
|
|||
const plugins = {} | |||
|
|||
const pluginsWatcher = chokidar.watch(modulesDirectory, { depth: 1 }) | |||
function setupPluginsWatcher() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you can use
function setupPluginsWatcher() { | |
(() => {...})() |
|
||
global.React = React | ||
global.ReactDOM = ReactDOM | ||
global.isBackground = true | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
const corePlugins = getCorePlugins()
app/background/background.js
Outdated
|
||
on('initializePluginAsync', ({ name }) => { | ||
console.group(`Initialize async plugin ${name}`) | ||
|
||
try { | ||
const plugin = plugins[name] || window.require(`${modulesDirectory}/${name}`) | ||
const plugin = PluginsService.getCorePlugins()[name] || window.require(`${modulesDirectory}/${name}`) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
const plugin = corePlugins[name] || window.require(`${modulesDirectory}/${name}`)
@@ -32,6 +32,6 @@ const fn = ({ term, display, actions }) => flow( | |||
filter(notMatch(term)), | |||
map(pluginToResult(actions)), | |||
display | |||
)(plugins) | |||
)(PluginsService.getAllPlugins()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
)(getAllPlugins())
app/lib/initializePlugins.js
Outdated
const plugin = plugins[name] | ||
if (plugin.onMessage) plugin.onMessage(data) | ||
}) | ||
listenToAsyncMessages() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this function is not necessary
app/lib/initializePlugins.js
Outdated
}) | ||
listenToAsyncMessages() | ||
|
||
const allPlugins = PluginsService.getAllPlugins() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
const allPlugins = PluginsService.getAllPlugins()
on('plugin.message', ({ name, data }) => {
const plugin = allPlugins[name]
if (plugin.onMessage) plugin.onMessage(data)
})
4907c74
to
d3f0247
Compare
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