Skip to content
pgib edited this page Jan 3, 2015 · 14 revisions

Directory of Rivets.js adapters with compatibility tables for common libraries and frameworks.

Backbone.js models / Stapes.js

rivets.configure({
  adapter: {
    observe: function(obj, keypath, callback) {
      obj.on("change:" + keypath, callback)
    },
    unobserve: function(obj, keypath, callback) {
      obj.off("change:" + keypath, callback)
    },
    get: function(obj, keypath) {
      return obj.get(keypath)
    },
    set: function(obj, keypath, value) {
      obj.set(keypath, value)
    }
  }
})

Backbone.js models with (partial) support for backbone-relational

CanJS

rivets.configure({
  adapter: {
    observe: function(obj, keypath, callback) {
      obj.bind('change', function(ev, attr, how, newVal, oldVal) {
        callback(newVal)
      })
    },
    unobserve: function(obj, keypath, callback) {
      obj.unbind('change', callback)
    },
    get: function(obj, keypath) {
      return obj.attr(keypath)
    },
    set: function(obj, keypath, value) {
      obj.attr(keypath, value)
    }
  }
})

Iota Observable

https://github.com/helgoboss/rivets-iota-observable-adapter

Watch.js

rivets.configure({
  adapter: {
    observe: function(obj, keypath, callback) {
      watch(obj, keypath, callback)
    },
    unobserve: function(obj, keypath, callback) {
      unwatch(obj, keypath, callback)
    },
    get: function(obj, keypath) {
      return obj[keypath]
    },
    set: function(obj, keypath, value) {
      obj[keypath] = value
    }
  }
})

YUI

Rivets adapter for Y.Model.

rivets.adapters[':'] = {                                            
  observe: function(obj, keypath, callback) {                     
    return obj.afterHandle = obj.after(keypath + 'Change', callback);  
  },                                                                
  unobserve: function(obj, keypath, callback) {                   
    var _ref;                                                       
    return (_ref = obj.afterHandle) != null ? _ref.detach() : void 0;  
  },                                                                
  get: function(obj, keypath) {                                    
    return obj.get(keypath);                                        
  },                                                                
  set: function(obj, keypath, value) {                          
    return obj.set(keypath, value);                                 
  }                                                                 
rivets.adapters[':'] =

  observe: (obj, keypath, callback) ->
    obj.afterHandle = obj.after(keypath + 'Change', callback)

  unobserve: (obj, keypath, callback) ->
    obj.afterHandle?.detach()

  get: (obj, keypath) ->
    obj.get(keypath)

  set: (obj, keypath, value) ->
    obj.set(keypath, value)