Skip to content

Commit 5593c80

Browse files
committed
refactor: removing module federation-based plugins
The code removed in this commit existed to load plugins via webpack module federation. It was never intended to be included in this version of plugins. We don’t intend to use module federation, and are instead investing in a micro-frontend framework like Piral.
1 parent d0b0dd2 commit 5593c80

File tree

7 files changed

+8
-129
lines changed

7 files changed

+8
-129
lines changed

src/plugins/Plugin.jsx

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
import React from 'react';
22

3-
import PluginComponent from './PluginComponent';
43
import PluginIframe from './PluginIframe';
54
import PluginErrorBoundary from './PluginErrorBoundary';
65

76
import {
8-
COMPONENT_PLUGIN, IFRAME_PLUGIN,
7+
IFRAME_PLUGIN,
98
} from './data/constants';
109
import { pluginShape } from './data/shapes';
1110

@@ -16,11 +15,6 @@ export default function Plugin({ plugin, ...props }) {
1615

1716
let renderer = null;
1817
switch (plugin.type) {
19-
case COMPONENT_PLUGIN:
20-
renderer = (
21-
<PluginComponent plugin={plugin} {...props} />
22-
);
23-
break;
2418
case IFRAME_PLUGIN:
2519
renderer = (
2620
<PluginIframe plugin={plugin} {...props} />

src/plugins/PluginComponent.jsx

Lines changed: 0 additions & 31 deletions
This file was deleted.

src/plugins/data/constants.js

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,5 @@
1-
// These are intended to represent three different plugin types. They're not fully used yet.
2-
3-
// Different plugins of different types would have different loading functionality.
4-
export const COMPONENT_PLUGIN = 'COMPONENT_PLUGIN'; // loads JS script then loads react component from its exports
5-
export const SCRIPT_PLUGIN = 'SCRIPT_PLUGIN'; // loads JS script
1+
// TODO: We expect other plugin types to be added here, such as LTI_PLUGIN and BUILD_TIME_PLUGIN.
62
export const IFRAME_PLUGIN = 'IFRAME_PLUGIN'; // loads iframe at the URL, rather than loading a JS file.
7-
export const LTI_PLUGIN = 'LTI_PLUGIN'; // loads LTI iframe at the URL, rather than loading a JS file.
83

94
// Plugin lifecycle events
105
export const PLUGIN_MOUNTED = 'PLUGIN_MOUNTED';

src/plugins/data/hooks.js

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,9 @@
11
import {
2-
lazy, useCallback, useEffect, useLayoutEffect, useMemo, useRef, useState,
2+
useCallback, useEffect, useLayoutEffect, useMemo, useRef, useState,
33
} from 'react';
4-
import { loadPluginComponent, unloadDynamicScript } from './utils';
54
import { getConfig } from '../../config';
65
import { PLUGIN_MOUNTED, PLUGIN_READY, PLUGIN_UNMOUNTED } from './constants';
76

8-
export function useDynamicPluginComponent(plugin) {
9-
// When this component unmounts, see if we should unload the script that provided it.
10-
// Note that this is not guaranteed to unload the script if other consumers are still using one
11-
// of its exports.
12-
useEffect(() => () => {
13-
unloadDynamicScript(plugin.url);
14-
}, []);
15-
16-
return lazy(loadPluginComponent(plugin));
17-
}
18-
197
export function usePluginSlot(id) {
208
if (getConfig().plugins[id] !== undefined) {
219
return getConfig().plugins[id];

src/plugins/data/shapes.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
/* eslint-disable import/prefer-default-export */
22
import PropTypes from 'prop-types';
3-
import { COMPONENT_PLUGIN, IFRAME_PLUGIN } from './constants';
3+
import { IFRAME_PLUGIN } from './constants';
44

55
export const pluginShape = PropTypes.shape({
66
scope: PropTypes.string,
77
module: PropTypes.string,
88
url: PropTypes.string.isRequired,
9-
type: PropTypes.oneOf([COMPONENT_PLUGIN, IFRAME_PLUGIN]).isRequired,
9+
type: PropTypes.oneOf([IFRAME_PLUGIN]).isRequired,
1010
// This is a place for us to put any generic props we want to pass to the component. We need it.
1111
props: PropTypes.object, // eslint-disable-line react/forbid-prop-types
1212
});

src/plugins/data/utils.js

Lines changed: 0 additions & 68 deletions
This file was deleted.

src/plugins/index.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
export { useDynamicPluginComponent, usePluginSlot } from './data/hooks';
1+
export {
2+
usePluginSlot,
3+
} from './data/hooks';
24
export {
35
default as Plugin,
46
} from './Plugin';
@@ -9,6 +11,5 @@ export {
911
default as PluginSlot,
1012
} from './PluginSlot';
1113
export {
12-
COMPONENT_PLUGIN,
1314
IFRAME_PLUGIN,
1415
} from './data/constants';

0 commit comments

Comments
 (0)