# kg-site-subapp-controller

> KG-site sub-app lifecycle controller base on document event

Latest version **0.0.4** (published 2020-06-09) · ISC license · 0 weekly downloads

## Install

```sh
npm install kg-site-subapp-controller
pnpm add kg-site-subapp-controller
yarn add kg-site-subapp-controller
bun add kg-site-subapp-controller
```

## Health

**Score 25/100 (F)** — status: abandoned.

Positive: has types; no vulnerabilities; high quality score.

Warnings: low downloads; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.0.4 |
| Published | 2020-06-09 |
| First published | 2020-06-02 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 4 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | kagashino |
| Maintainers | ghosthcp516 |

## Links

- npm: https://www.npmjs.com/package/kg-site-subapp-controller
- npm.io page: https://npm.io/package/kg-site-subapp-controller

## Recent versions

- 0.0.4 (latest) — 2020-06-09
- 0.0.3 — 2020-06-02
- 0.0.2 — 2020-06-02
- 0.0.1 — 2020-06-02

## README

# KG-Site Sub-app Controller

KG-site sub-app lifecycle controller based on document event.

## Install
> npm install kg-site-subapp-controller

## Usage
```typescript jsx
import React from 'react';
import ReactDOM from 'react-dom';
import { bootstrap } from 'kg-site-subapp-controller';
import App from './src/App';

bootstrap('my-app', {
  onLaunch (container) {
    ReactDOM.render(<App />, contaienr);
  },
  onClose (container) {
    ReactDOM.unmountComponentAtNode(container);
  },
  fallback () {
    ReactDOM.render(<App />, document.getElementById('root'));
  }
})
```


## API

> bootstrap(subAppName, config)
### subAppName
Unique name in `kg-site-subapp`.
### config
|prop|type|desc|default|
|:----:|:----:|:----:|:----:|
|selector|string|Sub app dom container id| `subAppName`|
|fallback|`()=>void`|Callback when container not exist| `undefined`|
|launchEventName|string|Custom launch event name|`LAUCH_APP:${subAppName}`|
|closeEventName|string|Custom close event name|`CLOSE_APP:${subAppName}`|
|onLaunch|`(container: HTMLElement) => void` |Callback when launch event fired|`undefined`|
|onClose|`(container: HTMLElement) => void` |Callback when close event fired|`undefined`|

---
_Source: https://npm.io/package/kg-site-subapp-controller · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
