web-gambit
TypeScript icon, indicating that this package has built-in type declarations

1.1.80 • Public • Published

Web-gambit: Modular micro front-end solution!

Web-gambit - lightweight (5Kb) modular micro front-end library for creation progressive web-application on typescript. This library provide a powerful solution based on Clean architecture principles. Web-gambit - easy way for creating composition of micro fronted modules from remote sources! REP, CCP and CRP - its simple. This solution is compatible with all popular frameworks: Vue, React, Angular, Svelte, Ember, etc.

Manual

1. Frontend micro modules (FMM)

1.1. Create Application Frontend Micro Module (AFMM) for instance module

AFMM - Independent reusable micro module. It can contain: Services, Interactors or Encapsulated application. AFMM can sync states without IFMM module only through a Proxy. After hard-reload page, Modules state will be reset to initial state.

import {Module} from 'web-gambit'

type ModuleState = {index: number}

const ModuleNamespace = {moduleName: 'numeric', moduleState: {index: 12345}}

Module<ModuleState>(ModuleNamespace, () => console.log(`AFMM ${ModuleNamespace.moduleName} is loaded`))

1.2. Import remote UMD Frontend Micro Module (UFMM)

UFMM - Its regular UMD modules compiled via webpack, parcel, etc.

import {Module, Emit, importModule, executeUmdModule} from 'web-gambit'

type CreatedDate = {getDate(): Date}
type UMD<ModuleType=any> = {exports: {default: ModuleType}}

const InstanceState = {createdDate: Date | null}
const InstanceNamespace = {moduleName: 'MainApp', moduleState: {createdDate: null}}

function fetchUmdModule<ModuleType=any>(): Promise<ModuleType> {
    return importModule('/assets/modules/date/js/date.js').then(umdModule => {
        const {exports} = executeUmdModule(umdModule) as UMD<ModuleType>
        return exports.default
    })
}

Module<InstanceState>(InstanceNamespace, () => {
    fetchUmdModule<CreatedDate>().then(dateModule => {
        Emit('createdDate', dateModule.getDate())
    }).catch(console.log)
})

1.3. FMM Data transfer.

Web-gambit provides methods for transferring and synchronizing data between modules, by default.

  • Watch - Create a listener for the selected command
  • Emit - Executing a data transfer command
import {Module, Emit} from 'web-gambit'

type InstanceState = {text: string}

const InstanceNamespace = {moduleName: 'MainApp', moduleState: {text: 'Hello World!'}}

Module<InstanceNamespace>(InstanceNamespace, () => {
    Watch({
        name: 'watchUniqueName',
        command: 'text',
        action: (text: string) => console.log(text)
    })
    setInterval(() => Emit('text', Math.random().toString()), 300)
})

2. Modular micro frontend UI

You can create a modular micro-interface application through any popular library or framework. But ... Web Gambit includes its own functional UI (React like) solution for fast client-side UI development.

2.1 Create UI via render function

For creation UI component with h and render functions

import {createJsx as h, CreateApp, Module, CreateRouter, IRoute} from 'web-gambit'
import MainPage from './pages/main/MainPage'

type IContent = {text: string}

const ModuleNamespace = {moduleName: 'contentView', moduleState: {text: 'Hello World!'}}
const routes: IRoute[] = [{path: '/', name: 'Main', component: MainPage}]

function SomeComponent() {
    return h('div', null, [
        h('h1', null, [ModuleNamespace.moduleState.text]),
        CreateRouter(routes)
    ])
}

Module<IContent>(ModuleNamespace, () => CreateApp(SomeComponent, document.getElementById('app')))

Contacts

npm@devoptions.ru

Versions

Current Tags

VersionDownloads (Last 7 Days)Tag
1.1.800latest

Version History

VersionDownloads (Last 7 Days)Published
1.1.800
1.1.790
1.1.780
1.1.770
1.1.761
1.1.750
1.1.740
1.1.730
1.1.720
1.1.710
1.1.700
1.1.690
1.1.680
1.1.670
1.1.660
1.1.650
1.1.640
1.1.630
1.1.620
1.1.610
1.1.601
1.1.590
1.1.580
1.1.570
1.1.560
1.1.550
1.1.540
1.1.530
1.1.521
1.1.510
1.1.500
1.1.490
1.1.480
1.1.470
1.1.460
1.1.450
1.1.440
1.1.430
1.1.420
1.1.410
1.1.400
1.1.390
1.1.380
1.1.370
1.1.360
1.1.350
1.1.340
1.1.330
1.1.320
1.1.310
1.1.300
1.1.290
1.1.280
1.1.270
1.1.260
1.1.250
1.1.240
1.1.230
1.1.220
1.1.210
1.1.200
1.1.190
1.1.180
1.1.170
1.1.160
1.1.150
1.1.140
1.1.130
1.1.120
1.1.110
1.1.100
1.1.90
1.1.80
1.1.70
1.1.60
1.1.50
1.1.40
1.1.30
1.1.20
1.1.10
1.1.00
1.0.1000
1.0.990
1.0.980
1.0.970
1.0.960
1.0.950
1.0.940
1.0.930
1.0.920
1.0.910
1.0.900
1.0.890
1.0.880
1.0.870
1.0.860
1.0.850
1.0.840
1.0.830
1.0.820
1.0.810
1.0.800
1.0.790
1.0.780
1.0.770
1.0.760
1.0.750
1.0.740
1.0.730
1.0.720
1.0.710
1.0.700
1.0.690
1.0.680
1.0.670
1.0.660
1.0.650
1.0.640
1.0.630
1.0.620
1.0.610
1.0.600
1.0.590
1.0.580
1.0.570
1.0.560
1.0.550
1.0.540
1.0.530
1.0.520
1.0.510
1.0.500
1.0.490
1.0.480
1.0.470
1.0.460
1.0.450
1.0.440
1.0.430
1.0.420
1.0.410
1.0.400
1.0.390
1.0.380
1.0.370
1.0.360
1.0.350
1.0.340
1.0.330
1.0.320
1.0.310
1.0.300
1.0.290
1.0.280
1.0.270
1.0.260
1.0.250
1.0.240
1.0.230
1.0.220
1.0.210
1.0.200
1.0.190
1.0.180
1.0.170
1.0.160
1.0.150
1.0.140
1.0.130
1.0.121
1.0.110
1.0.100
1.0.90
1.0.80
1.0.60
1.0.50
1.0.40
1.0.30
1.0.20
1.0.10
1.0.00

Package Sidebar

Install

npm i web-gambit

Weekly Downloads

2

Version

1.1.80

License

ISC

Unpacked Size

11.5 kB

Total Files

5

Last publish

Collaborators

  • devoptionscode