bs-pixi
bs-pixi copied to clipboard
Using return values
Im trying to use your EventEmitter binding to reproduce the primus demo without success. I can't see to reproduce the example.
This it js primus demo:
var EE = new EventEmitter();
var context = { foo: 'bar' };
function emitted() {
console.log(this === context); // true
}
EE.once('event-name', emitted, context);
EE.on('another-event', emitted, context);
EE.removeListener('another-event', emitted, context);
EE.on('foo', function () {
console.log('new connection');
});
EE.on('foo', function (color) {
console.log('color is', color);
});
EE.emit
eventEmitter->emit(~event=`String("foo,blue"));
eventEmitter->eventNames |> Js.log2("blue:nameEmitter");
Which produces:
~/D/p/echo ❯❯❯ node src/index.js
new connection
color is blue
In reason:
let noParams = () => {
Js.log( "noParams");
};
// works but is useless
eventEmitter |. addListener(~event=`String("foo"), ~fn=noParams,noParams());
let emitted = result => {
Js.log2("emitted called on foo: ", result); // true
// let checked = result === context;
// Js.log(checked); // true
};
open EventEmitter;
let eventEmitter = create();
let callback = color => {
Js.log("color is: " ++ color);
};
let onColor = foo => Js.log("color is: " ++ foo);
eventEmitter |. addListener(~event=`String("blue"), ~fn=(color) => onColor(color),());
eventEmitter->emit(~event=`String("foo,blue"));
eventEmitter->eventNames |> Js.log2("foo:nameEmitter");
gets me undefined. I have tried a bunch of other way obviously. How would you suggest I think through this?
Thank you, sir;
@idkjs: your reason code looks valid for me from the first glace, will try repro it soon and provide you more feedback on this
Just thinking out loud. I think my issue is that in the context of your program, you are defining the event types you are passing to the emitter for example here: https://github.com/ambientlight/bs-pixi/blob/982271c7dc9ee013dfd4b4e079f0285bec1f396c/examples/basic_container/src/Index.re#L28
I imagine that passing the sprite to the container is properly formatted and fits the Js.t({..}) being expected. So maybe to use the emitter on its own, I would need to define what it the Js.t({}) looks like and pass that to it....
Again, just thinking out loud. No pressure here. Just studying your code, brother.
Peace to you.