Skip to content

Should work with objects that have their own event system #145

@matthewp

Description

@matthewp
Contributor

can-define should work with objects that already have an addEventListener, such as dom elements.

Activity

matthewp

matthewp commented on Feb 3, 2017

@matthewp
ContributorAuthor

I'll create a test with an object that has its own mini event emitter system so we can better look at the solution.

self-assigned this
on Feb 3, 2017
added a commit that references this issue on Feb 3, 2017
matthewp

matthewp commented on Feb 3, 2017

@matthewp
ContributorAuthor

Added a test here: c93641f

matthewp

matthewp commented on Feb 3, 2017

@matthewp
ContributorAuthor

@justinbmeyer I did a quick and dirty implementation that uses the element's native addEventListener here: 4fbb7eb

The result of that change is that the DOM events now fire but the property events do not (without that change the opposite happens).

added a commit that references this issue on Feb 7, 2017
237ef58
added a commit that references this issue on Feb 8, 2017
aead3d7
matthewp

matthewp commented on Mar 6, 2017

@matthewp
ContributorAuthor

Last I left off with this there was a problem with can-observation expecting 3 argument events.

I patched my local can-observation to fix this:

onDependencyChange: function(ev, newVal, oldVal){
  if(arguments.length === 1 && Array.isArray(ev.args)) {
    newVal = ev.args[0];
    newVal = ev.args[1];
  }

  this.dependencyChange(ev, newVal, oldVal);
},

However, it still fails because there is no batchNum associated with this event:

screen shot 2017-03-05 at 9 12 35 pm

The problem is that I changed can-define to use canEvent.trigger, which triggers real DOM events if it's a DOM element. However this fails because there is no batch stuff happening now.

So I'm not sure how to fix this now. I suppose maybe canEvent.trigger might need to do some batching.

justinbmeyer

justinbmeyer commented on Mar 6, 2017

@justinbmeyer
Contributor

@matthewp I've been thinking about this probably and how it relates to can-operate.onKeyValue. Some event systems won't have a batchNum. It might be possible to "force" this via the onKeyValue symbol / setup. Can explain more later.

justinbmeyer

justinbmeyer commented on Apr 19, 2017

@justinbmeyer
Contributor

@matthewp can-operate only expects a onKeyValue that will be called with the new value. We should talk about what this will mean for this effort.

matthewp

matthewp commented on Jan 12, 2018

@matthewp
ContributorAuthor

Just noting that this never was fully fixed, should revisit.

removed their assignment
on Dec 27, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @justinbmeyer@matthewp

        Issue actions

          Should work with objects that have their own event system · Issue #145 · canjs/can-define