You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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
As a developer, I'd like to have a minimal plugin system so that I can organize common features into individual opt-in plugins that I can re-use across projects.
Driving principles
Protection of the loading sequence (Eager, Lazy, Delayed)
Separation of concerns
Increase code testability
Keep PIS score at 100
Technical
plugins can be loaded via the await withPlugin(<path>, <options>) method
protect the loading phases by moving the logic inside lib-franklin.js
Offer pre/post hooks for the Eager/Lazy/Delayed phases so plugins can inject logic at the most appropriate moment in the loading lifecycle
pre/post hooks get the options object as well as a map of plugins that expose an API. For instance
// this isn't publicly exposed and only available to direct importersexportfunctionaMethodNotExposedInTheApi(…){…}// this is publicly exposed and passed down in the pre/post hooksexportconstAPI={aMethodExposedInTheApi: (…)=>{…}}// defining a running before the Eager phaseexportasyncfunctionpreEager(options,plugins){// options.myOption// plugins.myPlugin.myMethod(…)}
Plugins can expose a limited API usable via const myApi = await withPlugin('./plugins/myPlugin.js', …);
Simple eager/lazy/delayed hooks in the project via the usual load* methods and a configurable delayed timeout:
Alias pre* in the plugin to load*, so that plugins that don't need both pre and post hooks are closer to the project's APIs
Add option to make some plugins "blocking" if they are needed in the eager phase, versus non-blocking (by default) if they are only needed in the lazy phase:
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Use case
As a developer, I'd like to have a minimal plugin system so that I can organize common features into individual opt-in plugins that I can re-use across projects.
Driving principles
Technical
await withPlugin(<path>, <options>)
methodlib-franklin.js
pre
/post
hooks for theEager
/Lazy
/Delayed
phases so plugins can inject logic at the most appropriate moment in the loading lifecyclepre
/post
hooks get theoptions
object as well as a map of plugins that expose an API. For instanceconst myApi = await withPlugin('./plugins/myPlugin.js', …);
load*
methods and a configurable delayed timeout:<link rel="modulepreload">
for the plugins to speed up page loadthis
)The loading sequence will be:
init
of all pluginspreEager
of all pluginsloadEager
for the projectpostEager
of all pluginspreLazy
of all pluginsloadLazy
for the projectpostLazy
of all pluginspreDelayed
of all pluginsloadDelayed
for the projectpostDelayed
of all pluginsPerformance comparison with
main
Fix #137
Test URLs: