Skip to content

Commit

Permalink
fix(pubsub): Update localStorage logic to function when cookies are d…
Browse files Browse the repository at this point in the history
…isabled
  • Loading branch information
stocaaro committed Jan 9, 2023
1 parent 51a1418 commit d5dfffc
Showing 1 changed file with 29 additions and 17 deletions.
46 changes: 29 additions & 17 deletions packages/pubsub/src/vendor/paho-mqtt.js
Original file line number Diff line number Diff line change
Expand Up @@ -102,23 +102,35 @@ function onMessageArrived(message) {
/**
* @private
*/
var localStorage =
global.localStorage ||
(function () {
var data = {};

return {
setItem: function (key, item) {
data[key] = item;
},
getItem: function (key) {
return data[key];
},
removeItem: function (key) {
delete data[key];
},
};
})();
var localStorage;
try {
} catch (_unused) {
console.log('asd');
}

try {
localStorage = global.localStorage;
} catch (e) {
console.log(e);
} finally {
localStorage =
localStorage ??
(function () {
var data = {};

return {
setItem: function (key, item) {
data[key] = item;
},
getItem: function (key) {
return data[key];
},
removeItem: function (key) {
delete data[key];
},
};
})();
}

/**
* Unique message type identifiers, with associated
Expand Down

0 comments on commit d5dfffc

Please sign in to comment.