Skip to content

Commit

Permalink
feat(bus): change the return value of touchBus
Browse files Browse the repository at this point in the history
  • Loading branch information
run-nan committed Sep 3, 2021
1 parent 3b7552e commit fe461d4
Show file tree
Hide file tree
Showing 9 changed files with 32 additions and 29 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand Down Expand Up @@ -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();
Expand All @@ -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;

Expand Down
10 changes: 5 additions & 5 deletions README.zh.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ umd:
## 快速开始
在宿主环境中创建bus,并声明微应用资源
```js
import {touchBus} from 'obvious-core';
import { touchBus } from 'obvious-core';

const [bus] = touchBus();

Expand Down Expand Up @@ -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) => {
Expand All @@ -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) => {
Expand Down
8 changes: 4 additions & 4 deletions dist/index.es.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down
8 changes: 4 additions & 4 deletions dist/index.umd.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
8 changes: 4 additions & 4 deletions src/lib/bus.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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];
};
12 changes: 6 additions & 6 deletions test/bus.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});

Expand Down

0 comments on commit fe461d4

Please sign in to comment.