component / reactive

Tiny reactive template engine
383 stars 48 forks source link

default adapter not available #128

Closed chemzqm closed 10 years ago

chemzqm commented 10 years ago

The new adapter API of reactive 1.0.0 is awesome, but the default adapter is missing. If I use component/model, I have to define the adapter every time I use reactive, which also makes some of examples not working like observe.html. Should we use default adapter in adapter.js like below?

Adapter.prototype.subscribe = function(prop, fn) {
  var model = this.obj;
  if (typeof model.on == 'function') {
    model.on('change ' + prop, fn);
  }
};

/**
 * Default unsubscription method.
 * Unsubscribe from changes on the model.
 */

Adapter.prototype.unsubscribe = function(prop, fn) {
  var model = this.obj;
  if (typeof model.off == 'function') {
    model.off('change ' + prop, fn);
  }
};

/**
 * Remove all subscriptions on this adapter
 */

Adapter.prototype.unsubscribeAll = function() {
  var model = this.obj;
  if (typeof model.off == 'function') {
    model.off();
  }
};
defunctzombie commented 10 years ago

The builtin adapter does not use events, if you want to handle models with events, then you need to specify the adapter to use. The examples should be fixed (separate issue). Yes, you have to specify the adapter every time if you want to use component/model. This is as designed.