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

Wrong logic is used in case of events #21

Closed
kkamkou opened this issue Jan 15, 2016 · 6 comments
Closed

Wrong logic is used in case of events #21

kkamkou opened this issue Jan 15, 2016 · 6 comments

Comments

@kkamkou
Copy link

kkamkou commented Jan 15, 2016

Events are used to notify other listeners about an event. What you did, is just a wrapper for a new object.

What was expected:

  • drop-zone emits an event, I can subscribe and react

What we have:

  • {{drop-zone url=imageUploadUrl addRemoveLinks=true complete=(action "onUploadComplete")}}
  • The result is: I've created a new object with MY OWN complete event, replacing the default one.

How to fix:

  • In case of events, you should register a callback using the emit function. Preserving the native event. Example: instance.on('complete', this.complete)

Workaround:

@kmiyashiro
Copy link

Yes, it seems that you are actually overriding the hooks instead of adding event listeners. Maybe adding properties like onaddedfile etc for adding event listeners to dropzone events would work. I think this problem is compounded by the fact that access to the Dropzone instance is impossible by actions unless you extend the component.

@FutoRicky
Copy link
Owner

I am having trouble understanding the issue. How would I go to recreate this problem?

Also, @kkamkou try assigning a function property instead of an action to the complete attribute.

@kkamkou
Copy link
Author

kkamkou commented Jan 15, 2016

try assigning a function property instead of an action

It doesn't matter. In the variant you propose me, I lose the context of the callback. And it won't fix the problem.

Yes, it seems that you are actually overriding the hooks instead of adding event listeners.

true

I am having trouble understanding the issue.

I see it from the code. All you need to do (in case you want to fix it) is to register events like events and not like an attribute. forEach() if (this.complete is function) {dropzone.on('complete', this.complete)}

@FutoRicky
Copy link
Owner

@kkamkou oohh yes I see. Thanks for pointing this out. Will definitely fix this.

@FutoRicky
Copy link
Owner

Fixed the event handling logic 7eb7b33.

Declare the event function in controller for example:

addedFileEvent: Ember.computed(function() {
  return function() {
    // do something...
  };
}),

Declare component

{{drop-zone url=http://example.com addfile=addedFileEvent}}

You can update to version 0.7.0 to have this fix

@kkamkou
Copy link
Author

kkamkou commented Jan 16, 2016

It works, thank you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants