Socket
Socket
Sign inDemoInstall

ddd-es-node

Package Overview
Dependencies
14
Maintainers
1
Versions
211
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 0.0.18 to 0.0.19

2

package.json
{
"name": "ddd-es-node",
"version": "0.0.18",
"version": "0.0.19",
"description": "ddd-es-node",

@@ -5,0 +5,0 @@ "main": "./dist/src/index.js",

@@ -19,7 +19,7 @@ # ddd-es-node

constructor(id) {
super(id, Entity.CONFIG((self, event) => {
super(id, (self, event) => {
if(event instanceof OrderCancelledEvent) {
this.cancelled = true;
}
}));
});
}

@@ -26,0 +26,0 @@ cancel() {

@@ -12,6 +12,7 @@ import {

constructor(id) {
super(id, Entity.CONFIG((self, event) => {
super(id, (self, event) => {
self.lastEventReceived = event;
}));
});
}
doSomething() {

@@ -23,6 +24,6 @@ this.dispatch(this.id, new TestEvent());

class TestEntitySuperclass extends Entity {
constructor(id, eventProcessor) {
super(id, Entity.CONFIG((self, event) => {
constructor(id, eventHandler) {
super(id, (self, event) => {
self.lastEventReceivedFromSuperclass = event;
}).apply(eventProcessor));
}, eventHandler);
}

@@ -65,3 +66,3 @@ }

afterEach(() => {
while(events.length > 0) {
while (events.length > 0) {
events.pop();

@@ -68,0 +69,0 @@ }

@@ -8,38 +8,24 @@ import {

export class EventProcessor {
private handler : EventHandler;
public apply(newHandler : EventHandler) : EventProcessor {
const parentHandler : EventHandler = this.handler;
let handlerToSet : EventHandler = newHandler;
if (parentHandler) {
handlerToSet = (entity : Entity, event : EntityEvent) : void => {
newHandler(entity, event);
parentHandler(entity, event);
};
const composeHandlers = (...handlers : EventHandler[]) : EventHandler => {
if (handlers.length === 1) {
return handlers[0];
}
return (entity : Entity, event : EntityEvent) => {
for (let i = handlers.length - 1; i >= 0; --i) {
handlers[i](entity, event);
}
this.handler = handlerToSet;
return this;
}
};
};
public accept(entity : Entity, event : EntityEvent) : void {
this.handler(entity, event);
}
}
export class Entity {
protected id : string;
protected config : EventProcessor;
protected applier : EventHandler;
protected dispatch : VoidEventDispatcher;
constructor(id : string,
config : EventProcessor) {
...appliers : EventHandler[]) {
this.id = id;
this.config = config;
this.applier = composeHandlers(...appliers);
}
public static CONFIG(newHandler : EventHandler) : EventProcessor {
return new EventProcessor().apply(newHandler);
}
public init(dispatch : VoidEventDispatcher) : void {

@@ -50,5 +36,5 @@ this.dispatch = dispatch;

public apply(event : EntityEvent) : void {
this.config.accept(this, event);
this.applier(this, event);
}
}
SocketSocket SOC 2 Logo

Product

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc