Skip to content

Commit

Permalink
refactor: removing module federation-based plugins
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
davidjoy committed May 26, 2023
1 parent aa5f8aa commit e73d697
Show file tree
Hide file tree
Showing 7 changed files with 8 additions and 129 deletions.
8 changes: 1 addition & 7 deletions src/plugins/Plugin.jsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
import React from 'react';

import PluginComponent from './PluginComponent';
import PluginIframe from './PluginIframe';
import PluginErrorBoundary from './PluginErrorBoundary';

import {
COMPONENT_PLUGIN, IFRAME_PLUGIN,
IFRAME_PLUGIN,
} from './data/constants';
import { pluginShape } from './data/shapes';

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

let renderer = null;
switch (plugin.type) {
case COMPONENT_PLUGIN:
renderer = (
<PluginComponent plugin={plugin} {...props} />
);
break;
case IFRAME_PLUGIN:
renderer = (
<PluginIframe plugin={plugin} {...props} />
Expand Down
31 changes: 0 additions & 31 deletions src/plugins/PluginComponent.jsx

This file was deleted.

7 changes: 1 addition & 6 deletions src/plugins/data/constants.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,5 @@
// These are intended to represent three different plugin types. They're not fully used yet.

// Different plugins of different types would have different loading functionality.
export const COMPONENT_PLUGIN = 'COMPONENT_PLUGIN'; // loads JS script then loads react component from its exports
export const SCRIPT_PLUGIN = 'SCRIPT_PLUGIN'; // loads JS script
// TODO: We expect other plugin types to be added here, such as LTI_PLUGIN and BUILD_TIME_PLUGIN.
export const IFRAME_PLUGIN = 'IFRAME_PLUGIN'; // loads iframe at the URL, rather than loading a JS file.
export const LTI_PLUGIN = 'LTI_PLUGIN'; // loads LTI iframe at the URL, rather than loading a JS file.

// Plugin lifecycle events
export const PLUGIN_MOUNTED = 'PLUGIN_MOUNTED';
Expand Down
14 changes: 1 addition & 13 deletions src/plugins/data/hooks.js
Original file line number Diff line number Diff line change
@@ -1,21 +1,9 @@
import {
lazy, useCallback, useEffect, useLayoutEffect, useMemo, useRef, useState,
useCallback, useEffect, useLayoutEffect, useMemo, useRef, useState,
} from 'react';
import { loadPluginComponent, unloadDynamicScript } from './utils';
import { getConfig } from '../../config';
import { PLUGIN_MOUNTED, PLUGIN_READY, PLUGIN_UNMOUNTED } from './constants';

export function useDynamicPluginComponent(plugin) {
// When this component unmounts, see if we should unload the script that provided it.
// Note that this is not guaranteed to unload the script if other consumers are still using one
// of its exports.
useEffect(() => () => {
unloadDynamicScript(plugin.url);
}, []);

return lazy(loadPluginComponent(plugin));
}

export function usePluginSlot(id) {
if (getConfig().plugins[id] !== undefined) {
return getConfig().plugins[id];
Expand Down
4 changes: 2 additions & 2 deletions src/plugins/data/shapes.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
/* eslint-disable import/prefer-default-export */
import PropTypes from 'prop-types';
import { COMPONENT_PLUGIN, IFRAME_PLUGIN } from './constants';
import { IFRAME_PLUGIN } from './constants';

export const pluginShape = PropTypes.shape({
scope: PropTypes.string,
module: PropTypes.string,
url: PropTypes.string.isRequired,
type: PropTypes.oneOf([COMPONENT_PLUGIN, IFRAME_PLUGIN]).isRequired,
type: PropTypes.oneOf([IFRAME_PLUGIN]).isRequired,
// This is a place for us to put any generic props we want to pass to the component. We need it.
props: PropTypes.object, // eslint-disable-line react/forbid-prop-types
});
68 changes: 0 additions & 68 deletions src/plugins/data/utils.js

This file was deleted.

5 changes: 3 additions & 2 deletions src/plugins/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
export { useDynamicPluginComponent, usePluginSlot } from './data/hooks';
export {
usePluginSlot,
} from './data/hooks';
export {
default as Plugin,
} from './Plugin';
Expand All @@ -9,6 +11,5 @@ export {
default as PluginSlot,
} from './PluginSlot';
export {
COMPONENT_PLUGIN,
IFRAME_PLUGIN,
} from './data/constants';

0 comments on commit e73d697

Please sign in to comment.