angular-tiny-eventemitter icon indicating copy to clipboard operation
angular-tiny-eventemitter copied to clipboard

What is the this.value for?

Open ghost opened this issue 9 years ago • 4 comments

Hi, could you please explain why do you need the this.value from the readme.

ghost avatar Nov 12 '15 22:11 ghost

You don't. Just use it on any service. Anything in MyType is an example, replace it with what you need.

Sorry for the confusion!

rubenv avatar Nov 13 '15 14:11 rubenv

Thanks, it's clear, that it is just a demo, but maybe it's a useful feature? How could I make use of it? Maybe this is possible?

var ev1 = new MyType(1);
var ev2 = new MyType(2);

var cb = function() { /* how to access this.value (1, 2) here */ }; // 

ev1.on('event', cb)
ev2.on('event', cb)

ev1.emit('event')
ev2.emit('event')

Or would you suggest to use it like this:

...
var cb = function(value) { console.log(value) };
...
ev1.emit('event', ev1.value)
ev2.emit('event', ev2.value)

ghost avatar Nov 13 '15 14:11 ghost

Heh, hadn't considered that possibility.

What you could do is to change this line: https://github.com/rubenv/angular-tiny-eventemitter/blob/a6ef4f0e5d84df7eb2650bcbfc0b29df051e5696/src/tiny-eventemitter.js#L76

Replace null with this. That will allow you to use this.value in callbacks.

rubenv avatar Nov 13 '15 14:11 rubenv

awesome, pr is coming

ghost avatar Nov 13 '15 14:11 ghost