Skip to content

Commit

Permalink
0.4.0
Browse files Browse the repository at this point in the history
  • Loading branch information
danielstjules committed Nov 15, 2014
1 parent 3679b7c commit 6a5d2a1
Show file tree
Hide file tree
Showing 8 changed files with 72 additions and 34 deletions.
2 changes: 1 addition & 1 deletion bower.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "cross-storage",
"version": "0.3.3",
"version": "0.4.0",
"description": "Cross domain local storage",
"license": "Apache-2.0",
"authors": [
Expand Down
11 changes: 0 additions & 11 deletions dist/client-0.3.3.min.js

This file was deleted.

46 changes: 39 additions & 7 deletions dist/client-0.3.3.js → dist/client-0.4.0.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/**
* cross-storage - Cross domain local storage
*
* @version 0.3.3
* @version 0.4.0
* @link https://github.com/zendesk/cross-storage
* @author Daniel St. Jules <danielst.jules@gmail.com>
* @copyright Zendesk
Expand Down Expand Up @@ -126,20 +126,36 @@ CrossStorageClient._generateUUID = function() {

/**
* Returns a promise that is fulfilled when a connection has been established
* with the cross storage hub. Its use is recommended to avoid sending any
* with the cross storage hub. Its use is required to avoid sending any
* requests prior to initialization being complete.
*
* @returns {Promise} A promise that is resolved on connect
*/
CrossStorageClient.prototype.onConnect = function() {
var client = this;

if (this._connected) {
return this._promise.resolve();
} else if (this._closed) {
return this._promise.reject(new Error('CrossStorageClient has closed'));
}

var client = this;
// Queue connect requests for client re-use
if (!this._requests.connect) {
this._requests.connect = [];
}

return new this._promise(function(resolve, reject) {
client._requests.connect = resolve;
var timeout = setTimeout(function() {
reject(new Error('CrossStorageClient could not connect'));
}, client._timeout);

client._requests.connect.push(function(err) {
clearTimeout(timeout);
if (err) return reject(err);

resolve();
});
});
};

Expand Down Expand Up @@ -236,19 +252,35 @@ CrossStorageClient.prototype._installListener = function() {
var client = this;

this._listener = function(message) {
var i, error;

if (client._closed) return;

// Ignore messages not from our hub
if (message.origin !== client._origin) return;

// LocalStorage isn't available in the hub
if (message.data === 'unavailable') {
if (!client._closed) client.close();
if (!client._requests.connect) return;

error = new Error('Closing client. Could not access localStorage in hub.');
for (i = 0; i < client._requests.connect.length; i++) {
client._requests.connect[i](error);
}

return;
}

// Handle initial connection
if (!client._connected) {
client._connected = true;
if (!client._requests.connect) return;

if (client._requests.connect) {
client._requests.connect();
delete client._requests.connect;
for (i = 0; i < client._requests.connect.length; i++) {
client._requests.connect[i](error);
}
delete client._requests.connect;
}

if (message.data === 'ready') return;
Expand Down
11 changes: 11 additions & 0 deletions dist/client-0.4.0.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 0 additions & 11 deletions dist/hub-0.3.3.min.js

This file was deleted.

12 changes: 9 additions & 3 deletions dist/hub-0.3.3.js → dist/hub-0.4.0.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/**
* cross-storage - Cross domain local storage
*
* @version 0.3.3
* @version 0.4.0
* @link https://github.com/zendesk/cross-storage
* @author Daniel St. Jules <danielst.jules@gmail.com>
* @copyright Zendesk
Expand All @@ -28,12 +28,18 @@ var CrossStorageHub = {};
* @param {array} permissions An array of objects with origin and allow
*/
CrossStorageHub.init = function(permissions) {
var available = true;

// Return if localStorage is unavailable, or third party
// access is disabled
try {
if (!window.localStorage) return;
if (!window.localStorage) available = false;
} catch (e) {
return;
available = false;
}

if (!available) {
return window.parent.postMessage('unavailable', '*');
}

CrossStorageHub._permissions = permissions || [];
Expand Down
11 changes: 11 additions & 0 deletions dist/hub-0.4.0.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "cross-storage",
"version": "0.3.3",
"version": "0.4.0",
"description": "Cross domain local storage",
"keywords": [
"local",
Expand Down

0 comments on commit 6a5d2a1

Please sign in to comment.