Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Some times developers may need to make their plugins configurable, this may even be necessary in some cases. For example, a Google Analytics plugin may need to have a configuration for tracking code, as this value is different for every project.
In BlueBase it is very each to achieve this using the Configs API. Just set or get a config value anywhere in the plugin's business logic.
There are times, when you may need to define default values for plugin configurations as well. To do this, create a defaultConfigs
property in your plugin as shown below:
BlueBase will automatically set this value in the Config registry, if a custom value isn't provided.
In BlueBase, we use the following naming convention for configs belonging to plugins:
So, as shown in the example plugin above, a config foo
for a plugin with key example
becomes:
Plugins are the best way to add features to your BlueBase app.
It is recommended to keep all plugins in separate NPM packages. This helps us keep all aspects of an app modular. Adding or removing any feature becomes a matter of enabling or disabling a plugin.
A plugin can be used to do any of the following:
Subscribe to application's lifecycle events through Filters and override/modify application behaviour in a non-invasive way.
Add new or modify existing Components in the app. Moreover, plugins can wrap any component in Higher Order Components (HOCs).
Modify an existing Theme in the app, or extend it to create a new one. It is also possible to create a theme completely from scratch.
Add new or modify existing routes to the app.
Additionally, plugins can be configurable through Plugin Configs.
You can add support for any analytics service provider by using the bluebase.analytics.track
filter.
There are many ways to register new plugins in BlueBase:
The easiest way to add a new plugin is pass it as a prop to BlueBaseApp
.
Typically, in a large project you would be using the bluebase.ts
file to inject props to your main BlueBaseApp
component. It is basically same thing as above.
You can add new Plugins anywhere in the code by calling the set method of PluginRegistry:
Beware though, it is important when a plugin is added to the registry in the system lifecycle. Because all plugins must be initiated, adding them to the registry is not enough.
Plugins are initialised with the bluebase.plugins.initialize.all
filter, which in turn calls the bluebase.plugins.initialize
filter for each plugin. So you'll either need to run this filter yourself, or add a plugin before the main filter is executed by the system.
Even so, to avoid unknown issues it is recommended to use the first method (Through BlueBaseApp Component).
A plugin can register any number of themes. To do this simple set the themes
property of your plugin class.
The following guide needs to be added to Themes section.
Each object in the theme property can be a BlueBase Module. This mean each theme's code can be split into different bundles on web.
Be aware though, that if you use this approach, these bundles will be downloaded during boot time. This is because BlueBase needs know each theme's name
and key
to store them in registry.
If you want to split the theme so that they are downloaded only when selected, spilt the internal theme
property.
A plugin is just a JavaScript object that has the following properties:
Key
Type
Required
Description
name
string
yes
Name of the plugin.
key
string
no
This property is used as an ID throughout the system.
description
string
no
Plugin description.
version
string
no
Plugin version.
categories
string[]
no
icon
DynamicIconProps
no
These are props of the DynamicIcon component. This value can also be a thunk, i.e. a function that should return the props object. This function receives BlueBase context as param.
enabled
boolean
no
(Default = true) Flag to check if a plugin is enabled.
filters
FilterNestedCollection
no
components
ComponentCollection
no
themes
ThemeCollection
no
defaultConfigs
ConfigCollection
no
Categories are used in plugin listing pages. Currently, we recognise the following kind of plugins, but a developer may define his own category as well.
Key
Description
app
A plugin that is a sub-app in the system. This applies that when BlueBase is used as a bigger platform, and different features are represented as individuals apps inside the platform.
store
A plugin that provides a state store functionality. i.e. Redux.
router
A plugin that provides routing mechanism. i.e. react-router or React Navigation.
logging
A plugin that provides integration with a logging service. i.e. Sentry.
theme
A plugin that provides a single or multiple themes.
analytics
A plugin that provides integration with a logging service. i.e. Google Analytics.
.