Wildhoney / EmberSockets

Socket.io (WebSockets) integrated with Ember.js' observer pattern.
http://ember-sockets.herokuapp.com/
MIT License
136 stars 22 forks source link

How make a subclass mix his `sockets` hash with the `sockets` hash existing in a parent class #43

Closed felipehw closed 10 years ago

felipehw commented 10 years ago

The actions hash in controllers inherit action handlers from parent classes ... how can i mimic this behavior with sockets hash in controllers?

I explained this problem in: https://stackoverflow.com/questions/26661229/how-do-a-hash-property-in-a-parent-class-controller-be-mixed-with-a-property-wit

Wildhoney commented 10 years ago

One solution could be to implement the init method and merge the two objects yourself:

// ...
    concatenatedProperties: ['sockets'],
    init: function init() {
        var sockets = this.get('sockets'),
            merged  = $.extend(sockets[0], sockets[1]);
        this.set('sockets', merged);
        this._super();
    }
// ...
felipehw commented 10 years ago

Many thanks @Wildhoney ! Works perfectly. One improvement is allow the merge with more than two objects dynamically:

concatenatedProperties: ['sockets'],
init: function() {
  var that = this,
      sockets = that.get('sockets'),
      merged = Ember.$.extend.apply( Ember.$, sockets );

  that.set('sockets', merged);
  that._super();
},
Wildhoney commented 10 years ago

Thanks. Nicely done :+1: