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

@zijin/messi

v1.0.41

Published

微应用

Downloads

32

Readme

messi:微应用通信类库(该类库是实现前端微应用化的核心)

页面跳转流程
1. 捕捉当前URL变化 以/app/items/module1/page1为例
1. 判断当前URL是否指向app(url的前缀是否为/app/)
1. 获取appName:items,appPath:/module1/page1
1. 根据appName获得applicationAgent实例。applicationAgent管理实际的Application
1. 调用applicationAgent.navigateByURL('/module1/page1'),打开指定的页面

基于angular的AppManagerComponent管理着所有的Application

主应用master初始化

import { HttpClient } from '@angular/common/http';
import { Injectable, NgZone } from '@angular/core';
import { NzMessageService } from 'ng-zorro-antd';
import { Observable, Subject } from 'rxjs';
import { filter } from 'rxjs/operators';
import { IMaster, messiMasterBuilder } from '@zijin/messi';
import { SessionService } from '@core/session.service';

@Injectable({
  providedIn: 'root',
})
export class MessiService {
  private readonly _master: Promise<IMaster> = null;
  private _appNameList: Array<string> = [];
  private _subAppUrlSubject = new Subject<string>();

  // 初始化messiMaster对象,全局唯一。
  constructor(
    private _http: HttpClient,
    private _ngZone: NgZone,
    private _message: NzMessageService,
    private _session: SessionService,
  ) {
    this._master = new Promise<IMaster>(resolve => {
      // 加载配置文件
      this._http.get('assets/apps.json')
        .subscribe((appConfigArray: any) => {
          appConfigArray.forEach(appConfig => {
            this._appNameList.push(appConfig.name);
          });

          resolve(this._buildAndInitMaster(appConfigArray));
        });
    });
  }

  set subAppUrl(url) {
    this._subAppUrlSubject.next(url);
  }

  get subAppUrl$(): Observable<string> {
    return this._subAppUrlSubject
      .asObservable()
      .pipe(filter((url) => !!url));
  }

  get master(): Promise<IMaster> {
    return this._master;
  }

  changeTheme(theme: string) {
    this._master.then((master) => {
      this._appNameList.forEach(subAppName => {
        master.triggerEventInApp(subAppName, 'changeTheme', theme);
      });
    });
  }

  /**
   * 创建并初始化主应用(master)
   * @param appConfigArray
   * @private
   */
  private _buildAndInitMaster(appConfigArray: Array<any>) {
    let master = messiMasterBuilder({
      parentElement: '#messiContainer',
      preload: false, // 是否预加载子应用
      preloadSize: 2, // 预加载子应用的数量
    }, appConfigArray);

    // 注册getToken方法,以便子应用调用从而获取登录信息等
    master.registerMethod('getToken', () => {
      return this._session.userInfo;
    });

    // 注册gotoLogin方法,在子应用token失效时跳转到主应用login页面
    master.registerMethod('gotoLogin', () => {
      this._session.logout();
    });

    // token过期,跳转到404页面
    master.registerMethod('tokenTimeout', () => {
      this._ngZone.run(() => {
        this._message.error('登录信息失效,请重新登录');
        this._session.gotoException();
      });
    });

    return master;
  }
}

子应用

        // Set the name of the subApplication(*)
        messiConfig.name = 'insight';
        // Set output level of log(默认值为debug,将产生较多日志输出)
        messiConfig.level = CONSOLE_LEVEL.DEBUG;
        window.addEventListener(MESSI_EVENT.ROUTING_NAVIGATE,
            (event: CustomEvent) => {
                if (event.detail && event.detail.url) {
                    this.router.navigateByUrl(event.detail.url);
                }
            });
        window.addEventListener('closeReuseTabByUrl', (event: CustomEvent) => {
            console.log(event.detail);
            AppReuseStrategy.deleteRouteSnapshot(event.detail);

        });

        window.addEventListener('changeTheme', (event: CustomEvent) => {
            this.theme.setTheme(event.detail);
            this.settings.setLayout('theme', event.detail);
        });

        messiApplication.getToken()
            .then((token) => {
                console.log('The device management system gets token from master application!', token);
                this.session.token = token;
            }, error => {
                console.error('error:' + error);
            });

        // Notifies the master application that the current sub-application load is complete!
        messiApplication.updateStatus(APP_STATUS.LOADED);