🚀 Big News: Socket Acquires Coana to Bring Reachability Analysis to Every Appsec Team.Learn more
Socket
Book a DemoInstallSign in
Socket

obvious-core

Package Overview
Dependencies
Maintainers
1
Versions
14
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

obvious-core - npm Package Compare versions

Comparing version

to
0.2.2-alpha

8

CHANGELOG.md

@@ -6,4 +6,10 @@ # Changelog

and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
## [0.2.1] - 2020-12-10
### Added
- enable to watch and set state deeply
## [0.0.1] - 2020-08-03
## [0.1.1] - 2020-08-04
### Fixed
- fix some bugs
## [0.1.0] - 2020-08-03
### Added

@@ -10,0 +16,0 @@ - State and event communication capabilities

2

dist/lib/app.d.ts

@@ -5,3 +5,3 @@ declare type CallbackType = (config?: any) => Promise<void>;

name: string;
private dependenciesReady;
dependenciesReady: boolean;
bootstrapped: boolean;

@@ -8,0 +8,0 @@ dependencies: DependenciesType;

@@ -19,6 +19,6 @@ import { Socket } from './socket';

private apps;
private bootstrapNumberOnce;
private dependencyDepth;
state: Record<string, any>;
allowCrossOriginScript: boolean;
maxBootstrapNumberOnce: number;
maxDependencyDepth: number;
constructor(name?: string, assets?: AssetsConfigType, middleware?: MiddlewareType);

