This library allows the interplay between React components and web components. Arisen from R&D development on mia-platform Backoffice library, it integrates a React-based design system on a more general web component library.
This library combines multiple features:
- on
.
: types, events and their event factory - on
./base
: base webcomponents to be extended to implement React/webcomponent interplay - on
./engine
: the core React/webcomponent lifecycle syncing engine for lit based webcomponent - on
./utils
: some useful utils - on
./west
: a readymade wrapper of JEST testing library to run unit testing on webcomponents implementing this library engine
# npm
npm i @micro-lc/back-kit-engine
# yarn
yarn add @micro-lc/back-kit-engine
If you don't know about the element-composer interface, please check out base superclasses
Event Factory is an utility that provides standardization to events
that webcomponents might
receive from the eventBus
set when connected to the DOM by the element-composer
.
factory
is a hybrid function which creates a hybrid function representing an EventBus
event. By providing factory
with a string you'll receive and event builder
type LoadingDataPayload = {
loading: boolean
}
const loadingData = factory<LoadingDataPayload>('loading-data')
in this example we specify the label every loadingData
event will have and the type of its payload. loadingData
now is
- a factory
- a filter/predicate
- and a label
as per the following snippet
const newLoadingDataEvent = loadingData({loading: true})
assert(loadingData.is(newLoadingDataEvent)) // true
assert(loadingData.is({label: 'any-label'})) // false
assert(loadingData.filter === 'loading-data') // true
factory
has also some options.
type FactoryOptions = {
scope?: string
divider?: string
aliases?: string | string[]
}
where the scope is prefixed to the label with the default divider /
. The divider can be overridden
const themeOptions = factory('options', {scope: 'theme'})
assert(themeOptions.label === 'theme/options')
const themeOptionsHashed = factory('options', {scope: 'theme', divider: '#'})
assert(themeOptions.label === 'theme#options')
finally a factory can receive aliases to events to ensure retro-compatibility
const loadingData = factory('loading', {scope: 'data', aliases: ['loading-data', 'whatever-data']})
assert(loadingData.is({label: 'whatever-data'})) // true
There is a set of events already registered by including the factory in your code. A full list can be found here