From fe461d4b4a42db3e2e5f2479a4bad29215b12ccf Mon Sep 17 00:00:00 2001 From: runnan <1608272694@qq.com> Date: Fri, 3 Sep 2021 12:00:25 +0800 Subject: [PATCH] feat(bus): change the return value of touchBus --- CHANGELOG.md | 3 +++ README.md | 6 +++--- README.zh.md | 10 +++++----- dist/index.es.js | 8 ++++---- dist/index.umd.js | 8 ++++---- package-lock.json | 4 ++-- package.json | 2 +- src/lib/bus.ts | 8 ++++---- test/bus.test.ts | 12 ++++++------ 9 files changed, 32 insertions(+), 29 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index abc8646..70af5a9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,9 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +## [0.3.2] - 2021-09-03 +### Changed +- change the return value of touchBus ## [0.3.1] - 2021-09-02 ### Added - new Api: touchBus diff --git a/README.md b/README.md index 2a82580..9d317c6 100644 --- a/README.md +++ b/README.md @@ -30,7 +30,7 @@ umd: In host enviroment, create a bus and declare the resource info ```js -import {touchBus} from 'obvious-core'; +import { touchBus } from 'obvious-core'; const [bus] = touchBus() bus.config({ @@ -58,7 +58,7 @@ react-app ```js import React from 'react'; import ReactDOM from 'react-dom'; -import {touchBus} from 'obvious-core'; +import { touchBus } from 'obvious-core'; const [bus] = touchBus(); const socket = bus.createSocket(); @@ -75,7 +75,7 @@ vue-app ```js import Vue from 'vue'; import App from './App.vue'; -import {touchBus} from 'obvious-core'; +import { touchBus } from 'obvious-core'; Vue.config.productionTip = false; diff --git a/README.zh.md b/README.zh.md index 73d351a..9053326 100644 --- a/README.zh.md +++ b/README.zh.md @@ -27,7 +27,7 @@ umd: ## 快速开始 在宿主环境中创建bus,并声明微应用资源 ```js -import {touchBus} from 'obvious-core'; +import { touchBus } from 'obvious-core'; const [bus] = touchBus(); @@ -56,9 +56,9 @@ react-app ```js import React from 'react'; import ReactDOM from 'react-dom'; -import {touchBus} from 'obvious-core'; +import { touchBus } from 'obvious-core'; -const bus = touchBus('host'); +const bus = touchBus(); const socket = bus.createSocket(); bus.createApp('react-app') .bootstrap(async (config) => { @@ -73,11 +73,11 @@ vue-app ```js import Vue from 'vue'; import App from './App.vue'; -import {touchBus} from 'obvious-core'; +import { touchBus } from 'obvious-core'; Vue.config.productionTip = false; -const [bus] = touchBus('host'); +const [bus] = touchBus(); const socket = bus.createSocket(); bus.createApp('vue-app') .bootstrap(async (config) => { diff --git a/dist/index.es.js b/dist/index.es.js index bb9b2f0..847b711 100644 --- a/dist/index.es.js +++ b/dist/index.es.js @@ -1094,17 +1094,17 @@ var getBus = function (name) { var touchBus = function (name) { if (name === void 0) { name = DEFAULT_BUS_NAME; } var bus = null; - var isBusAlreadyExists = false; + var isHost = false; var existedBus = getBus(name); if (existedBus) { bus = existedBus; - isBusAlreadyExists = true; + isHost = false; } else { bus = createBus(name); - isBusAlreadyExists = false; + isHost = true; } - return [bus, isBusAlreadyExists]; + return [bus, isHost]; }; var Obvious = { diff --git a/dist/index.umd.js b/dist/index.umd.js index 74cc472..4e8edcb 100644 --- a/dist/index.umd.js +++ b/dist/index.umd.js @@ -1100,17 +1100,17 @@ var touchBus = function (name) { if (name === void 0) { name = DEFAULT_BUS_NAME; } var bus = null; - var isBusAlreadyExists = false; + var isHost = false; var existedBus = getBus(name); if (existedBus) { bus = existedBus; - isBusAlreadyExists = true; + isHost = false; } else { bus = createBus(name); - isBusAlreadyExists = false; + isHost = true; } - return [bus, isBusAlreadyExists]; + return [bus, isHost]; }; var Obvious = { diff --git a/package-lock.json b/package-lock.json index 027d157..56f882d 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,11 +1,11 @@ { "name": "obvious-core", - "version": "0.3.1", + "version": "0.3.2", "lockfileVersion": 2, "requires": true, "packages": { "": { - "version": "0.2.4", + "version": "0.3.2", "license": "ISC", "dependencies": { "tslib": "^2.3.1" diff --git a/package.json b/package.json index b22d1d3..a86d058 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "obvious-core", - "version": "0.3.1", + "version": "0.3.2", "description": "a progressive micro front framework", "main": "./dist/index.umd.js", "module": "./dist/index.es.js", diff --git a/src/lib/bus.ts b/src/lib/bus.ts index a3ba900..5719ca8 100644 --- a/src/lib/bus.ts +++ b/src/lib/bus.ts @@ -266,14 +266,14 @@ export const getBus = (name: string = DEFAULT_BUS_NAME) => { */ export const touchBus = (name: string = DEFAULT_BUS_NAME): [Bus, boolean] => { let bus: Bus = null; - let isBusAlreadyExists: boolean = false; + let isHost: boolean = false; const existedBus = getBus(name); if (existedBus) { bus = existedBus; - isBusAlreadyExists = true; + isHost = false; } else { bus = createBus(name); - isBusAlreadyExists = false; + isHost = true; } - return [bus, isBusAlreadyExists]; + return [bus, isHost]; }; diff --git a/test/bus.test.ts b/test/bus.test.ts index c53c08a..f01eda7 100644 --- a/test/bus.test.ts +++ b/test/bus.test.ts @@ -129,14 +129,14 @@ describe('Test the capability to load the resources of an app or lib', () => { }); test('# case 6: test touchBus and default bus', () => { - const [testBus, isTestBusAlreadyExists] = touchBus('testBus'); - expect(isTestBusAlreadyExists).toBeTruthy(); + const [testBus, isTestBusHost] = touchBus('testBus'); + expect(isTestBusHost).toBeFalsy(); expect(testBus).toEqual(bus); - const [defaultBus1, isDefaultBus1AlreadyExists] = touchBus(); - expect(isDefaultBus1AlreadyExists).toBeFalsy(); + const [defaultBus1, isDefaultBus1Host] = touchBus(); + expect(isDefaultBus1Host).toBeTruthy(); expect(defaultBus1).toEqual(window.__Bus__[DEFAULT_BUS_NAME]); - const [defaultBus2, isDefaultBus2AlreadyExists] = touchBus(); - expect(isDefaultBus2AlreadyExists).toBeTruthy(); + const [defaultBus2, isDefaultBus2Host] = touchBus(); + expect(isDefaultBus2Host).toBeFalsy(); expect(defaultBus2).toEqual(defaultBus1); });