@@ -25,0 +25,0 @@ /**

@@ -20,5 +20,5 @@ "use strict";

this.apps = {};
this.bootstrapNumberOnce = 0;
this.dependencyDepth = 0;
this.allowCrossOriginScript = true;
this.maxBootstrapNumberOnce = 100;
this.maxDependencyDepth = 100;
/**

@@ -204,7 +204,7 @@ * define fetchJs、loadJs and loadCss as arrow function because

if (!!app.bootstrapped) return [3 /*break*/, 8];
if (this.bootstrapNumberOnce > this.maxBootstrapNumberOnce) {
this.bootstrapNumberOnce = 0;
if (this.dependencyDepth > this.maxDependencyDepth) {
this.dependencyDepth = 0;
throw new Error(utils_1.Errors.bootstrapNumberOverflow());
}
this.bootstrapNumberOnce++;
this.dependencyDepth++;
return [4 /*yield*/, app.activateDependenciesApp(this.activateApp.bind(this))];

@@ -226,3 +226,3 @@ case 3:

app.bootstrapped = true;
this.bootstrapNumberOnce--;
this.dependencyDepth--;
return [3 /*break*/, 11];

@@ -265,4 +265,4 @@ case 8:

_a;
delete this.apps[name];
delete this._state["app-" + name + "-created"];
app.bootstrapped = false;
app.dependenciesReady = false;
_b.label = 3;

@@ -269,0 +269,0 @@ case 3: return [2 /*return*/];

import { CallbackType } from './types';
export declare class EventEmitter {
private broadcastEvents;
private uniCastEvents;
private unicastEvents;
getBroadcastEvents(): Record<string, CallbackType[]>;

@@ -6,0 +6,0 @@ addBroadcastEventListener(event: string, callback: CallbackType): void;

@@ -7,3 +7,3 @@ "use strict";

this.broadcastEvents = {};
this.uniCastEvents = {};
this.unicastEvents = {};
}

@@ -18,6 +18,6 @@ EventEmitter.prototype.getBroadcastEvents = function () {

EventEmitter.prototype.addUnicastEventListener = function (event, callback) {
if (this.uniCastEvents[event]) {
if (this.unicastEvents[event]) {
throw new Error(utils_1.Errors.registedExistedUnicast(event));
}
this.uniCastEvents[event] = callback;
this.unicastEvents[event] = callback;
};

@@ -48,11 +48,11 @@ EventEmitter.prototype.removeBroadcastEventListener = function (event, callback) {

EventEmitter.prototype.removeUnicastEventListener = function (event, callback) {
if (!this.uniCastEvents[event]) {
if (!this.unicastEvents[event]) {
var msg = utils_1.Errors.removeNonExistedUnicast(event);
throw new Error(msg);
}
if (this.uniCastEvents[event] !== callback) {
if (this.unicastEvents[event] !== callback) {
var msg = utils_1.Errors.wrongUnicastCallback(event);
throw new Error(msg);
}
delete this.uniCastEvents[event];
delete this.unicastEvents[event];
};

@@ -86,3 +86,3 @@ EventEmitter.prototype.emitBroadcast = function (event) {

}
var callback = this.uniCastEvents[event];
var callback = this.unicastEvents[event];
return callback.apply(void 0, args);

@@ -89,0 +89,0 @@ };

@@ -44,2 +44,7 @@ import { EventEmitter } from './event-emitter';

/**
* judge if state has been initialized
* @param stateName
*/
existState(stateName: string): boolean;
/**
* init a state

@@ -46,0 +51,0 @@ * @param stateName

@@ -71,2 +71,9 @@ "use strict";

/**
* judge if state has been initialized
* @param stateName
*/
Socket.prototype.existState = function (stateName) {
return this._state[stateName] !== undefined;
};
/**
* init a state

@@ -73,0 +80,0 @@ * @param stateName

@@ -63,3 +63,3 @@ "use strict";

'it means that there may be circular dependencies, please check the app dependencies declaration ' +
'or reset the bus\'s maxBootstrapNumberOnce';
'or reset the bus\'s maxDependencyDepth';
},

@@ -165,2 +165,5 @@ // ================= State ==================

}
if (stateName.startsWith(matchedState) && !result.includes(matchedState)) {
result.push(matchedState);
}
}

@@ -167,0 +170,0 @@ });

@@ -955,3 +955,3 @@ # 介绍

- 属性:**maxBootstrapNumberOnce**
- 属性:**maxDependencyDepth**
|类型|默认值|描述|

@@ -997,2 +997,7 @@ |:---:|:---:|:---:|

- 判断状态是否已经被初始化:**existsState**:(stateName) => boolean
|参数名|是否必选|类型|描述|
|:---:|:---:|:---:|:---:|
|stateName|是|string|状态名|
- 获取状态:**getState**: (stateName) => any

@@ -999,0 +1004,0 @@ |参数名|是否必选|类型|描述|

{
"name": "obvious-core",
"version": "0.2.1",
"version": "0.2.2-alpha",
"description": "a progressive micro front framework",
"main": "dist/index.js",
"main": "./dist/index.js",
"scripts": {
"demo": "cd ./demo && npm run start",
"build": "tsc",
"lint": "eslint --fix --ext .ts,.js src",
"docs": "docsify serve docs",
"test": "jest --coverage"
"test": "jest --coverage",
"demo:install": "cd ./examples/react-app && npm install && cd ../vue-app && npm install && cd ../host-enviroment && npm install",
"demo:react": "cd ./examples/react-app && npm run start",
"demo:vue": "cd ./examples/vue-app && npm run serve",
"demo:host": "cd ./examples/host-enviroment && npm start"
},
"author": "Philip Lau",
"license": "ISC",
"husky": {
"hooks": {
"pre-commit": "npm run lint && npm run build && git add ."
}
},
"devDependencies": {

@@ -26,2 +35,3 @@ "@types/jest": "^24.0.23",

"eslint-plugin-standard": "^4.0.1",
"husky": "^4.3.6",
"jest": "^24.9.0",

@@ -41,5 +51,5 @@ "nock": "^11.7.2",

"bugs": {
"url": "https://github.com/SMIELPF/run-nan/issues"
"url": "https://github.com/ObviousJs/obvious-core/issues"
},
"homepage": "https://github.com/ObviousJs/obvious-core#readme"
}
# obvious.js
Obvious is a progressive micro-front-end framework. In the micro-front-end architecture, Obvious focuses on solving the problem of orchestration and communication between micro frontend applications. It aims to help users quickly build a basic micro-front-end system and support deeper customization to achieve a complete and reliable micro-front-end architecture by providing easy-to-understand APIs flexible middleware mechanisms.
Obvious is a progressive micro-front-end framework. In the micro-front-end architecture, Obvious focuses on solving the problem of orchestration and communication between micro frontend applications. It aims to help users quickly build a basic micro-front-end system and support deeper customization to achieve a complete and reliable micro-front-end architecture by providing easy-to-understand APIs and flexible middleware mechanisms.
## Features
- Provide flexible and convenient capabilities based on global status, event broadcast, and event unicast
- Support declaring dependencies capabilities when defining micro applications, and automatically activate dependencies when activating micro applications, allowing micro applications to be freely split and combine
- Have a flexible middleware mechanism. Allow developers to freely customize the unified registration and loading rules of resources in the form of writing middleware to realize automatic registration. At the same time, allow developers to write middleware to control the code excuting, so that developers can elegantly access log, js sandbox and other functions
- Provide flexible and convenient communication capabilities based on global status, event broadcast, and event unicast
- Support declaring dependencies when defining micro applications, and automatically activate dependencies when activating micro applications, allowing micro applications to be freely split and combine
- Have a flexible middleware mechanism which allows developers to freely customize the unified registration and loading rules of resources in the form of writing middleware to realize automatic registration. At the same time, allow developers to write middleware to control the code excuting, so that developers can elegantly access log, js sandbox and other functions
- Naturally supports loading multiple micro-applications in a single-screen page, based on which a high-end spa micro-front-end framework can be encapsulated, and the activation conditions of the micro-applications are completely freely set by the developer, no longer limited to routing hijacking.

@@ -9,0 +9,0 @@ - The concept is simple, the functional API is clear and easy to understand, and it can be developed without documentation

@@ -5,4 +5,3 @@ type CallbackType = (config?: any) => Promise<void>;

export class App {
private dependenciesReady: boolean = false;
public dependenciesReady: boolean = false;
public bootstrapped: boolean = false;

@@ -9,0 +8,0 @@ public dependencies: DependenciesType = [];

@@ -25,7 +25,7 @@ import { EventEmitter } from './event-emitter';

private apps: Record<string, App | boolean> = {};
private bootstrapNumberOnce = 0;
private dependencyDepth = 0;
public state: Record<string, any>;
public allowCrossOriginScript: boolean = true;
public maxBootstrapNumberOnce = 100;
public maxDependencyDepth = 100;

@@ -170,7 +170,7 @@ constructor(

if (!app.bootstrapped) {
if (this.bootstrapNumberOnce > this.maxBootstrapNumberOnce) {
this.bootstrapNumberOnce = 0;
if (this.dependencyDepth > this.maxDependencyDepth) {
this.dependencyDepth = 0;
throw new Error(Errors.bootstrapNumberOverflow());
}
this.bootstrapNumberOnce++;
this.dependencyDepth++;
await app.activateDependenciesApp(this.activateApp.bind(this));

@@ -183,3 +183,3 @@ if (app.doBootstrap) {

app.bootstrapped = true;
this.bootstrapNumberOnce--;
this.dependencyDepth--;
} else {

@@ -200,6 +200,6 @@ app.doActivate && (await app.doActivate(config));

app.doDestroy && (await app.doDestroy(config));
delete this.apps[name];
delete this._state[`app-${name}-created`];
app.bootstrapped = false;
app.dependenciesReady = false;
}
}
}

@@ -6,3 +6,3 @@ import { CallbackType } from './types'; // eslint-disable-line

type UnicastEventsType = Record<string, CallbackType>
type unicastEventsType = Record<string, CallbackType>

@@ -13,3 +13,3 @@ export class EventEmitter {

private uniCastEvents: UnicastEventsType = {}
private unicastEvents: unicastEventsType = {}

@@ -26,6 +26,6 @@ public getBroadcastEvents() {

public addUnicastEventListener(event: string, callback: CallbackType) {
if (this.uniCastEvents[event]) {
if (this.unicastEvents[event]) {
throw new Error(Errors.registedExistedUnicast(event));
}
this.uniCastEvents[event] = callback;
this.unicastEvents[event] = callback;
}

@@ -56,3 +56,3 @@

public removeUnicastEventListener(event: string, callback: CallbackType) {
if (!this.uniCastEvents[event]) {
if (!this.unicastEvents[event]) {
const msg = Errors.removeNonExistedUnicast(event);

@@ -62,7 +62,7 @@ throw new Error(msg);

if (this.uniCastEvents[event] !== callback) {
if (this.unicastEvents[event] !== callback) {
const msg = Errors.wrongUnicastCallback(event);
throw new Error(msg);
}
delete this.uniCastEvents[event];
delete this.unicastEvents[event];
}

@@ -88,5 +88,5 @@

public emitUnicast(event: string, ...args: any[]) {
const callback = this.uniCastEvents[event];
const callback = this.unicastEvents[event];
return callback(...args);
}
}

@@ -67,2 +67,10 @@ import { EventEmitter } from './event-emitter'; // eslint-disable-line

/**
* judge if state has been initialized
* @param stateName
*/
public existState(stateName: string) {
return this._state[stateName] !== undefined;
}
/**
* init a state

@@ -69,0 +77,0 @@ * @param stateName

@@ -62,3 +62,3 @@ const isObject = (object: any) => {

'it means that there may be circular dependencies, please check the app dependencies declaration ' +
'or reset the bus\'s maxBootstrapNumberOnce';
'or reset the bus\'s maxDependencyDepth';
},

@@ -65,0 +65,0 @@ // ================= State ==================

@@ -8,4 +8,4 @@ {

"lib": ["ES6", "DOM", "ES2017"], /* Specify library files to be included in the compilation. */
// "allowJs": true, /* Allow javascript files to be compiled. */
// "checkJs": true, /* Report errors in .js files. */
"allowJs": false, /* Allow javascript files to be compiled. */
// "checkJs": false, /* Report errors in .js files. */
// "jsx": "preserve", /* Specify JSX code generation: 'preserve', 'react-native', or 'react'. */

@@ -70,4 +70,5 @@ "declaration": true, /* Generates corresponding '.d.ts' file. */

"test",
"build"
"dist",
"examples"
]
}