Sunday, 29 September 2013

Events getting lost when moving to a RequireJS setup

Events getting lost when moving to a RequireJS setup

So, I am porting a small Backbone app to a RequireJS setup, surprisingly I
get a problem with this code:

define([
'jquery',
'underscore',
'backbone',
'channel',
'templates'
], function ($, _, Backbone, channel, JST) {
'use strict';
var SomeView = Backbone.View.extend({
// ... template, render
initialize: function() {
var that = this;
// was working previosuly, not sure why not now...
// this.collection.on('reset', function() {
// that.render()
// });
// hack:
this.collection.deferred.then(function() {
that.render()
});
So, I found that introducing an event bus like this helps:
this.listenTo(channel, 'reset', function(id) {
that.render()
});
But I am not sure if I miss something else. Does communication between
modules with RequireJS involve in general an event bus, or can I debug the
missing 'reset' event in another way?
Thanks!

No comments:

Post a Comment