chrisdavies / eev

A tiny, fast, zero-dependency event emitter
522 stars 32 forks source link

Eev.Eev is not a constructor #15

Open gAllegr opened 5 years ago

gAllegr commented 5 years ago

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
  }
}
valepu commented 5 years ago

I was having a similar issue but i solved using import Eev from 'eev';

shilangyu commented 5 years ago

Its because the d.ts file says Eev is being exported as a property and as a default, whilst the code exports it as a default only. Therefore Eev should be imported as import Eev from 'eev'. I fixed this issue in #16