Skip to content

Instantly share code, notes, and snippets.

@JemiloII
Last active April 8, 2018 04:17
Show Gist options
  • Save JemiloII/82f3b4076ec0988558c4 to your computer and use it in GitHub Desktop.
Save JemiloII/82f3b4076ec0988558c4 to your computer and use it in GitHub Desktop.
This is just the beginning of the native storage promise system
Storage.prototype._setItem = Storage.prototype.setItem;
Storage.prototype.setItem = function(key, value, type, name) {
var eventName = name || 'storage';
var eventObject = {
"target": window,
"type": "storage",
"bubbles": false,
"cancelable": false,
"key": key,
"oldValue": type.getItem(key),
"newValue": value,
"url": window.location.href,
"storageArea": type
};
this._setItem(key, value);
window.dispatchEvent(new StorageEvent(eventName, eventObject));
};
window.addEventListener('storage', function(e){ document.querySelector('body').innerHTML = e.newValue;});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment