Skip to content

Commit

Permalink
5.0.1
Browse files Browse the repository at this point in the history
  • Loading branch information
pubkey committed Mar 23, 2023
1 parent c5369e8 commit 2311480
Show file tree
Hide file tree
Showing 12 changed files with 162 additions and 104 deletions.
26 changes: 16 additions & 10 deletions dist/es5node/leader-election-web-lock.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,32 +26,38 @@ var LeaderElectionWebLock = function LeaderElectionWebLock(broadcastChannel, opt
this._dpLC = false; // true when onduplicate called

this._wKMC = {}; // stuff for cleanup

// lock name
this.lN = 'pubkey-bc||' + broadcastChannel.method.type + '||' + broadcastChannel.name;
};
exports.LeaderElectionWebLock = LeaderElectionWebLock;
LeaderElectionWebLock.prototype = {
hasLeader: function hasLeader() {
var _this2 = this;
return navigator.locks.query().then(function (locks) {
if (locks.held && locks.held.length > 0) {
var relevantLocks = locks.held ? locks.held.filter(function (lock) {
return lock.name === _this2.lN;
}) : [];
if (relevantLocks && relevantLocks.length > 0) {
return true;
} else {
return false;
}
});
},
awaitLeadership: function awaitLeadership() {
var _this2 = this;
var _this3 = this;
if (!this._wLMP) {
this._wKMC.c = new AbortController();
var returnPromise = new Promise(function (res, rej) {
_this2._wKMC.res = res;
_this2._wKMC.rej = rej;
_this3._wKMC.res = res;
_this3._wKMC.rej = rej;
});
this._wLMP = new Promise(function (res) {
var lockId = 'pubkey-bc||' + _this2.broadcastChannel.method.type + '||' + _this2.broadcastChannel.name;
navigator.locks.request(lockId, {
signal: _this2._wKMC.c.signal
navigator.locks.request(_this3.lN, {
signal: _this3._wKMC.c.signal
}, function () {
(0, _leaderElectionUtil.beLeader)(_this2);
(0, _leaderElectionUtil.beLeader)(_this3);
res();
return returnPromise;
});
Expand All @@ -63,10 +69,10 @@ LeaderElectionWebLock.prototype = {
// Do nothing because there are no duplicates in the WebLock version
},
die: function die() {
var _this3 = this;
var _this4 = this;
var ret = (0, _leaderElectionUtil.sendLeaderMessage)(this, 'death');
this._lstns.forEach(function (listener) {
return _this3.broadcastChannel.removeEventListener('internal', listener);
return _this4.broadcastChannel.removeEventListener('internal', listener);
});
this._lstns = [];
this._unl.forEach(function (uFn) {
Expand Down
27 changes: 16 additions & 11 deletions dist/esbrowser/leader-election-web-lock.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,32 +21,37 @@ export var LeaderElectionWebLock = function LeaderElectionWebLock(broadcastChann
this._dpLC = false; // true when onduplicate called

this._wKMC = {}; // stuff for cleanup
};

// lock name
this.lN = 'pubkey-bc||' + broadcastChannel.method.type + '||' + broadcastChannel.name;
};
LeaderElectionWebLock.prototype = {
hasLeader: function hasLeader() {
var _this2 = this;
return navigator.locks.query().then(function (locks) {
if (locks.held && locks.held.length > 0) {
var relevantLocks = locks.held ? locks.held.filter(function (lock) {
return lock.name === _this2.lN;
}) : [];
if (relevantLocks && relevantLocks.length > 0) {
return true;
} else {
return false;
}
});
},
awaitLeadership: function awaitLeadership() {
var _this2 = this;
var _this3 = this;
if (!this._wLMP) {
this._wKMC.c = new AbortController();
var returnPromise = new Promise(function (res, rej) {
_this2._wKMC.res = res;
_this2._wKMC.rej = rej;
_this3._wKMC.res = res;
_this3._wKMC.rej = rej;
});
this._wLMP = new Promise(function (res) {
var lockId = 'pubkey-bc||' + _this2.broadcastChannel.method.type + '||' + _this2.broadcastChannel.name;
navigator.locks.request(lockId, {
signal: _this2._wKMC.c.signal
navigator.locks.request(_this3.lN, {
signal: _this3._wKMC.c.signal
}, function () {
beLeader(_this2);
beLeader(_this3);
res();
return returnPromise;
});
Expand All @@ -58,10 +63,10 @@ LeaderElectionWebLock.prototype = {
// Do nothing because there are no duplicates in the WebLock version
},
die: function die() {
var _this3 = this;
var _this4 = this;
var ret = sendLeaderMessage(this, 'death');
this._lstns.forEach(function (listener) {
return _this3.broadcastChannel.removeEventListener('internal', listener);
return _this4.broadcastChannel.removeEventListener('internal', listener);
});
this._lstns = [];
this._unl.forEach(function (uFn) {
Expand Down
27 changes: 16 additions & 11 deletions dist/esnode/leader-election-web-lock.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,32 +21,37 @@ export var LeaderElectionWebLock = function LeaderElectionWebLock(broadcastChann
this._dpLC = false; // true when onduplicate called

this._wKMC = {}; // stuff for cleanup
};

// lock name
this.lN = 'pubkey-bc||' + broadcastChannel.method.type + '||' + broadcastChannel.name;
};
LeaderElectionWebLock.prototype = {
hasLeader: function hasLeader() {
var _this2 = this;
return navigator.locks.query().then(function (locks) {
if (locks.held && locks.held.length > 0) {
var relevantLocks = locks.held ? locks.held.filter(function (lock) {
return lock.name === _this2.lN;
}) : [];
if (relevantLocks && relevantLocks.length > 0) {
return true;
} else {
return false;
}
});
},
awaitLeadership: function awaitLeadership() {
var _this2 = this;
var _this3 = this;
if (!this._wLMP) {
this._wKMC.c = new AbortController();
var returnPromise = new Promise(function (res, rej) {
_this2._wKMC.res = res;
_this2._wKMC.rej = rej;
_this3._wKMC.res = res;
_this3._wKMC.rej = rej;
});
this._wLMP = new Promise(function (res) {
var lockId = 'pubkey-bc||' + _this2.broadcastChannel.method.type + '||' + _this2.broadcastChannel.name;
navigator.locks.request(lockId, {
signal: _this2._wKMC.c.signal
navigator.locks.request(_this3.lN, {
signal: _this3._wKMC.c.signal
}, function () {
beLeader(_this2);
beLeader(_this3);
res();
return returnPromise;
});
Expand All @@ -58,10 +63,10 @@ LeaderElectionWebLock.prototype = {
// Do nothing because there are no duplicates in the WebLock version
},
die: function die() {
var _this3 = this;
var _this4 = this;
var ret = sendLeaderMessage(this, 'death');
this._lstns.forEach(function (listener) {
return _this3.broadcastChannel.removeEventListener('internal', listener);
return _this4.broadcastChannel.removeEventListener('internal', listener);
});
this._lstns = [];
this._unl.forEach(function (uFn) {
Expand Down
26 changes: 16 additions & 10 deletions dist/lib/browser.js
Original file line number Diff line number Diff line change
Expand Up @@ -428,32 +428,38 @@ var LeaderElectionWebLock = function LeaderElectionWebLock(broadcastChannel, opt
this._dpLC = false; // true when onduplicate called

this._wKMC = {}; // stuff for cleanup

// lock name
this.lN = 'pubkey-bc||' + broadcastChannel.method.type + '||' + broadcastChannel.name;
};
exports.LeaderElectionWebLock = LeaderElectionWebLock;
LeaderElectionWebLock.prototype = {
hasLeader: function hasLeader() {
var _this2 = this;
return navigator.locks.query().then(function (locks) {
if (locks.held && locks.held.length > 0) {
var relevantLocks = locks.held ? locks.held.filter(function (lock) {
return lock.name === _this2.lN;
}) : [];
if (relevantLocks && relevantLocks.length > 0) {
return true;
} else {
return false;
}
});
},
awaitLeadership: function awaitLeadership() {
var _this2 = this;
var _this3 = this;
if (!this._wLMP) {
this._wKMC.c = new AbortController();
var returnPromise = new Promise(function (res, rej) {
_this2._wKMC.res = res;
_this2._wKMC.rej = rej;
_this3._wKMC.res = res;
_this3._wKMC.rej = rej;
});
this._wLMP = new Promise(function (res) {
var lockId = 'pubkey-bc||' + _this2.broadcastChannel.method.type + '||' + _this2.broadcastChannel.name;
navigator.locks.request(lockId, {
signal: _this2._wKMC.c.signal
navigator.locks.request(_this3.lN, {
signal: _this3._wKMC.c.signal
}, function () {
(0, _leaderElectionUtil.beLeader)(_this2);
(0, _leaderElectionUtil.beLeader)(_this3);
res();
return returnPromise;
});
Expand All @@ -465,10 +471,10 @@ LeaderElectionWebLock.prototype = {
// Do nothing because there are no duplicates in the WebLock version
},
die: function die() {
var _this3 = this;
var _this4 = this;
var ret = (0, _leaderElectionUtil.sendLeaderMessage)(this, 'death');
this._lstns.forEach(function (listener) {
return _this3.broadcastChannel.removeEventListener('internal', listener);
return _this4.broadcastChannel.removeEventListener('internal', listener);
});
this._lstns = [];
this._unl.forEach(function (uFn) {
Expand Down
2 changes: 1 addition & 1 deletion dist/lib/browser.min.js

Large diffs are not rendered by default.

26 changes: 16 additions & 10 deletions dist/lib/leader-election-web-lock.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,32 +26,38 @@ var LeaderElectionWebLock = function LeaderElectionWebLock(broadcastChannel, opt
this._dpLC = false; // true when onduplicate called

this._wKMC = {}; // stuff for cleanup

// lock name
this.lN = 'pubkey-bc||' + broadcastChannel.method.type + '||' + broadcastChannel.name;
};
exports.LeaderElectionWebLock = LeaderElectionWebLock;
LeaderElectionWebLock.prototype = {
hasLeader: function hasLeader() {
var _this2 = this;
return navigator.locks.query().then(function (locks) {
if (locks.held && locks.held.length > 0) {
var relevantLocks = locks.held ? locks.held.filter(function (lock) {
return lock.name === _this2.lN;
}) : [];
if (relevantLocks && relevantLocks.length > 0) {
return true;
} else {
return false;
}
});
},
awaitLeadership: function awaitLeadership() {
var _this2 = this;
var _this3 = this;
if (!this._wLMP) {
this._wKMC.c = new AbortController();
var returnPromise = new Promise(function (res, rej) {
_this2._wKMC.res = res;
_this2._wKMC.rej = rej;
_this3._wKMC.res = res;
_this3._wKMC.rej = rej;
});
this._wLMP = new Promise(function (res) {
var lockId = 'pubkey-bc||' + _this2.broadcastChannel.method.type + '||' + _this2.broadcastChannel.name;
navigator.locks.request(lockId, {
signal: _this2._wKMC.c.signal
navigator.locks.request(_this3.lN, {
signal: _this3._wKMC.c.signal
}, function () {
(0, _leaderElectionUtil.beLeader)(_this2);
(0, _leaderElectionUtil.beLeader)(_this3);
res();
return returnPromise;
});
Expand All @@ -63,10 +69,10 @@ LeaderElectionWebLock.prototype = {
// Do nothing because there are no duplicates in the WebLock version
},
die: function die() {
var _this3 = this;
var _this4 = this;
var ret = (0, _leaderElectionUtil.sendLeaderMessage)(this, 'death');
this._lstns.forEach(function (listener) {
return _this3.broadcastChannel.removeEventListener('internal', listener);
return _this4.broadcastChannel.removeEventListener('internal', listener);
});
this._lstns = [];
this._unl.forEach(function (uFn) {
Expand Down
26 changes: 16 additions & 10 deletions docs/e2e.js
Original file line number Diff line number Diff line change
Expand Up @@ -420,32 +420,38 @@ var LeaderElectionWebLock = function LeaderElectionWebLock(broadcastChannel, opt
this._dpLC = false; // true when onduplicate called

this._wKMC = {}; // stuff for cleanup

// lock name
this.lN = 'pubkey-bc||' + broadcastChannel.method.type + '||' + broadcastChannel.name;
};
exports.LeaderElectionWebLock = LeaderElectionWebLock;
LeaderElectionWebLock.prototype = {
hasLeader: function hasLeader() {
var _this2 = this;
return navigator.locks.query().then(function (locks) {
if (locks.held && locks.held.length > 0) {
var relevantLocks = locks.held ? locks.held.filter(function (lock) {
return lock.name === _this2.lN;
}) : [];
if (relevantLocks && relevantLocks.length > 0) {
return true;
} else {
return false;
}
});
},
awaitLeadership: function awaitLeadership() {
var _this2 = this;
var _this3 = this;
if (!this._wLMP) {
this._wKMC.c = new AbortController();
var returnPromise = new Promise(function (res, rej) {
_this2._wKMC.res = res;
_this2._wKMC.rej = rej;
_this3._wKMC.res = res;
_this3._wKMC.rej = rej;
});
this._wLMP = new Promise(function (res) {
var lockId = 'pubkey-bc||' + _this2.broadcastChannel.method.type + '||' + _this2.broadcastChannel.name;
navigator.locks.request(lockId, {
signal: _this2._wKMC.c.signal
navigator.locks.request(_this3.lN, {
signal: _this3._wKMC.c.signal
}, function () {
(0, _leaderElectionUtil.beLeader)(_this2);
(0, _leaderElectionUtil.beLeader)(_this3);
res();
return returnPromise;
});
Expand All @@ -457,10 +463,10 @@ LeaderElectionWebLock.prototype = {
// Do nothing because there are no duplicates in the WebLock version
},
die: function die() {
var _this3 = this;
var _this4 = this;
var ret = (0, _leaderElectionUtil.sendLeaderMessage)(this, 'death');
this._lstns.forEach(function (listener) {
return _this3.broadcastChannel.removeEventListener('internal', listener);
return _this4.broadcastChannel.removeEventListener('internal', listener);
});
this._lstns = [];
this._unl.forEach(function (uFn) {
Expand Down
Loading

0 comments on commit 2311480

Please sign in to comment.