canjs / can-observable-mixin

Define properties on JavaScript classes
https://canjs.com
MIT License
2 stars 1 forks source link

Include onEvent in Type events mixin #136

Closed nlundquist closed 5 years ago

nlundquist commented 5 years ago

I noticed that classes that extend ObservableObject aren't able to be event targets since they don't implement the onKeyValue or onEvent symbols. Trying to set up a listener for an event on the class results in an error, e.g:

class Todo extends ObservableObject {
    ...
}

class CreatedTodos extends StacheElement {
  ...
  connected() {
    this.listenTo(Todo, "created", (ev, created) => {
      this.todos.unshift(created);
    })
  }
}

This will cause the error "Uncaught Error: can-event-queue: Unable to bind created".

To resolve this Justin suggested I add the can-event-queue/map/map mixin to mixin-typeevents.js.

nlundquist commented 5 years ago

I've added a test that dispatches an event on a type inheriting from the mixin object.