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

eventm

Package Overview
Dependencies
Maintainers
1
Versions
9
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

eventm - npm Package Compare versions

Comparing version 1.2.1 to 1.3.0

33

eventm.js

@@ -20,12 +20,9 @@ const Eventm = function() {

const executeCallback = cb => {
if (options.promise) {
_engine.state === 'resolve'
? options.resolve(_engine.dataInCache)
: options.reject(_engine.dataInCache);
}
if (typeof(cb) !== "function") {
return undefined;
}
if (options.disableErrorParameter && _engine.state === "resolve") {
return cb(_engine.dataInCache);
if (options.promise === true) {
return _engine.state === "reject"
? undefined
: cb(_engine.dataInCache);
}

@@ -46,2 +43,7 @@ return cb(

_engine.stack.map(cb => executeCallback(cb));
if (options.promise === true) {
_engine.state === 'resolve'
? options.resolve(_engine.dataInCache)
: options.reject(_engine.dataInCache);
}
// _engine.stack = [];

@@ -55,7 +57,7 @@ };

this.push = cb => {
const elemId = _engine.stack.push(cb) - 1;
_engine.stack.push(cb) - 1;
if (_engine.state !== null && options.keepSession) {
return executeCallback(cb);
executeCallback(cb);
}
return elemId;
return this.getPromise();
};

@@ -68,3 +70,3 @@

this.getEvent = name => listEvents[name];
this.create = (name, cb, options) => {
this.create = (name, options) => {
// configuration options

@@ -77,10 +79,6 @@ options = options || {};

: true,
disableErrorParameter:
typeof options.disableErrorParameter === "boolean"
? options.disableErrorParameter
: true,
promise:
typeof options.promise === "boolean"
? options.promise
: false
: true
};

@@ -90,4 +88,3 @@

listEvents[name] = listEvents[name] || new childEvent(name, options);
listEvents[name].push(cb);
return listEvents[name].getPromise();
return listEvents[name];
};

@@ -94,0 +91,0 @@

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

const Eventm=function(){const a=function(a,b){const c={dataInCache:null,state:null,stack:[]},d=b.promise&&new Promise((a,c)=>{b.resolve=a,b.reject=c})||void 0,e=a=>(b.promise&&("resolve"===c.state?b.resolve(c.dataInCache):b.reject(c.dataInCache)),"function"==typeof a?b.disableErrorParameter&&"resolve"===c.state?a(c.dataInCache):a("reject"===c.state&&c.dataInCache,"resolve"===c.state&&c.dataInCache):void 0),f=(b,d)=>f=>{if(null!==c.state&&!d)throw a+"_statement_is_already_set_to_"+c.state;c.state=b,c.dataInCache=f,c.stack.map(a=>e(a))};return this.getPromise=()=>d,this.resolveForced=f("resolve",!0),this.resolve=f("resolve"),this.reject=f("reject"),this.push=a=>{const d=c.stack.push(a)-1;return null!==c.state&&b.keepSession?e(a):d},this},b={};return this.getEvent=a=>b[a],this.create=(c,d,e)=>(e=e||{},e={keepSession:"boolean"!=typeof e.keepSession||e.keepSession,disableErrorParameter:"boolean"!=typeof e.disableErrorParameter||e.disableErrorParameter,promise:"boolean"==typeof e.promise&&e.promise},b[c]=b[c]||new a(c,e),b[c].push(d),b[c].getPromise()),this};module&&module.exports&&(module.exports=Eventm);
const Eventm=function(){const a=function(a,b){const c={dataInCache:null,state:null,stack:[]},d=b.promise&&new Promise((a,c)=>{b.resolve=a,b.reject=c})||void 0,e=a=>"function"==typeof a?!0===b.promise?"reject"===c.state?void 0:a(c.dataInCache):a("reject"===c.state&&c.dataInCache,"resolve"===c.state&&c.dataInCache):void 0,f=(d,f)=>g=>{if(null!==c.state&&!f)throw a+"_statement_is_already_set_to_"+c.state;c.state=d,c.dataInCache=g,c.stack.map(a=>e(a)),"resolve"===c.state?b.resolve(c.dataInCache):b.reject(c.dataInCache)};return this.getPromise=()=>d,this.resolveForced=f("resolve",!0),this.resolve=f("resolve"),this.reject=f("reject"),this.push=a=>(c.stack.push(a)-1,null!==c.state&&b.keepSession&&e(a),this.getPromise()),this},b={};return this.getEvent=a=>b[a],this.create=(c,d)=>(d=d||{},d={keepSession:"boolean"!=typeof d.keepSession||d.keepSession,promise:"boolean"!=typeof d.promise||d.promise},b[c]=b[c]||new a(c,d),b[c]),this};module&&module.exports&&(module.exports=Eventm);

@@ -6,30 +6,23 @@ // -------------- BEHIND

{
this.tryEventInSingleParam = (cb) => mevent.create('tryEventInSingleParam', cb);
setTimeout(() => mevent.getEvent('tryEventInSingleParam').resolve('tryEventInSingleParam function executed'), 1000);
this.tryEvenSuccessCallback = (cb) => mevent.create('tryEvenSuccessCallback').push(cb);
setTimeout(() => mevent.getEvent('tryEvenSuccessCallback').resolve('tryEvenSuccessCallback function executed'), 1000);
this.tryEventMultiParams = (cb) => mevent.create('tryEventMultiParams', cb, { disableErrorParameter: false });
this.tryEventMultiParams = (cb) => mevent.create('tryEventMultiParams', { promise: false }).push(cb);
setTimeout(() => mevent.getEvent('tryEventMultiParams').resolve('tryEventMultiParams function executed'), 2000);
this.tryEventWithPromise = (cb) => mevent.create('tryEventWithPromise', cb, { promise: true });
setTimeout(() => mevent.getEvent('tryEventWithPromise').resolve('tryEventWithPromise function executed'), 3000);
this.tryEventKeepSession = (cb) => mevent.create('tryEventKeepSession').push(cb);
setTimeout(() => mevent.getEvent('tryEventKeepSession').resolve('tryEventKeepSession function executed'), 3000);
this.tryEventKeepSession = (cb) => mevent.create('tryEventKeepSession', cb, { promise: true });
setTimeout(() => mevent.getEvent('tryEventKeepSession').resolve('tryEventKeepSession function executed'), 4000);
this.tryEventDontKeepSession = (cb) => mevent.create('tryEventDontKeepSession', cb, { keepSession: false, promise: true });
this.tryEventDontKeepSession = (cb) => mevent.create('tryEventDontKeepSession', { keepSession: false }).push(cb);
setTimeout(() => mevent.getEvent('tryEventDontKeepSession').resolve('tryEventDontKeepSession function executed'), 4000);
this.tryAnEventInReject = () => {
mevent.create('tryAnEventInReject', null, { promise: true });
setTimeout(() => mevent.getEvent('tryAnEventInReject').reject('tryAnEventInReject function executed'), 5000);;
};
this.tryAnEventInReject = () => mevent.create('tryAnEventInReject').getPromise();
setTimeout(() => mevent.getEvent('tryAnEventInReject').reject('tryAnEventInReject function executed'), 7000);
}
// -------------- AHEAD
myLib.tryEventInSingleParam(data => {
myLib.tryEvenSuccessCallback(data => {
console.log(data);
myLib.tryEventMultiParams(async (err, data) => {
console.log(err, data);
data = await myLib.tryEventWithPromise();
console.log(data);
data = await myLib.tryEventKeepSession();

@@ -36,0 +29,0 @@ console.log(data);

{
"name": "eventm",
"version": "1.2.1",
"description": "Eventm help you to manage all evenements in your code. The library store the state and the callback stack for you.",
"version": "1.3.0",
"description": "Eventm help you to manage all evenements in your code. The library store the state, data returned and the callback stack for you. Can be used like RabbitMQ in your local project.",
"main": "eventm.min.js",

@@ -6,0 +6,0 @@ "scripts": {

# Event Manager
Eventm help you to manage all evenements in your code. The library store the state and the callback stack for you.
Eventm help you to manage all evenements in your code. The library store the state, data returned and the callback stack for you.
Can be used like RabbitMQ in your local project.

@@ -13,3 +14,3 @@ ## ☁️ Installation

``` js
// -------------- BEHIND LIBRARY SIDE
// -------------- BEHIND
const Eventm = require('eventm');

@@ -20,30 +21,24 @@ const mevent = new Eventm();

{
this.tryEventInSingleParam = (cb) => mevent.create('tryEventInSingleParam', cb);
setTimeout(() => mevent.getEvent('tryEventInSingleParam').resolve('tryEventInSingleParam function executed'), 1000);
const eventSucessCb = mevent.create('tryEvenSuccessCallback');
this.tryEvenSuccessCallback = (cb) => eventSucessCb.push(cb);
setTimeout(() => mevent.getEvent('tryEvenSuccessCallback').resolve('tryEvenSuccessCallback function executed'), 1000);
this.tryEventMultiParams = (cb) => mevent.create('tryEventMultiParams', cb, { disableErrorParameter: false });
this.tryEventMultiParams = (cb) => mevent.create('tryEventMultiParams', { promise: false }).push(cb);
setTimeout(() => mevent.getEvent('tryEventMultiParams').resolve('tryEventMultiParams function executed'), 2000);
this.tryEventWithPromise = (cb) => mevent.create('tryEventWithPromise', cb, { promise: true });
setTimeout(() => mevent.getEvent('tryEventWithPromise').resolve('tryEventWithPromise function executed'), 3000);
this.tryEventKeepSession = (cb) => mevent.create('tryEventKeepSession').push(cb);
setTimeout(() => mevent.getEvent('tryEventKeepSession').resolve('tryEventKeepSession function executed'), 3000);
this.tryEventKeepSession = (cb) => mevent.create('tryEventKeepSession', cb, { promise: true });
setTimeout(() => mevent.getEvent('tryEventKeepSession').resolve('tryEventKeepSession function executed'), 4000);
this.tryEventDontKeepSession = (cb) => mevent.create('tryEventDontKeepSession', cb, { keepSession: false, promise: true });
this.tryEventDontKeepSession = (cb) => mevent.create('tryEventDontKeepSession', { keepSession: false }).push(cb);
setTimeout(() => mevent.getEvent('tryEventDontKeepSession').resolve('tryEventDontKeepSession function executed'), 4000);
this.tryAnEventInReject = () => {
mevent.create('tryAnEventInReject', null, { promise: true });
setTimeout(() => mevent.getEvent('tryAnEventInReject').reject('tryAnEventInReject function executed'), 5000);;
};
this.tryAnEventInReject = () => mevent.create('tryAnEventInReject').getPromise();
setTimeout(() => mevent.getEvent('tryAnEventInReject').reject('tryAnEventInReject function executed'), 7000);
}
// -------------- AHEAD
myLib.tryEventInSingleParam(data => {
// -------------- AHEAD
myLib.tryEvenSuccessCallback(data => {
console.log(data);
myLib.tryEventMultiParams(async (err, data) => {
console.log(err, data);
data = await myLib.tryEventWithPromise();
console.log(data);
data = await myLib.tryEventKeepSession();

@@ -68,6 +63,6 @@ console.log(data);

| Name | Description
| --------------------------------------------------------------------- | ------------
| create(string: name, function: callback = null, object: options = {}) | `create` method is used to create a new event and/or push a new callback
| getEvent(string: name) | `getEvent` method is used to retrieve `event level`
| Name | Description
| ----------------------------------------------------------| ------------
| create(string: name, object: options = {}): `Event Level` | `create` method is used to create a new event
| getEvent(string: name): `Event Level` | `getEvent` method is used to retrieve `event level`

@@ -78,6 +73,6 @@ ### Event level

| ----------------------------------------------------------------- | ------------
| resolve(any: data = undefined) | `resolve` method is used to set a success response
| resolveForced(any: data = undefined) | `resolveForced` method is used to set a success response in forced mode (it means: if there are already a statement then this forces the system to recall all callbacks with the new paramter). Obviously it doesn't works for promise.
| reject(any: data = undefined) | `reject` method is used to set an error response
| push(function: callback = null) | `push` method is used to add new callback
| resolve(any: data = undefined): undefined | `resolve` method is used to set a success response
| resolveForced(any: data = undefined): undefined | `resolveForced` method is used to set a success response in forced mode (it means: if there are already a statement then this forces the system to recall all callbacks with the new paramter). Obviously it doesn't works for promise.
| reject(any: data = undefined): undefined | `reject` method is used to set an error response
| push(function: callback): Promise | `push` method is used to add new callback

@@ -88,4 +83,3 @@ ## Options

| --------------------- | ------- | -----------
| disableErrorParameter | true | true = When the callback is executing, only `data` parameter is accessible
| keepSession | true | true = If the callback is alreayd executed, `keepSession` keep the session open for the futur callback
| promise | false | true = Enable Promise and `create` method return a Promise
| promise | false | true = The callback is called with a single paramter - false = The callback is call with (`err`, `data`) => {} parameters
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