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

@equinor/fusion-framework-module-event

Package Overview
Dependencies
Maintainers
3
Versions
63
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@equinor/fusion-framework-module-event - npm Package Compare versions

Comparing version 1.0.8 to 1.0.9

8

CHANGELOG.md

@@ -6,2 +6,10 @@ # Change Log

## 1.0.9 (2022-10-03)
**Note:** Version bump only for package @equinor/fusion-framework-module-event
## [1.0.8](https://github.com/equinor/fusion-framework/compare/@equinor/fusion-framework-module-event@1.0.7...@equinor/fusion-framework-module-event@1.0.8) (2022-09-29)

@@ -8,0 +16,0 @@

64

dist/esm/dispatcher.js

@@ -0,4 +1,11 @@

var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
export class FrameworkEventDispatcher {
__onDispatch;
__onBubble;
constructor({ onDispatch, onBubble }) {

@@ -8,27 +15,7 @@ this.__onDispatch = onDispatch;

}
async dispatch(event, listeners) {
try {
await this.__onDispatch?.(event);
}
catch (err) {
throw err;
}
const dispatchEvent = event;
if (!dispatchEvent.dispatcher) {
dispatchEvent.dispatcher = this;
}
else if (dispatchEvent.dispatcher === this) {
throw Error('loop detected');
}
for (const dispatch of listeners) {
if (!event.cancelable) {
dispatch(event);
}
else if (!event.canceled) {
await Promise.resolve(dispatch(event));
}
}
if (event.bubbles) {
dispatch(event, listeners) {
var _a, _b;
return __awaiter(this, void 0, void 0, function* () {
try {
await this.__onBubble?.(event);
yield ((_a = this.__onDispatch) === null || _a === void 0 ? void 0 : _a.call(this, event));
}

@@ -38,5 +25,28 @@ catch (err) {

}
}
const dispatchEvent = event;
if (!dispatchEvent.dispatcher) {
dispatchEvent.dispatcher = this;
}
else if (dispatchEvent.dispatcher === this) {
throw Error('loop detected');
}
for (const dispatch of listeners) {
if (!event.cancelable) {
dispatch(event);
}
else if (!event.canceled) {
yield Promise.resolve(dispatch(event));
}
}
if (event.bubbles) {
try {
yield ((_b = this.__onBubble) === null || _b === void 0 ? void 0 : _b.call(this, event));
}
catch (err) {
throw err;
}
}
});
}
}
//# sourceMappingURL=dispatcher.js.map
export class FrameworkEvent {
__type;
__detail;
__source;
__canceled = false;
__cancelable;
__canBubble;
__created = Date.now();
constructor(__type, args) {
this.__type = __type;
this.__canceled = false;
this.__created = Date.now();
this.__detail = args.detail;

@@ -12,0 +7,0 @@ this.__source = args.source;

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

var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
import { EventModuleProvider } from './provider';

@@ -7,7 +16,7 @@ export const moduleKey = 'event';

const configurator = {};
const parentProvider = ref?.event;
const parentProvider = ref === null || ref === void 0 ? void 0 : ref.event;
if (parentProvider) {
configurator.onBubble = async (e) => {
await parentProvider.dispatchEvent(e);
};
configurator.onBubble = (e) => __awaiter(void 0, void 0, void 0, function* () {
yield parentProvider.dispatchEvent(e);
});
}

@@ -14,0 +23,0 @@ return configurator;

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

var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
import { Observable, Subject } from 'rxjs';

@@ -5,8 +14,2 @@ import { FrameworkEventDispatcher } from './dispatcher';

export class EventModuleProvider extends Observable {
__listeners = [];
__event$ = new Subject();
__dispatcher;
get closed() {
return this.__event$.closed;
}
constructor(config) {

@@ -16,2 +19,4 @@ super((subscriber) => {

});
this.__listeners = [];
this.__event$ = new Subject();
this.__dispatcher = new FrameworkEventDispatcher({

@@ -22,2 +27,5 @@ onDispatch: config.onDispatch,

}
get closed() {
return this.__event$.closed;
}
addEventListener(type, handler) {

@@ -34,28 +42,32 @@ if (this.closed) {

}
async dispatchEvent(typeOrEvent, init) {
if (typeof typeOrEvent === 'string') {
if (!init) {
throw Error('invalid arguments, missing [FrameworkEventInit]');
dispatchEvent(typeOrEvent, init) {
return __awaiter(this, void 0, void 0, function* () {
if (typeof typeOrEvent === 'string') {
if (!init) {
throw Error('invalid arguments, missing [FrameworkEventInit]');
}
return this._dispatchEvent(new FrameworkEvent(typeOrEvent, init));
}
return this._dispatchEvent(new FrameworkEvent(typeOrEvent, init));
}
else {
return this._dispatchEvent(typeOrEvent);
}
else {
return this._dispatchEvent(typeOrEvent);
}
});
}
async _dispatchEvent(event) {
if (this.closed) {
throw Error('Cannot dispatch events when provider is closed!');
}
this.__event$.next(event);
try {
const listeners = this.__listeners
.filter((listener) => listener.type === event.type)
.map(({ handler }) => handler);
await this.__dispatcher.dispatch(event, listeners);
}
catch (err) {
throw err;
}
return event;
_dispatchEvent(event) {
return __awaiter(this, void 0, void 0, function* () {
if (this.closed) {
throw Error('Cannot dispatch events when provider is closed!');
}
this.__event$.next(event);
try {
const listeners = this.__listeners
.filter((listener) => listener.type === event.type)
.map(({ handler }) => handler);
yield this.__dispatcher.dispatch(event, listeners);
}
catch (err) {
throw err;
}
return event;
});
}

@@ -62,0 +74,0 @@ dispose() {

{
"name": "@equinor/fusion-framework-module-event",
"version": "1.0.8",
"version": "1.0.9",
"description": "Fusion module for events",

@@ -26,3 +26,3 @@ "main": "./dist/esm/index.js",

"dependencies": {
"@equinor/fusion-framework-module": "^1.2.2"
"@equinor/fusion-framework-module": "^1.2.3"
},

@@ -40,3 +40,3 @@ "devDependencies": {

},
"gitHead": "81198e7772ed6e1f0c318fc37c5b4f2a9fe72ada"
"gitHead": "573a97b7b0938a4cfad7063480ad88b5adab6ba1"
}

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

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