npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@sigma-streaming/micro

v1.1.3

Published

CMS micro frontend integration package

Downloads

25

Readme

Sigma Streaming Micro Frontend

Installation

npm

npm install @sigma-streaming/micro wujie-react

yarn

yarn add @sigma-streaming/micro wujie-react

pnpm

pnpm install @sigma-streaming/micro wujie-react

Usage

React demo

1. Register Sigma Apps

main.tsx

import type { AppConfig, MicroApp } from '@sigma-streaming/micro'
import { registerSigmaApps } from '@sigma-streaming/micro'

export const microApps: MicroApp[] = [
  {
    name: '@sigma-streaming/ssai',
    url: '//123.31.18.25:2181/micro/cms/ssai/',
  },
  {
    name: '@sigma-streaming/lrm',
    url: '//dev-livestream.gviet.vn/micro/cms/lrm/',
  },
]

const appConfig: AppConfig = {
  // generated token for sigma micro app
  token: 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...',
  // token type
  tokenProp: 'x-backdoor',
  // App channel ID - Optional - For tokenType Bearer
  appId: 'c9c2ebfb-...',
}

export const actions = registerSigmaApps(microApps, appConfig)

2. Create component for Micro App

LrmApp.tsx

import React from 'react'
import WujieReact from 'wujie-react'
import { useHistory, useLocation } from 'react-router-dom'

export default function LrmApp(
  {
    url = '//dev-livestream.gviet.vn/micro/cms/lrm/',
    name = '@sigma-streaming/lrm'
  }: MicroProps) {
  const location = useLocation()
  // const navigation = useNavigate(); // new react-router
  const history = useHistory()
  const mainPath = '/lrm'
  const subPath = '/lrm-sub'
  const path = location.pathname.replace(subPath, '').replace(mainPath, '').replace('/', '')
  const viteUrl = url + path

  const props = {
    jump: (newRoute) => {
      history.replace(`/${newRoute}`)
    },
  }

  return (
    // Single mode, Name is the same to reuse an unbounded instance,
    // changing the URL sub-application re-rendering instance to the corresponding routing
    <WujieReact
      width="100%"
      height="100%"
      name={name}
      url={viteUrl}
      sync={true}
      props={props}
    ></WujieReact>
  )
}

3. Create container and add route corresponding for each app's activeRule

*** Note: We use tailwind css class to demonstrate layout styling App.tsx

import { Route, HashRouter as Router, Switch } from 'react-router-dom'
import { CONTAINER } from './main'
import LrmApp from './LrmApp'

// Usecase 1: Main path
<div className="relative my-[-15px] min-h-[calc(100vh-45px)] mx-[-20px]">
  <Switch>
    <Route exact path="/lrm"><LrmApp /></Route>
    <Route exact path="/ssai"></Route>
  </Switch>
</div>

// Usecase 2: With sub path
<div className="relative my-[-15px] min-h-[calc(100vh-45px)] mx-[-20px]">
  <Switch>
    <Route exact path="/lrm"><LrmApp /></Route>
    <Route exact path="/lrm-sub/:path"><LrmApp /></Route>
    <Route exact path="/ssai"></Route>
  </Switch>
</div>


// Usecase 3: Sub path only
<div className="relative my-[-15px] min-h-[calc(100vh-45px)] mx-[-20px]">
  <Switch>
    <Route exact path="/lrm-sub/:path"><LrmApp /></Route>
    <Route exact path="/ssai-sub/:path"></Route>
  </Switch>
</div>

4. Add routing to each app to your Main Sidebar

Each app expose a routes and list

Sidebar.tsx

import type { GlobalState } from '@sigma-streaming/micro'
import type { MenuProps } from 'antd'
import { Menu } from 'antd'
import { actions } from './main'

const Sidebar = (props: SidebarProps) => {
  const history = useHistory()
  const [state, setState] = useState<GlobalState>()

  useEffect(() => {
    const cleanUp = actions.onStateChange((newState) => {
      setState(newState)
    })
    return () => { cleanUp() }
  }, [])

  // Render sidebar from state children
  // Ant design example

   type MenuItem = Required<MenuProps>['items'][number]

   function getItem(
     label: React.ReactNode,
     key: React.Key,
     icon?: React.ReactNode,
     children?: MenuItem[],
     type?: 'group',
   ): MenuItem {
     return {
       key,
       icon,
       children,
       label,
       type,
     } as MenuItem
   }

   const memoItems = useMemo(() => {
     const items: MenuProps['items'] = (state?.children || []).map(item =>
       getItem(item.name, item.name, <div className="i-ant-design:mail-filled" />,
         item.routes.map(route => getItem(route.meta.title, route.path, <div className={route.meta.icon} />))
       ),
     )
     return items
   }, [state])

   const onClick: MenuProps['onClick'] = (e) => {
     const path = `/${e.keyPath[1]}-sub${e.keyPath[0]}`
     if (e.keyPath)
       history.push(path)
   }

   return (
    <Menu
      className="flex-1"
      onClick={onClick}
      style={{ width: 220 }}
      mode="inline"
      items={memoItems}
    />
   )
}