Latest Threat ResearchGlassWorm Loader Hits Open VSX via Developer Account Compromise.Details
Socket
Book a DemoInstallSign in
Socket

web-gambit-cli

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

web-gambit-cli

web-gambit cli

latest
npmnpm
Version
1.0.2
Version published
Maintainers
1
Created
Source

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.

DistversionInfo
Latestv1.1.xLatest release
Stablev1.1.72Stable release
Legacyv1.0.100Stable legacy supported
Deprecatedless than v1.0.100Unsupported

All information you can find at devoptions

Links to official web-gambit resources, where you can learn, communicate and subscribe to the latest information about the web-gambit library.

ResourceURLDescription
Show caseshow-case.devoptions.ruDemonstration stand
Get startedgambit.devoptions.ruCookbook & examples
Blogblog.devoptions.ruInformation of development process
Communitycommunity.devoptions.ruLive communication with the development team

Resources will be available soon...

CLI

CommandModeDescription
yarn add web-gambitJSadd web-gambit to any lib or framework
web-gambit create-appFMMCreate Encapsulated-app, UMD or Host-app as FMM
web-gambit create-dockerCICreate docker-compose and Dockerfile
web-gambit serveDEVRun development mode
web-gambit buildBUILDBuild FMMs as .js bundle
web-gambit startPRODRun release ready modular Application

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')))

2.2 Create UI via tsx

If you want to create UI via jsx render, you mast add to project: babel, babel-loader, babel preset for jsx and webpack. Soon in web-gambit cli!

INFO: adding createJsx import method via webpack-import-loader!

import {CreateApp, Module, CreateRouter, CurrentRoute, 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 Application() {
    return <SomeComponent routes={CreateRouter(routes)}/>
}

function SomeComponent({routes}: {routes: JSXElement}) {
    const Route = CurrentRoute()
    return <div>
        <h1>{ModuleNamespace.moduleState.text}</h1>
        <h1>{Route.name}</h1>
        {routes}
    </div>
}

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

Contacts

npm@devoptions.ru

Tech inside

Code-gambit - Code card transpiler for FMM

Webpack - Powerful "weapon" for configuration and modulate your application

Babel - Modern javascript compiler

Express - Very cool Nodejs framework

Keywords

microfront

FAQs

Package last updated on 13 Oct 2021

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts