1. @mixspa/core
This is a library for create a micro-frontend app
@mixspa/core
Package: @mixspa/core
Created by: mixspa
Last modified: Wed, 06 Apr 2022 05:53:38 GMT
Version: 0.6.3
License: MIT
Downloads: 16
Repository: https://github.com/mixspa/mixspa-core

Install

npm install @mixspa/core
yarn add @mixspa/core

mixspa-core

mixspa-core is a base library for micro-frontend.

Current Status:

NPM Version
NPM Downloads
Build Status

NPM

What's the purpose for this library

The aim of this library what to be.

Architecture Micro-Web

The following targets:

  • A component or module can be an app to be load dynamically.
  • A component or module can choice a different framework or library by itself.
  • A component or module together with the backend service should have the whole and independent business.

What the api for this library?

1. Define an app

According the following to define a app. The id & render must be provided.

 import Mixspa from '@mixspa/core';

Mixspa.define({
  tag: 'app-demo', /* This name will be used for tag name */
  init: function(element) {
    /* will be call when custom element has been created */
  },
  render: function(element) {
    let attrName = element.getAttribute('data-name'); //
    /* will be call after custom element has been rendered */
  },
  unmount: function(element) {
    /* will be call when custom element has been removed */
  },
  update: function(element) {
    /* will be call when attribute has been changed */
  }
});

The Mixspa will create a custom element for one app.
About more details & the apis for element, please reference here:
CustomElement

2. Register one app

 import Mixspa from '@mixspa/core'

Mixspa.register({
  id: 'app-id',
  tag: 'app-demo',
  assets: ['https://www.app-demo.com/app.js', 'https://www.app-demo.com/app.css']
});

3. Get one app and load

 import Mixspa from '@mixspa/core'

Mixspa.getApp('app-id').load([Element]).then(app => {
  let el = document.createElement(app.tag);
  el.attributeOne = 'attribute one';
  document.getElementById('app-container').appendChild(el);
});

4. Event in Mixspa

 import Mixspa from '@mixspa/core'
/*
let listener = Mixspa.on('[module]:[action]', callback);  // bind event
*/
let listener = Mixspa.on('test:update', (message) => {
  console.log(message);
});

/*
Mixspa.off('[module]:[action]', listener);  // unbind event
*/
Mixspa.off('test:update', listener);

/*
Mixspa.emit('[module]:[action]', message);  // emit event
*/
Mixspa.emit('test:update', 'Hello Test');

5. Link in Mixspa

 import Mixspa from '@mixspa/core'
/*
let listener = Mixspa.onLink(handler);  // bind link change event
*/
let listener = Mixspa.onLink((url) => {
  console.log(url);
});

/*
Mixspa.offLink(listener);  // unbind link change event
*/
Mixspa.offLink(listener);

/*
Mixspa.emitLink(url);  // emit link change event
*/
Mixspa.emitLink('http://test.url');

License

mixspa-app is released under the MIT license.

RELATED POST

10 Must-Know Windows Shortcuts That Will Save You Time

10 Must-Know Windows Shortcuts That Will Save You Time

Arrays vs Linked Lists: Which is Better for Memory Management in Data Structures?

Arrays vs Linked Lists: Which is Better for Memory Management in Data Structures?

Navigating AWS Networking: Essential Hacks for Smooth Operation

Navigating AWS Networking: Essential Hacks for Smooth Operation

Achieving Stunning Visuals with Unity's Global Illumination

Achieving Stunning Visuals with Unity's Global Illumination

Nim's Hidden Gems: Lesser-known Features for Writing Efficient Code

Nim's Hidden Gems: Lesser-known Features for Writing Efficient Code