I have a controller that defines onDragEvent:
controller = Em.Object.create( {
onDragEvent: function() {
console.log("Drag Event");
}
});
And I have a Mixin:
Event = Ember.Mixin.create( {
attributeBindings: 'draggable',
draggable: 'true',
drag: function (event) {
Em.run.throttle(this, controller.onDragEvent, 1000);
}
});
My understanding is that during the drag the controller.onDragEvent should be called once every 1000 milliseconds.
The console is logging out:
Uncaught TypeError: Object function (a,b){var d,e;f.begin();try{if(a||b)d=c(a,b,arguments,2)}finally{f.end()}return d} has no method 'throttle' Events.js:42
Events.Ember.Mixin.create.drag Events.js:42
Ember.View.Ember.Object.extend.trigger ember-1.0.pre.min.js:16
d ember-1.0.pre.min.js:14
Ember.View.states.hasElement.handleEvent ember-1.0.pre.min.js:16
Ember.View.Ember.Object.extend.invokeForState ember-1.0.pre.min.js:16
Ember.View.Ember.Object.extend.handleEvent ember-1.0.pre.min.js:16
(anonymous function) ember-1.0.pre.min.js:16
c ember-1.0.pre.min.js:14
Ember.run ember-1.0.pre.min.js:14
Ember.EventDispatcher.Ember.Object.extend._bubbleEvent ember-1.0.pre.min.js:16
(anonymous function) ember-1.0.pre.min.js:16
f.event.dispatch jquery-1.7.2.min.js:3
h.handle.i
I'm pretty sure I don't understand how to use the throttle feature. I also notice that I am using Em.Object.create
vs. Ember.Mixin.create
, but calling the controller.onDragEvent
without the throttle works fine. What am I doing incorrectly?
edit 1:
if I use:
Event = Ember.Mixin.create( {
attributeBindings: 'draggable',
draggable: 'true',
drag: function (event) {
Em.run.throttle(controller, onDragEvent, 1000);
}
});
I get a different error:
Uncaught ReferenceError: onDragEvent is not defined
For reference; just calling controller.onDragEvent();
works fine.