chrisdavies / eev Goto Github PK
View Code? Open in Web Editor NEWA tiny, fast, zero-dependency event emitter
A tiny, fast, zero-dependency event emitter
Please advise what are safety guards using this library?
For example that only intended receiving application can process message from identified source application.
We are trying to use this library in micro-frontend applications
Can use event-bus placed in browser's window. as mentioned here, the scope is if I have multiple independent application as a Single-spa Application.
Thank You
Hi,
Is there a eev.d.ts
I can include in my typescript project?
I think this should be enough?
declare module Minute {
class Eev {
on(name: string, fn: Function);
off(name: string, fn: Function);
emit(name: string, data: Object);
constructor();
}
}
Thanks,
San
I'm working on an Angular 7 application, bundled with Webpack 4.
Inside a service file, I put the following code related to Eev
import * as Eev from 'eev';
export class RecipeService {
// create an Eev instance
e = new Eev.Eev();
functionToEmitEvent(ingredients: Ingredient[]) {
// add handler using Eev
this.e.on('ingrToShopList', (data) => {
console.log('Eev event ingrToShopList on');
console.log('ingrToShopList data: ' + data);
});
this.e.emit('ingrToShopList', ingredients);
this.e.off('ingrToShopList', (data) => {
console.log('Eev event ingrToShopList off');
console.log('ingrToShopList data: ' + data);
});
}
}
After bundling and starting the server, the app is not loaded and here is what shows up in console
ERROR TypeError: Eev.Eev is not a constructor
I tryed also with this code
import { Eev } from 'eev';
export class RecipeService {
// create an Eev instance
e = new Eev();
functionToEmitEvent(ingredients: Ingredient[]) {
// same as before
}
}
As few use jQuery anymore, I created a new test case comparing eev to using Vue as an eventBus. In it, you'll notice that it's considerably faster. I also tried it in Firefox, Safari and Edge (incorrectly reported as Chrome 51.0.2704), and eev's performance in these browsers is orders of magnitudes greater than against both Vue and jQuery.
Then, I decided to compare eev to the much more popular, Mitt and the results were, surprisingly to me, very similar to the massive performance improvements to the other libraries.
I really think you should publicise this.
Hi, is it possible with the current implementation to subscribe to all events with a single 'on()' call?
An example use case would be to have a (user-land) debugger that can listen to all events (without explicitly subscribing to all of them).
Thanks
I don't know if is only me, but the minified version doesn't work. It spills the
Uncaught SyntaxError: Unexpected token )
error just by loading it, in both, Firefox Developer Edition 47 and Chrome 50, at least.
I had to minify this with ShrinkSafe to get a acceptable size and a working script.
Seems like UglifyJS breaks this particular (because generally it's my chosen one too) code with their «optimizations». And same happens with other alternatives, like Google Closure minifier.
It would be great if Eev would support easy interoperability with RxJS fromEvent
https://rxjs-dev.firebaseapp.com/api/index/function/fromEvent
Currently, the only difficulty seems to be a minor type mismatch in the on
/ off
function signatures, which do not quite match JQueryStyleEventEmitter
.
changing
on(names: string, fn: CallbackFunction): void;
off(names: string, fn: CallbackFunction): void;
to
on(names: string, fn: Function): void;
off(names: string, fn: Function): void;
in eev.d.ts
would fix this and allow easy conversion of events to Observables through fromEvent
.
by this line, we made the callback to of
as mandatory which will not a case for many scenarios. Can we make this as optional?
Happy to raise a PR. 😃
Hi!
My TS compilation breaks and asks me to install @types/eev
. However, there is no such thing like that, because the ambient module declaration is right in the package. However, that is not picked up. That said there is a very simple fix:
https://stackoverflow.com/questions/46650399/how-do-i-reference-a-type-declared-in-a-typescript-d-ts-file-generated-by-tscs?rq=1
You just need to reference eev.d.ts
file in package.json
:
{
"main": "eev.js",
"types": "eev.d.ts",
"[...]": "[...]"
}
Hi,
I am trying to make two Angular apps and i want an event emitter to listen events commonly in between two different application just like micro frontend but i am unable to import this in angular 4 . Can please give some instruction to integrate this.
Hi,
I am trying to use Eev in the browser (using native JS).On importing the library, I am getting type error at line 65
!function(t, e) { var n = t.define; <- here n && n.amd ? n([], e) : "undefined" != typeof module && module.exports && (module.exports = e()) }(this, function() { return Eev });
Input:
var e = new Eev()
function myHandler (data) { console.log(data); }
e.on('some-event', myHandler);
e.emit('some-event', { foo: 'Bar' });
Expected:
{ foo: 'Bar' }
is passed to myHander
Actual:
Nothing happens.
Notes:
If some-event
is changed to some_event
or someevent
, then it works. If this is intentional, it should probably be documented somewhere.
For example, event "first-visibility:1"
not works.
Line 4 in f0117ab
You can use regex /[\s,]+/g
— split spaces or commas.
I use the shit out of this library in many projects, so thanks for saving me lots of pain and suffering :-)
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.