-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: allow plugins to hook client and server rendering
- Loading branch information
Showing
8 changed files
with
203 additions
and
59 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
// webpack-injected script | ||
// eslint-disable-next-line no-undef | ||
const hooks = $$RJS_VARS$$.HOOKS_CLIENT; | ||
|
||
export default hooks; |
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
// webpack-injected script | ||
// eslint-disable-next-line no-undef | ||
const hooks = $$RJS_VARS$$.HOOKS_SERVER; | ||
|
||
export default hooks; |
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
// @flow | ||
|
||
import frameworkConfig from '../shared/framework-config'; | ||
|
||
type PluginHooks = { | ||
client: string, | ||
server: string, | ||
}; | ||
|
||
type FrameworkPlugin = { | ||
getInstallableDependencies: ?() => { [string]: string }, | ||
getHooks: ?(() => PluginHooks), | ||
}; | ||
|
||
/** | ||
* Loads and returns ReworkJS plugin instances (eg. @reworkjs/redux) | ||
*/ | ||
export default function getPlugins(): FrameworkPlugin[] { | ||
const pluginConfigs = frameworkConfig.plugins; | ||
|
||
if (!pluginConfigs) { | ||
return []; | ||
} | ||
|
||
const plugins = []; | ||
for (const pluginConfig of pluginConfigs) { | ||
const pluginUri = typeof pluginConfig === 'string' ? pluginConfig : pluginConfig.plugin; | ||
const config = typeof pluginConfig === 'string' ? null : pluginConfig.config; | ||
|
||
// $FlowIgnore | ||
const Plugin = require(pluginUri); | ||
const pluginInstance = new Plugin(config); | ||
|
||
plugins.push(pluginInstance); | ||
} | ||
|
||
return plugins; | ||
} | ||
|
||
export function getHooks(side: string): string[] { | ||
|
||
const hooks = []; | ||
|
||
for (const plugin of getPlugins()) { | ||
if (!plugin.getHooks) { | ||
continue; | ||
} | ||
|
||
const pluginHooks = plugin.getHooks(); | ||
if (pluginHooks[side]) { | ||
hooks.push(pluginHooks[side]); | ||
} | ||
} | ||
|
||
return hooks; | ||
} |
This file contains 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
This file contains 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
This file contains 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