3 ms·
I would create a global mediator: export var mediator = _.extend({}, Backbone.Events); And then use it to listen to messages in Views: m.mediator.on(
by agilebyte 13y ago
I would create a global mediator:
export var mediator = _.extend({}, Backbone.Events);
And then use it to listen to messages in Views:
m.mediator.on('change:page change:sort change:tags', this.renderTable, this);
And fire them from Models/Collections:
m.mediator.trigger('change:sort', sortOrder);
Instead of listening to changes on them:
this.paginator.bind('change', fn, this);
So I can plug & play different parts of the system together.
Edit: A link from Addy Osmani: http://addyosmani.com/largescalejavascript/#mediatorpattern http://addyosmani.com/largescalejavascript/#mediatorpattern
- steveklabnik 13y agoHave you tried out functional reactive programming? How does it compare to the mediator?
- agilebyte 13y agoYou mean like Bacon.js? I have not, yet. Looking at it now it seems that it is used for filtering/mapping/combining values? The messages I send are more light weight and usually say "this has happened" to which a View would respond by re-rendering itself or its part rather then me directly passing whole Models and Collections around.
- steveklabnik 13y agoYup! It sounds quite a bit like your mediator: make a stream, send events in the stream, certain things respond to the stream. Check out this talk: http://vimeo.com/68987289 http://vimeo.com/68987289