Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@garfish/core

Package Overview
Dependencies
Maintainers
0
Versions
380
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@garfish/core

core module.

  • 1.19.2-beta-20240709081230.0
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
418
decreased by-75.18%
Maintainers
0
Weekly downloads
 
Created
Source

@garfish/core

NPM version

Usage

$ yarn add @garfish/core @garfish/cjs-app @garfish/router @garfish/browser-vm @garfish/browser-snapshot
import Garfish from '@garfish/core';
import { GarfishRouter } from '@garfish/router';
import { GarfishBrowserVm } from '@garfish/browser-vm';
import { GarfishBrowserSnapshot } from '@garfish/browser-snapshot';

const GarfishInstance = new Garfish({
  apps,
  plugins: [GarfishRouter(), GarfishBrowserVm(), GarfishBrowserSnapshot()],
});

loadApp

import Garfish from '@garfish/core';
import { GarfishBrowserVm } from '@garfish/browser-vm';

const GarfishInstance = new Garfish({
  plugins: [GarfishBrowserVm()],
  beforeLoad: async (appInfo, options) => {
    // `return false` will prevent the app from loading
    // return false;
  },
  afterLoad: (appInfo, options) => {},
  beforeEval: (appInfo, code, env, url, options) => {},
  afterEval: (appInfo, code, env, url, options) => {},
  beforeMount: (appInfo, app) => {},
  afterMount: (appInfo, app) => {},
  beforeUnmount: (appInfo, app) => {},
  afterUnmount: (appInfo, app) => {},
  errorLoadApp: (err, appInfo) => console.error(err),
  errorMountApp: (err, appInfo) => console.error(err),
  errorUnmountApp: (err, appInfo) => console.error(err),
  errorExecCode: (err, appInfo) => console.error(err),
});

// `appName` is globally unique.
GarfishInstance.loadApp('appName', 'https://xx.html').then(async (app) => {
  if (!app) return;
  let mountSuccess;
  try {
    mountSuccess = await app.mount();
  } catch (e) {
    // If you add the `errorMountApp` hook, no error will be thrown here
    console.log(e);
  }

  if (mountSuccess) {
    document.body.appendChild(app.appContainer);
    // unmount
    setTimeout(() => {
      const unmountSuccess = app.unmout();
      console.log(unmountSuccess);
    }, 1000);
  }
});

You can also pass more complex parameters.

GarfishInstance.loadApp('appName', {
  cache: true,
  entry: 'https://xx.html',
  domGetter: '#appContainer', // When the child application is rendered, it will be mounted here
}).then(async (app) => {
  if (!app) return;
  // ...
});

Keywords

FAQs

Package last updated on 09 Jul 2024

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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc