1.0.0 • Published 6 years ago
event-observer-factory v1.0.0
Event Observer
A simple event observer with vanilla JavaScript for the event communication of different JavaScript Layers. Maybe it is helpful for a MVC software architecture.
Simple Example with new version of JavaScript
// ./src/component-a.js
const EventObserverFactory = require('eventobserver');
class ComponentA {
constructor() {
this.eventObserver = EventObserverFactory.createEventObserver();
this.componentB = require('./component-b');
this.componentB.eventObserver;
this.eventObserver.subscribe(this.update);
}
update(value) {
console.log(value);
// ...
}
}
// ./src/component-b.js
class ComponentB {
constructor() {
this.prop = 'Hallo Welt';
this.log = [];
}
set observedProp(value) {
if (this.eventObserver) {
this.eventObserver.emit(value);
}
this.prop = 'Hallo Welt';
this.log.push(value);
}
}
module.exports = new ComponentB();
Usage for browser or any other (non CJS) environment
You can just use your favorite CJS bundler. If you have no favorite yet? Maybe you can try: Browserify or Webpack
1.0.0
6 years ago