Coder Social home page Coder Social logo

back-kit-engine's Introduction

back-kit-engine 🦦️

Coverage Status Mia-Platform

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

How to install

# npm
npm i @micro-lc/back-kit-engine

# yarn
yarn add @micro-lc/back-kit-engine

Event Factory

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

BK Events

There is a set of events already registered by including the factory in your code. A full list can be found here

back-kit-engine's People

Contributors

amountainram avatar clabene avatar epessina avatar ianfar96 avatar liliumcandidum avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Forkers

clabene

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.