AmpersandJS / ampersand-sync

Provides sync behavior for updating data from ampersand models and collections to the server.
http://ampersandjs.com
MIT License
20 stars 28 forks source link

Feature request: pluggable transports #21

Closed emdin closed 9 years ago

emdin commented 9 years ago

Ampersand-sync can be upgraded to work on server, to do so xhr or any other transport should be pluggable. Something along the lines:

var request = require('request');
var xhr = require('xhr');
var sync = require('ampersand-sync')({ 
    transport: (typeof window === 'undefined')? request: xhr 
});
naugtur commented 9 years ago

Is there an idea how you (maintainers) would like it to work? I could implement that while making the switch to xhr v2.0 I'd just prefer to know your opinion before I submit a PR

naugtur commented 9 years ago

This got accidentally done in xhr2-and-node branch.

var sync = require("ampersand-sync/core")(whateverXhrYouWant)

Also, if you just wanted to switch between xhr for the browser and request for node, that's going to happen without any setup.