Skip to content

[Proposal] MapStore Modular Plugins

Lorenzo Natali edited this page Jun 16, 2022 · 11 revisions

#Overview

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.

Proposed By

  • Lorenzo Natali

Assigned to Release

The proposal is for 2022.02.00 (first version integrated with GeOrchestra).

State

  • TBD
  • Under Discussion
  • In Progress
  • Completed
  • Rejected
  • Deferred

Motivation

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.

Tecnical Background

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 + a connect 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 the StandardApp 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:

https://github.com/GeoNode/geonode-mapstore-client/blob/master/geonode_mapstore_client/client/js/plugins/index.js

an hook here:

https://github.com/GeoNode/geonode-mapstore-client/blob/master/geonode_mapstore_client/client/js/hooks/useLazyPlugins.js

is used in the page to load pending plugins:

https://github.com/GeoNode/geonode-mapstore-client/blob/master/geonode_mapstore_client/client/js/routes/Viewer.jsx#L76-L79

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

Proposal

Suggested Tasks

  • Deprecate

[TBD]