-
Notifications
You must be signed in to change notification settings - Fork 409
[Proposal] MapStore Modular Plugins
The goal of this improvement is to allow MapStore runtime load of plugins and their side-effects, to reduce the size of the initial JS downloaded and to allow to create extensions that do not affect the other pages.
- Lorenzo Natali
The proposal is for 2022.02.00 (first version integrated with GeOrchestra).
- TBD
- Under Discussion
- In Progress
- Completed
- Rejected
- Deferred
The improvement is proposed to make MapStore initial load faster, and allow sandboxing of plugins in the same time, by loading epics/reducers in a second time.
Actually MapStore provides some partial implementations for dynamic load of plugins:
-
loadPlugin/enabler: Defined as lazy plugins allows to load only the component of plugins. It is actually used by:
Print
,MapImport
,ThematicLayer
. It can be replaced by React.lazy + aconnect
for the enabler. So we may decide to deprecate this to clean up the code. - Extensions: allows to load a plugin for a module. Implemented by
withExtensions
enhancer applied to theStandardApp
allows to import plugins definition, but these are loaded only at the beginning.
The new feature should allow to:
- Load the code only when effectively required (e.g. when plugin is rendered)
- Allow the extensions to do it too.
After a first investigation and a implmentation attempt, we had a sync with dev team.
We noticed that @allyoucanmap already developed a similar work for GeoNode, that looks a lot similar to first attempt, so to illustrate the main concept we can refer to it:
Here the plugins.js
file imports dynamically the files:
an hook here:
is used in the page to load pending plugins:
The difference between this solution and the one we want to apply to the main project are:
- The plugins in this case are loaded in page context. For the main project we should instead load plugins once for all, incrementally on needing
- A nice to have is to create several modules, reusing and powering the extensions system, in order to make MapStore more modular.
- We need also to isolate the side effect as much as possible
A MapStore module is a React Component that implements a specific API to be loaded by MapStore asyncronously. Once the module is rendered, it can :
- Register reducers and epics to the store
- Define/ReDefine plugins implementations (maybe using with loadPlugin).
On unmount, the module can
- Unregister epics and reducers
- Optional:
- Deprecate
loadPlugin/enabler
in favor ofReact.lazy
- Replace actual implememtations of
loadPlugin/enabler
for MapImport/Print/ThematicLayer
- Deprecate
[TBD]