Skip to content

Commit

Permalink
Release 0.14.0
Browse files Browse the repository at this point in the history
  • Loading branch information
raucao committed Nov 30, 2016
1 parent 6749be6 commit 1672d0e
Show file tree
Hide file tree
Showing 15 changed files with 1,366 additions and 442 deletions.
4 changes: 2 additions & 2 deletions bower.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
{
"name": "remotestorage",
"version": "0.13.0",
"version": "0.14.0",
"main": [
"./release/stable/remotestorage.js"
],
"license": "MIT",
"homepage": "https://github.com/remotestorage/remotestorage.js",
"keywords": ["localstorage", "indexeddb", "storage", "offline", "no-backend", "unhosted"]
"keywords": ["localstorage", "indexeddb", "storage", "offline", "no-backend", "unhosted", "offline-first"]
}
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "remotestoragejs",
"description": "JavaScript library for integrating remoteStorage",
"version": "0.13.1-pre",
"version": "0.14.0",
"private": false,
"license": "MIT",
"main": "./node-main.js",
Expand Down
137 changes: 122 additions & 15 deletions release/head/remotestorage-nocache.amd.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/** remotestorage.js 0.13.1-pre, http://remotestorage.io, MIT-licensed **/
/** remotestorage.js 0.14.0, http://remotestorage.io, MIT-licensed **/
define([], function() {

/** FILE: src/remotestorage.js **/
Expand Down Expand Up @@ -171,6 +171,18 @@ define([], function() {
*
* Fired when a wire request completes
**/
/**
* Event: network-offline
*
* Fired once when a wire request fails for the first time, and
* `remote.online` is set to false
**/
/**
* Event: network-online
*
* Fired once when a wire request succeeds for the first time after a
* failed one, and `remote.online` is set back to true
**/

// Initial configuration property settings.
if (typeof cfg === 'object') {
Expand All @@ -180,8 +192,9 @@ define([], function() {

RemoteStorage.eventHandling(
this, 'ready', 'connected', 'disconnected', 'not-connected', 'conflict',
'error', 'features-loaded', 'connecting', 'authing', 'wire-busy',
'wire-done', 'sync-interval-change'
'error', 'features-loaded', 'connecting', 'authing',
'sync-interval-change', 'wire-busy', 'wire-done',
'network-offline', 'network-online'
);

// pending get/put/delete calls.
Expand Down Expand Up @@ -316,6 +329,20 @@ define([], function() {
* remoteStorage.scope('/public/pictures/').getListing('');
*/

/**
* Method: startSync
*
* Start synchronization with remote storage, downloading and uploading any
* changes within the cached paths.
*
* Please consider: local changes will attempt sync immediately, and remote
* changes should also be synced timely when using library defaults. So
* this is mostly useful for letting users sync manually, when pressing a
* sync button for example. This might feel safer to them sometimes, esp.
* when shifting between offline and online a lot.
*/
// (see src/sync.js for implementation)

/**
* Method: connect
*
Expand Down Expand Up @@ -1617,6 +1644,7 @@ define([], function() {
* Class : RemoteStorage.WireClient
**/
RS.WireClient = function (rs) {
this.rs = rs;
this.connected = false;

/**
Expand All @@ -1628,7 +1656,8 @@ define([], function() {
* Fired when the wireclient connect method realizes that it is in
* possession of a token and href
**/
RS.eventHandling(this, 'change', 'connected', 'wire-busy', 'wire-done', 'not-connected');
RS.eventHandling(this, 'change', 'connected', 'not-connected',
'wire-busy', 'wire-done');

onErrorCb = function (error){
if (error instanceof RemoteStorage.Unauthorized) {
Expand Down Expand Up @@ -1714,13 +1743,17 @@ define([], function() {
body: body,
headers: headers,
responseType: 'arraybuffer'
}).then(function (response) {
}).then(function(response) {
if (!self.online) {
self.online = true;
self.rs._emit('network-online');
}
self._emit('wire-done', {
method: method,
isFolder: isFolder(uri),
success: true
});
self.online = true;

if (isErrorStatus(response.status)) {
RemoteStorage.log('[WireClient] Error response status', response.status);
if (getEtag) {
Expand Down Expand Up @@ -1756,11 +1789,16 @@ define([], function() {
}
}
}, function (error) {
if (self.online) {
self.online = false;
self.rs._emit('network-offline');
}
self._emit('wire-done', {
method: method,
isFolder: isFolder(uri),
success: false
});

return Promise.reject(error);
});
},
Expand Down Expand Up @@ -6612,6 +6650,8 @@ Math.uuid = function (len, radix) {
var GD_DIR_MIME_TYPE = 'application/vnd.google-apps.folder';
var RS_DIR_MIME_TYPE = 'application/json; charset=UTF-8';

var isFolder = RemoteStorage.util.isFolder;

function buildQueryString(params) {
return Object.keys(params).map(function (key) {
return encodeURIComponent(key) + '=' + encodeURIComponent(params[key]);
Expand Down Expand Up @@ -6977,15 +7017,45 @@ Math.uuid = function (len, radix) {

_request: function (method, url, options) {
var self = this;

if (! options.headers) { options.headers = {}; }
options.headers['Authorization'] = 'Bearer ' + self.token;
return RS.WireClient.request(method, url, options).then(function (xhr) {
// google tokens expire from time to time...

this._emit('wire-busy', {
method: method,
isFolder: isFolder(url)
});

return RS.WireClient.request.call(this, method, url, options).then(function(xhr) {
// Google tokens expire from time to time...
if (xhr && xhr.status === 401) {
self.connect();
return;
} else {
if (!self.online) {
self.online = true;
self.rs._emit('network-online');
}
self._emit('wire-done', {
method: method,
isFolder: isFolder(url),
success: true
});

return Promise.resolve(xhr);
}
}, function(error) {
if (self.online) {
self.online = false;
self.rs._emit('network-offline');
}
return xhr;
self._emit('wire-done', {
method: method,
isFolder: isFolder(url),
success: false
});

return Promise.reject(error);
});
}
};
Expand Down Expand Up @@ -7062,6 +7132,8 @@ Math.uuid = function (len, radix) {
var SETTINGS_KEY = 'remotestorage:dropbox';
var PATH_PREFIX = '/remotestorage';

var isFolder = RemoteStorage.util.isFolder;

/**
* Function: getDropboxPath(path)
*
Expand Down Expand Up @@ -7630,15 +7702,49 @@ Math.uuid = function (len, radix) {
*/
_request: function (method, url, options) {
var self = this;

if (! options.headers) { options.headers = {}; }
options.headers['Authorization'] = 'Bearer ' + this.token;
return RS.WireClient.request.call(this, method, url, options).then(function (xhr) {
//503 means retry this later

this._emit('wire-busy', {
method: method,
isFolder: isFolder(url)
});

return RS.WireClient.request.call(this, method, url, options).then(function(xhr) {
// 503 means retry this later
if (xhr && xhr.status === 503) {
if (self.online) {
self.online = false;
self.rs._emit('network-offline');
}

return global.setTimeout(self._request(method, url, options), 3210);
} else {
if (!self.online) {
self.online = true;
self.rs._emit('network-online');
}
self._emit('wire-done', {
method: method,
isFolder: isFolder(url),
success: true
});

return Promise.resolve(xhr);
}
}, function(error) {
if (self.online) {
self.online = false;
self.rs._emit('network-offline');
}
self._emit('wire-done', {
method: method,
isFolder: isFolder(url),
success: false
});

return Promise.reject(error);
});
},

Expand Down Expand Up @@ -7717,8 +7823,8 @@ Math.uuid = function (len, radix) {
}, function (err) {
this.rs.log('fetchDeltas', err);
this.rs._emit('error', new RemoteStorage.SyncError('fetchDeltas failed.' + err));
promise.reject(err);
}).then(function () {
return Promise.resolve(args);
}.bind(this)).then(function () {
if (self._revCache) {
var args = Array.prototype.slice.call(arguments);
self._revCache._activatePropagation();
Expand Down Expand Up @@ -7866,7 +7972,7 @@ Math.uuid = function (len, radix) {
}
};

//hooking and unhooking the sync
// Hooking and unhooking the sync

function hookSync(rs) {
if (rs._dropboxOrigSync) { return; } // already hooked
Expand All @@ -7875,6 +7981,7 @@ Math.uuid = function (len, radix) {
return this.dropbox.fetchDelta.apply(this.dropbox, arguments).
then(rs._dropboxOrigSync, function (err) {
rs._emit('error', new RemoteStorage.SyncError(err));
return Promise.reject(err);
});
}.bind(rs);
}
Expand All @@ -7885,7 +7992,7 @@ Math.uuid = function (len, radix) {
delete rs._dropboxOrigSync;
}

// hooking and unhooking getItemURL
// Hooking and unhooking getItemURL

function hookGetItemURL(rs) {
if (rs._origBaseClientGetItemURL) { return; }
Expand Down
Loading

0 comments on commit 1672d0e

Please sign in to comment.