# virutal-application-core

> 虚拟应用核心，使Web前端工程更接近一个PC应用工程，主要约束工程的整体运行框架。强调“应用”，“窗口”等概念，加强应用（窗口）之间的通信交互能力。

Latest version **0.1.6** (published 2023-10-28) · MIT license · 0 weekly downloads

## Install

```sh
npm install virutal-application-core
pnpm add virutal-application-core
yarn add virutal-application-core
bun add virutal-application-core
```

## Health

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

Positive: has types; no vulnerabilities.

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

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.1.6 |
| Published | 2023-10-28 |
| First published | 2023-10-28 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 5 |
| Unpacked size | 255.2 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | chen fei |
| Maintainers | icozeta |
| Keywords | Vue Framework, web, web-pc |

## Links

- npm: https://www.npmjs.com/package/virutal-application-core
- npm.io page: https://npm.io/package/virutal-application-core

## Dependencies (5)

- [debug](https://npm.io/package/debug.md) ^4.3.4
- [@types/vue](https://npm.io/package/@types/vue.md) ^2.0.0
- [@types/debug](https://npm.io/package/@types/debug.md) ^4.1.7
- [message-sender](https://npm.io/package/message-sender.md) ^0.1.6
- [@types/vue-router](https://npm.io/package/@types/vue-router.md) ^2.0.0

## Alternatives

- [@opentelemetry/exporter-zipkin](https://npm.io/package/@opentelemetry/exporter-zipkin.md) — 14.8M weekly downloads
- [pusher-js](https://npm.io/package/pusher-js.md) — 2.0M weekly downloads
- [browserify](https://npm.io/package/browserify.md) — 1.7M weekly downloads
- [sqs-consumer](https://npm.io/package/sqs-consumer.md) — 1.7M weekly downloads
- [@sanity/eventsource](https://npm.io/package/@sanity/eventsource.md) — 930.8K weekly downloads

## Recent versions

- 0.1.6 (latest) — 2023-10-28
- 0.1.5 — 2023-10-28

## README

# Virtual Application Core

虚拟应用核心，使Web前端工程更接近一个PC应用工程，主要约束工程的整体运行框架。强调“应用”，“窗口”等概念，加强应用（窗口）之间的通信交互能力。

## Install - 安装

安装依赖
```shell        
npm install --save virtual-application-core
```

## Usage - 基本用法
```javascript
import { VirtualAppCore } from 'virtual-application-core'
import pkg from '@package.json' // 工程根路径下package.json，@package.json是别名用法，需要在构建工具中声明才能使用

const app = new VirtualAppCore({
    debug: true, // 开启debg
    name: pkg.name, // 应用名称
})
```

## Step Event - 应用的生命周期
应用（窗口）装载时发生的事件, 其他应用可以订阅对应应用（窗口）的装载事件。   
step:init(初始化) -> step:before-mount(挂载前) -> step:mount(挂载完成)

step.1 应用初始化 - 应用通信挂载
```javascript
app.on('step:init', () => {
    return Promise.resolve() // 支持返回Promise对象来阻塞流程
})
```

step.2 应用挂载前
```javascript
app.on('step:before-mount', () => {
    return Promise.resolve() // 支持返回Promise对象来阻塞流程
})
```

step.3 应用挂载完成
```javascript
app.on('step:mount', () => {
    return Promise.resolve() // 支持返回Promise对象来阻塞流程
})
```


## Custom Step 自定义装载事件
针对当前应用拓展生命周期, 需在sync为false，且需在init方法执行之前定义。

```javascript
// 定义在step:init之前
app.setup({
    name: 'myAppSetupEventName',
    beforeEvent: 'step:init',
    doth() {
        // ....
        return Promise.resolve() // 返回Promise可以阻塞流程
    },
})
```

## Step Reply Usage 重新执行应用事件
在目标应用的事件完成后，其他应用可以重新触发目标应用的事件，谨慎使用。

```javascript
app.use('appName', 'step:init', { 'xxxx': 'xxxxxxxxxxx' })
app.use('appName', 'step:before-mount', { 'xxxx': 'xxxxxxxxxxx' })
app.use('appName', 'step:mount', { 'xxxx': 'xxxxxxxxxxx' })
app.use('appName', 'myAppSetupEventName', { 'xxxx': 'xxxxxxxxxxx' })
```

---
_Source: https://npm.io/package/virutal-application-core · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
