Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

emit payload overwritten #153

Closed
AndresSepar opened this issue Sep 18, 2017 · 6 comments
Closed

emit payload overwritten #153

AndresSepar opened this issue Sep 18, 2017 · 6 comments
Labels

Comments

@AndresSepar
Copy link

Hi, @kbrsh... when you emit something like:

instance.emit('doSomething', {product: 'cheese', type: 'cheddar'});

// emit overwrites the property 'type' with emit eventName param 'doSomething'
console.log(payload); // {product: 'cheese', type: 'doSomething'}

I think that emit payload could be:

{
  data: {product: 'cheese', type: 'cheddar'},
  type: 'doSomething'
}
@kbrsh
Copy link
Owner

kbrsh commented Sep 20, 2017

How about something like:

instance.on("foo", (type, data) => {
  console.log(type, data);
});

instance.emit("foo", {bar: 3}); // note: data doesn't have to be an object

@kbrsh kbrsh added the feature label Sep 20, 2017
@AndresSepar
Copy link
Author

Looks good!

@kbrsh
Copy link
Owner

kbrsh commented Sep 20, 2017

Awesome! I'll definitely add this once I'm done rewriting the virtual DOM engine. This change should actually reduce the size a little, but is breaking and will come in v1.

@AndresSepar
Copy link
Author

In this way, type could be an optional param:

instance.on("foo", (data, type) => {
  console.log(data, type);
});

@kbrsh
Copy link
Owner

kbrsh commented Sep 23, 2017

Looking good! I think I should actually remove the type completely except for the global event.

instance.on("foo", (data) => {
  // data can be anything
});

instance.on("*", (type, data) => {
  // access to both the type of event and the data passed
});

@AndresSepar
Copy link
Author

Great idea!

@kbrsh kbrsh closed this as completed in 18ffb75 Sep 25, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants