Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@eroc/core

Package Overview
Dependencies
Maintainers
1
Versions
24
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@eroc/core - npm Package Compare versions

Comparing version 1.1.0 to 2.0.0

67

dist/core.es.js

@@ -1,2 +0,2 @@

/* @eroc/core v1.1.0 2019-09-14T22:21:31.696Z licensed MIT */
/* @eroc/core v2.0.0 2019-11-16T15:46:54.617Z licensed MIT */
/**

@@ -151,2 +151,3 @@ * Use it as a constructor

const ALL = Symbol();
const ERROR = Symbol();

@@ -167,5 +168,9 @@ const Core = class {

if (this.moduleInstances.has(name)) {
throw `module with name ${name} already started`;
return Promise.reject(`module with name ${name} already started`);
}
if (!module.start) {
return Promise.reject(`module must have start defined`);
}
const emitter = new EventEmitter3();

@@ -175,10 +180,20 @@

this.moduleInstances.set(name, {
module,
instance: module.start(emitter),
name,
emitter,
return Promise.resolve().then(() => {
return module.start(emitter);
}).then(instance => {
this.moduleInstances.set(name, {
module,
instance,
name,
emitter,
});
}).then(() => {
return name;
}).catch(errorModuleStart => {
this.emit(ERROR, {
time: Date.now(),
phase: `module.start`,
error: errorModuleStart,
});
});
return name;
}

@@ -190,13 +205,21 @@

if (!wrapper) {
return false;
return Promise.resolve(false);
}
wrapper.emitter.off();
if (wrapper.module.stop) {
wrapper.module.stop(wrapper.instance);
}
this.moduleInstances.delete(name);
return true;
return Promise.resolve().then(() => {
this.moduleInstances.delete(name);
if (wrapper.module.stop) {
wrapper.module.stop(wrapper.instance);
}
}).catch(errorModuleStop => {
this.emit(ERROR, {
time: Date.now(),
phase: `module.stop`,
error: errorModuleStop,
});
}).then(() => {
return true;
});
}

@@ -215,3 +238,11 @@

this.moduleInstances.forEach(({ emitter }) => {
EventEmitter3.prototype.emit.call(emitter, name, data);
try {
EventEmitter3.prototype.emit.call(emitter, name, data);
} catch (error) {
this.emit(ERROR, {
time: Date.now(),
phase: `module runtime (emitter.on)`,
error,
});
}
});

@@ -221,2 +252,2 @@ }

export { ALL, Core };
export { ALL, Core, ERROR };

@@ -1,2 +0,2 @@

/* @eroc/core v1.1.0 2019-09-14T22:21:31.696Z licensed MIT */
/* @eroc/core v2.0.0 2019-11-16T15:46:54.617Z licensed MIT */
var Core = (function (exports) {

@@ -154,2 +154,3 @@ 'use strict';

const ALL = Symbol();
const ERROR = Symbol();

@@ -170,5 +171,9 @@ const Core = class {

if (this.moduleInstances.has(name)) {
throw `module with name ${name} already started`;
return Promise.reject(`module with name ${name} already started`);
}
if (!module.start) {
return Promise.reject(`module must have start defined`);
}
const emitter = new EventEmitter3();

@@ -178,10 +183,20 @@

this.moduleInstances.set(name, {
module,
instance: module.start(emitter),
name,
emitter,
return Promise.resolve().then(() => {
return module.start(emitter);
}).then(instance => {
this.moduleInstances.set(name, {
module,
instance,
name,
emitter,
});
}).then(() => {
return name;
}).catch(errorModuleStart => {
this.emit(ERROR, {
time: Date.now(),
phase: `module.start`,
error: errorModuleStart,
});
});
return name;
}

@@ -193,13 +208,21 @@

if (!wrapper) {
return false;
return Promise.resolve(false);
}
wrapper.emitter.off();
if (wrapper.module.stop) {
wrapper.module.stop(wrapper.instance);
}
this.moduleInstances.delete(name);
return true;
return Promise.resolve().then(() => {
this.moduleInstances.delete(name);
if (wrapper.module.stop) {
wrapper.module.stop(wrapper.instance);
}
}).catch(errorModuleStop => {
this.emit(ERROR, {
time: Date.now(),
phase: `module.stop`,
error: errorModuleStop,
});
}).then(() => {
return true;
});
}

@@ -218,3 +241,11 @@

this.moduleInstances.forEach(({ emitter }) => {
EventEmitter3.prototype.emit.call(emitter, name, data);
try {
EventEmitter3.prototype.emit.call(emitter, name, data);
} catch (error) {
this.emit(ERROR, {
time: Date.now(),
phase: `module runtime (emitter.on)`,
error,
});
}
});

@@ -226,2 +257,3 @@ }

exports.Core = Core;
exports.ERROR = ERROR;

@@ -228,0 +260,0 @@ return exports;

@@ -1,2 +0,2 @@

/* @eroc/core v1.1.0 2019-09-14T22:21:31.696Z licensed MIT */
/* @eroc/core v2.0.0 2019-11-16T15:46:54.617Z licensed MIT */
(function (global, factory) {

@@ -157,2 +157,3 @@ typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) :

const ALL = Symbol();
const ERROR = Symbol();

@@ -173,5 +174,9 @@ const Core = class {

if (this.moduleInstances.has(name)) {
throw `module with name ${name} already started`;
return Promise.reject(`module with name ${name} already started`);
}
if (!module.start) {
return Promise.reject(`module must have start defined`);
}
const emitter = new EventEmitter3();

@@ -181,10 +186,20 @@

this.moduleInstances.set(name, {
module,
instance: module.start(emitter),
name,
emitter,
return Promise.resolve().then(() => {
return module.start(emitter);
}).then(instance => {
this.moduleInstances.set(name, {
module,
instance,
name,
emitter,
});
}).then(() => {
return name;
}).catch(errorModuleStart => {
this.emit(ERROR, {
time: Date.now(),
phase: `module.start`,
error: errorModuleStart,
});
});
return name;
}

@@ -196,13 +211,21 @@

if (!wrapper) {
return false;
return Promise.resolve(false);
}
wrapper.emitter.off();
if (wrapper.module.stop) {
wrapper.module.stop(wrapper.instance);
}
this.moduleInstances.delete(name);
return true;
return Promise.resolve().then(() => {
this.moduleInstances.delete(name);
if (wrapper.module.stop) {
wrapper.module.stop(wrapper.instance);
}
}).catch(errorModuleStop => {
this.emit(ERROR, {
time: Date.now(),
phase: `module.stop`,
error: errorModuleStop,
});
}).then(() => {
return true;
});
}

@@ -221,3 +244,11 @@

this.moduleInstances.forEach(({ emitter }) => {
EventEmitter3.prototype.emit.call(emitter, name, data);
try {
EventEmitter3.prototype.emit.call(emitter, name, data);
} catch (error) {
this.emit(ERROR, {
time: Date.now(),
phase: `module runtime (emitter.on)`,
error,
});
}
});

@@ -229,2 +260,3 @@ }

exports.Core = Core;
exports.ERROR = ERROR;

@@ -231,0 +263,0 @@ Object.defineProperty(exports, '__esModule', { value: true });

{
"name": "@eroc/core",
"version": "1.1.0",
"version": "2.0.0",
"main": "dist/core.umd.js",

@@ -5,0 +5,0 @@ "module": "dist/core.es.js",

@@ -13,2 +13,4 @@ # core [![Build Status](https://travis-ci.org/mauriciosoares/core.js.svg?branch=master)](https://travis-ci.org/mauriciosoares/core.js) [![Coverage Status](https://img.shields.io/coveralls/mauriciosoares/core.js.svg)](https://coveralls.io/r/mauriciosoares/core.js) [![Code Climate](https://codeclimate.com/github/mauriciosoares/core.js/badges/gpa.svg)](https://codeclimate.com/github/mauriciosoares/core.js)

The central piece is the core.
A module should never talks directly to another module, for that you use a combination of listeners and notifications.

@@ -35,11 +37,11 @@

`import { Core } from "./node_modules/@eroc/core/dist/core.js";`
`import { Core, ALL, ERROR } from "./node_modules/@eroc/core/dist/core.js";`
With rollup, webpack or parcel
`import { Core } from "@eroc/core";`
`import { Core, ALL, ERROR } from "@eroc/core";`
NodeJs or Browserify
`const { Core } = require("@eroc/core");`
`const { Core, ALL, ERROR } = require("@eroc/core");`

@@ -62,6 +64,7 @@ Let's start with the tweet module.

// instance is what start returned
// this allows to close open files, sockets, etc
};
```
To start this module in your main file:
To start this module in your core file:

@@ -91,7 +94,7 @@ ```js

You might want to stop a module in some point, this can be easily done using the method `Core.stop()`.
You might want to stop a module in some point, this can be easily done using the method `core.stop()`.
```js
const exampleId = Core.start(exampleModule);
Core.stop(exampleId);
const exampleId = core.start(exampleModule);
core.stop(exampleId);
```

@@ -141,25 +144,47 @@

#### Core.start( module, options )
#### core.start(module, options)
* `module` The module as a name-space (import * as exampleModule from "./exampleModule.js")
* `options` optional object
* name optional, String or Symbol that become *moduleInstanceId*
- `module` The module as a name-space (import * as exampleModule from "./exampleModule.js")
- `options` (function): The implementation of the module
returns a promise that resolves with *moduleInstanceId* that can later be used to stop the module
__Usage__
```js
Core.start(exampleModule)
const exampleInstanceId = await Core.start(exampleModule);
```
#### Core.stop( moduleInstanceId )
#### core.stop(moduleInstanceId)
moduleInstanceId is what is returned by Core.start or the name used with Core.start
```js
await core.stop(exampleInstanceId);
```
__Usage__
#### ALL
Constant to listen to all events
```js
Core.stop(moduleInstanceId);
// listen for all events
core.on(ALL, ({ name, data, time }) => {
const timeString = new Date(time).toISOString();
console.debug(`${timeString} event ${String(name)} with data`, data);
});
```
#### ERROR
Constant to listen to most errors
```js
// listen for errors
core.on(ERROR, ({ time, phase, error }) => {
const timeString = new Date(time).toISOString();
console.error(`Error during phase ${phase} at ${timeString}`);
console.error(error);
});
```
## tl;dr

@@ -193,19 +218,25 @@

* 1.1.0 introduce event recorder and player
* 1.0.0 stable release
* 0.15.0 major architecture change
* 2018-10-30 v0.13.0 remove deprecated startAll and stopAll
* 2018-10-29 v0.12.0 Drop bower and publish on npm
* 2018 Various changes
* 2015-06-15   v0.7.3   Refactor UMD
* 2015-05-14   v0.7.2   Hotfix with ID's
* 2015-02-15   v0.7.0   Deprecate `Core.stopAll`
* 2015-02-12   v0.6.0   Deprecate `Core.startAll`
* 2015-02-05   v0.5.0   Changes `x` to `use` in `Sandbox`
* 2015-01-17   v0.4.0   Add UMD
* 2015-01-15   v0.3.0   Ability to return values from init and destroy methods
* 2015-01-10   v0.2.1   Improve error messages
* 2014-12-30   v0.2.0   Isolation of DOM in modules
* 2014-12-21   v0.1.0   Release usable version
### 2.0.0
* core.start, core.stop return Promises
* the module start and stop can return a promise
* errors are emitted
### 1.1.0 introduce event recorder and player
### 1.0.0 stable release
### 0.15.0 major architecture change
### 2018-10-30 v0.13.0 remove deprecated startAll and stopAll
### 2018-10-29 v0.12.0 Drop bower and publish on npm
### 2018 Various changes
### 2015-06-15   v0.7.3   Refactor UMD
### 2015-05-14   v0.7.2   Hotfix with ID's
### 2015-02-15   v0.7.0   Deprecate `Core.stopAll`
### 2015-02-12   v0.6.0   Deprecate `Core.startAll`
### 2015-02-05   v0.5.0   Changes `x` to `use` in `Sandbox`
### 2015-01-17   v0.4.0   Add UMD
### 2015-01-15   v0.3.0   Ability to return values from init and destroy methods
### 2015-01-10   v0.2.1   Improve error messages
### 2014-12-30   v0.2.0   Isolation of DOM in modules
### 2014-12-21   v0.1.0   Release usable version
## License

@@ -212,0 +243,0 @@

@@ -1,2 +0,2 @@

export { Core, ALL };
export { Core, ALL, ERROR };
import EventEmitter from "../node_modules/event-e3/event-e3.js";

@@ -6,2 +6,3 @@

const ALL = Symbol();
const ERROR = Symbol();

@@ -22,5 +23,9 @@ const Core = class {

if (this.moduleInstances.has(name)) {
throw `module with name ${name} already started`;
return Promise.reject(`module with name ${name} already started`);
}
if (!module.start) {
return Promise.reject(`module must have start defined`);
}
const emitter = new EventEmitter();

@@ -30,10 +35,20 @@

this.moduleInstances.set(name, {
module,
instance: module.start(emitter),
name,
emitter,
return Promise.resolve().then(() => {
return module.start(emitter);
}).then(instance => {
this.moduleInstances.set(name, {
module,
instance,
name,
emitter,
});
}).then(() => {
return name;
}).catch(errorModuleStart => {
this.emit(ERROR, {
time: Date.now(),
phase: `module.start`,
error: errorModuleStart,
});
});
return name;
}

@@ -45,13 +60,21 @@

if (!wrapper) {
return false;
return Promise.resolve(false);
}
wrapper.emitter.off();
if (wrapper.module.stop) {
wrapper.module.stop(wrapper.instance);
}
this.moduleInstances.delete(name);
return true;
return Promise.resolve().then(() => {
this.moduleInstances.delete(name);
if (wrapper.module.stop) {
wrapper.module.stop(wrapper.instance);
}
}).catch(errorModuleStop => {
this.emit(ERROR, {
time: Date.now(),
phase: `module.stop`,
error: errorModuleStop,
});
}).then(() => {
return true;
});
}

@@ -70,5 +93,13 @@

this.moduleInstances.forEach(({ emitter }) => {
EventEmitter.prototype.emit.call(emitter, name, data);
try {
EventEmitter.prototype.emit.call(emitter, name, data);
} catch (error) {
this.emit(ERROR, {
time: Date.now(),
phase: `module runtime (emitter.on)`,
error,
});
}
});
}
};

@@ -30,3 +30,3 @@ export { replayEvents };

const timeDifference = events[i].time - event.time;
setTimeout(playNext, timeDifference); v
setTimeout(playNext, timeDifference);
return;

@@ -33,0 +33,0 @@ }

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc