Skip to content

Commit 2311480

Browse files
committed
5.0.1
1 parent c5369e8 commit 2311480

12 files changed

+162
-104
lines changed

dist/es5node/leader-election-web-lock.js

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -26,32 +26,38 @@ var LeaderElectionWebLock = function LeaderElectionWebLock(broadcastChannel, opt
2626
this._dpLC = false; // true when onduplicate called
2727

2828
this._wKMC = {}; // stuff for cleanup
29+
30+
// lock name
31+
this.lN = 'pubkey-bc||' + broadcastChannel.method.type + '||' + broadcastChannel.name;
2932
};
3033
exports.LeaderElectionWebLock = LeaderElectionWebLock;
3134
LeaderElectionWebLock.prototype = {
3235
hasLeader: function hasLeader() {
36+
var _this2 = this;
3337
return navigator.locks.query().then(function (locks) {
34-
if (locks.held && locks.held.length > 0) {
38+
var relevantLocks = locks.held ? locks.held.filter(function (lock) {
39+
return lock.name === _this2.lN;
40+
}) : [];
41+
if (relevantLocks && relevantLocks.length > 0) {
3542
return true;
3643
} else {
3744
return false;
3845
}
3946
});
4047
},
4148
awaitLeadership: function awaitLeadership() {
42-
var _this2 = this;
49+
var _this3 = this;
4350
if (!this._wLMP) {
4451
this._wKMC.c = new AbortController();
4552
var returnPromise = new Promise(function (res, rej) {
46-
_this2._wKMC.res = res;
47-
_this2._wKMC.rej = rej;
53+
_this3._wKMC.res = res;
54+
_this3._wKMC.rej = rej;
4855
});
4956
this._wLMP = new Promise(function (res) {
50-
var lockId = 'pubkey-bc||' + _this2.broadcastChannel.method.type + '||' + _this2.broadcastChannel.name;
51-
navigator.locks.request(lockId, {
52-
signal: _this2._wKMC.c.signal
57+
navigator.locks.request(_this3.lN, {
58+
signal: _this3._wKMC.c.signal
5359
}, function () {
54-
(0, _leaderElectionUtil.beLeader)(_this2);
60+
(0, _leaderElectionUtil.beLeader)(_this3);
5561
res();
5662
return returnPromise;
5763
});
@@ -63,10 +69,10 @@ LeaderElectionWebLock.prototype = {
6369
// Do nothing because there are no duplicates in the WebLock version
6470
},
6571
die: function die() {
66-
var _this3 = this;
72+
var _this4 = this;
6773
var ret = (0, _leaderElectionUtil.sendLeaderMessage)(this, 'death');
6874
this._lstns.forEach(function (listener) {
69-
return _this3.broadcastChannel.removeEventListener('internal', listener);
75+
return _this4.broadcastChannel.removeEventListener('internal', listener);
7076
});
7177
this._lstns = [];
7278
this._unl.forEach(function (uFn) {

dist/esbrowser/leader-election-web-lock.js

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -21,32 +21,37 @@ export var LeaderElectionWebLock = function LeaderElectionWebLock(broadcastChann
2121
this._dpLC = false; // true when onduplicate called
2222

2323
this._wKMC = {}; // stuff for cleanup
24-
};
2524

25+
// lock name
26+
this.lN = 'pubkey-bc||' + broadcastChannel.method.type + '||' + broadcastChannel.name;
27+
};
2628
LeaderElectionWebLock.prototype = {
2729
hasLeader: function hasLeader() {
30+
var _this2 = this;
2831
return navigator.locks.query().then(function (locks) {
29-
if (locks.held && locks.held.length > 0) {
32+
var relevantLocks = locks.held ? locks.held.filter(function (lock) {
33+
return lock.name === _this2.lN;
34+
}) : [];
35+
if (relevantLocks && relevantLocks.length > 0) {
3036
return true;
3137
} else {
3238
return false;
3339
}
3440
});
3541
},
3642
awaitLeadership: function awaitLeadership() {
37-
var _this2 = this;
43+
var _this3 = this;
3844
if (!this._wLMP) {
3945
this._wKMC.c = new AbortController();
4046
var returnPromise = new Promise(function (res, rej) {
41-
_this2._wKMC.res = res;
42-
_this2._wKMC.rej = rej;
47+
_this3._wKMC.res = res;
48+
_this3._wKMC.rej = rej;
4349
});
4450
this._wLMP = new Promise(function (res) {
45-
var lockId = 'pubkey-bc||' + _this2.broadcastChannel.method.type + '||' + _this2.broadcastChannel.name;
46-
navigator.locks.request(lockId, {
47-
signal: _this2._wKMC.c.signal
51+
navigator.locks.request(_this3.lN, {
52+
signal: _this3._wKMC.c.signal
4853
}, function () {
49-
beLeader(_this2);
54+
beLeader(_this3);
5055
res();
5156
return returnPromise;
5257
});
@@ -58,10 +63,10 @@ LeaderElectionWebLock.prototype = {
5863
// Do nothing because there are no duplicates in the WebLock version
5964
},
6065
die: function die() {
61-
var _this3 = this;
66+
var _this4 = this;
6267
var ret = sendLeaderMessage(this, 'death');
6368
this._lstns.forEach(function (listener) {
64-
return _this3.broadcastChannel.removeEventListener('internal', listener);
69+
return _this4.broadcastChannel.removeEventListener('internal', listener);
6570
});
6671
this._lstns = [];
6772
this._unl.forEach(function (uFn) {

dist/esnode/leader-election-web-lock.js

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -21,32 +21,37 @@ export var LeaderElectionWebLock = function LeaderElectionWebLock(broadcastChann
2121
this._dpLC = false; // true when onduplicate called
2222

2323
this._wKMC = {}; // stuff for cleanup
24-
};
2524

25+
// lock name
26+
this.lN = 'pubkey-bc||' + broadcastChannel.method.type + '||' + broadcastChannel.name;
27+
};
2628
LeaderElectionWebLock.prototype = {
2729
hasLeader: function hasLeader() {
30+
var _this2 = this;
2831
return navigator.locks.query().then(function (locks) {
29-
if (locks.held && locks.held.length > 0) {
32+
var relevantLocks = locks.held ? locks.held.filter(function (lock) {
33+
return lock.name === _this2.lN;
34+
}) : [];
35+
if (relevantLocks && relevantLocks.length > 0) {
3036
return true;
3137
} else {
3238
return false;
3339
}
3440
});
3541
},
3642
awaitLeadership: function awaitLeadership() {
37-
var _this2 = this;
43+
var _this3 = this;
3844
if (!this._wLMP) {
3945
this._wKMC.c = new AbortController();
4046
var returnPromise = new Promise(function (res, rej) {
41-
_this2._wKMC.res = res;
42-
_this2._wKMC.rej = rej;
47+
_this3._wKMC.res = res;
48+
_this3._wKMC.rej = rej;
4349
});
4450
this._wLMP = new Promise(function (res) {
45-
var lockId = 'pubkey-bc||' + _this2.broadcastChannel.method.type + '||' + _this2.broadcastChannel.name;
46-
navigator.locks.request(lockId, {
47-
signal: _this2._wKMC.c.signal
51+
navigator.locks.request(_this3.lN, {
52+
signal: _this3._wKMC.c.signal
4853
}, function () {
49-
beLeader(_this2);
54+
beLeader(_this3);
5055
res();
5156
return returnPromise;
5257
});
@@ -58,10 +63,10 @@ LeaderElectionWebLock.prototype = {
5863
// Do nothing because there are no duplicates in the WebLock version
5964
},
6065
die: function die() {
61-
var _this3 = this;
66+
var _this4 = this;
6267
var ret = sendLeaderMessage(this, 'death');
6368
this._lstns.forEach(function (listener) {
64-
return _this3.broadcastChannel.removeEventListener('internal', listener);
69+
return _this4.broadcastChannel.removeEventListener('internal', listener);
6570
});
6671
this._lstns = [];
6772
this._unl.forEach(function (uFn) {

dist/lib/browser.js

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -428,32 +428,38 @@ var LeaderElectionWebLock = function LeaderElectionWebLock(broadcastChannel, opt
428428
this._dpLC = false; // true when onduplicate called
429429

430430
this._wKMC = {}; // stuff for cleanup
431+
432+
// lock name
433+
this.lN = 'pubkey-bc||' + broadcastChannel.method.type + '||' + broadcastChannel.name;
431434
};
432435
exports.LeaderElectionWebLock = LeaderElectionWebLock;
433436
LeaderElectionWebLock.prototype = {
434437
hasLeader: function hasLeader() {
438+
var _this2 = this;
435439
return navigator.locks.query().then(function (locks) {
436-
if (locks.held && locks.held.length > 0) {
440+
var relevantLocks = locks.held ? locks.held.filter(function (lock) {
441+
return lock.name === _this2.lN;
442+
}) : [];
443+
if (relevantLocks && relevantLocks.length > 0) {
437444
return true;
438445
} else {
439446
return false;
440447
}
441448
});
442449
},
443450
awaitLeadership: function awaitLeadership() {
444-
var _this2 = this;
451+
var _this3 = this;
445452
if (!this._wLMP) {
446453
this._wKMC.c = new AbortController();
447454
var returnPromise = new Promise(function (res, rej) {
448-
_this2._wKMC.res = res;
449-
_this2._wKMC.rej = rej;
455+
_this3._wKMC.res = res;
456+
_this3._wKMC.rej = rej;
450457
});
451458
this._wLMP = new Promise(function (res) {
452-
var lockId = 'pubkey-bc||' + _this2.broadcastChannel.method.type + '||' + _this2.broadcastChannel.name;
453-
navigator.locks.request(lockId, {
454-
signal: _this2._wKMC.c.signal
459+
navigator.locks.request(_this3.lN, {
460+
signal: _this3._wKMC.c.signal
455461
}, function () {
456-
(0, _leaderElectionUtil.beLeader)(_this2);
462+
(0, _leaderElectionUtil.beLeader)(_this3);
457463
res();
458464
return returnPromise;
459465
});
@@ -465,10 +471,10 @@ LeaderElectionWebLock.prototype = {
465471
// Do nothing because there are no duplicates in the WebLock version
466472
},
467473
die: function die() {
468-
var _this3 = this;
474+
var _this4 = this;
469475
var ret = (0, _leaderElectionUtil.sendLeaderMessage)(this, 'death');
470476
this._lstns.forEach(function (listener) {
471-
return _this3.broadcastChannel.removeEventListener('internal', listener);
477+
return _this4.broadcastChannel.removeEventListener('internal', listener);
472478
});
473479
this._lstns = [];
474480
this._unl.forEach(function (uFn) {

dist/lib/browser.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/lib/leader-election-web-lock.js

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -26,32 +26,38 @@ var LeaderElectionWebLock = function LeaderElectionWebLock(broadcastChannel, opt
2626
this._dpLC = false; // true when onduplicate called
2727

2828
this._wKMC = {}; // stuff for cleanup
29+
30+
// lock name
31+
this.lN = 'pubkey-bc||' + broadcastChannel.method.type + '||' + broadcastChannel.name;
2932
};
3033
exports.LeaderElectionWebLock = LeaderElectionWebLock;
3134
LeaderElectionWebLock.prototype = {
3235
hasLeader: function hasLeader() {
36+
var _this2 = this;
3337
return navigator.locks.query().then(function (locks) {
34-
if (locks.held && locks.held.length > 0) {
38+
var relevantLocks = locks.held ? locks.held.filter(function (lock) {
39+
return lock.name === _this2.lN;
40+
}) : [];
41+
if (relevantLocks && relevantLocks.length > 0) {
3542
return true;
3643
} else {
3744
return false;
3845
}
3946
});
4047
},
4148
awaitLeadership: function awaitLeadership() {
42-
var _this2 = this;
49+
var _this3 = this;
4350
if (!this._wLMP) {
4451
this._wKMC.c = new AbortController();
4552
var returnPromise = new Promise(function (res, rej) {
46-
_this2._wKMC.res = res;
47-
_this2._wKMC.rej = rej;
53+
_this3._wKMC.res = res;
54+
_this3._wKMC.rej = rej;
4855
});
4956
this._wLMP = new Promise(function (res) {
50-
var lockId = 'pubkey-bc||' + _this2.broadcastChannel.method.type + '||' + _this2.broadcastChannel.name;
51-
navigator.locks.request(lockId, {
52-
signal: _this2._wKMC.c.signal
57+
navigator.locks.request(_this3.lN, {
58+
signal: _this3._wKMC.c.signal
5359
}, function () {
54-
(0, _leaderElectionUtil.beLeader)(_this2);
60+
(0, _leaderElectionUtil.beLeader)(_this3);
5561
res();
5662
return returnPromise;
5763
});
@@ -63,10 +69,10 @@ LeaderElectionWebLock.prototype = {
6369
// Do nothing because there are no duplicates in the WebLock version
6470
},
6571
die: function die() {
66-
var _this3 = this;
72+
var _this4 = this;
6773
var ret = (0, _leaderElectionUtil.sendLeaderMessage)(this, 'death');
6874
this._lstns.forEach(function (listener) {
69-
return _this3.broadcastChannel.removeEventListener('internal', listener);
75+
return _this4.broadcastChannel.removeEventListener('internal', listener);
7076
});
7177
this._lstns = [];
7278
this._unl.forEach(function (uFn) {

docs/e2e.js

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -420,32 +420,38 @@ var LeaderElectionWebLock = function LeaderElectionWebLock(broadcastChannel, opt
420420
this._dpLC = false; // true when onduplicate called
421421

422422
this._wKMC = {}; // stuff for cleanup
423+
424+
// lock name
425+
this.lN = 'pubkey-bc||' + broadcastChannel.method.type + '||' + broadcastChannel.name;
423426
};
424427
exports.LeaderElectionWebLock = LeaderElectionWebLock;
425428
LeaderElectionWebLock.prototype = {
426429
hasLeader: function hasLeader() {
430+
var _this2 = this;
427431
return navigator.locks.query().then(function (locks) {
428-
if (locks.held && locks.held.length > 0) {
432+
var relevantLocks = locks.held ? locks.held.filter(function (lock) {
433+
return lock.name === _this2.lN;
434+
}) : [];
435+
if (relevantLocks && relevantLocks.length > 0) {
429436
return true;
430437
} else {
431438
return false;
432439
}
433440
});
434441
},
435442
awaitLeadership: function awaitLeadership() {
436-
var _this2 = this;
443+
var _this3 = this;
437444
if (!this._wLMP) {
438445
this._wKMC.c = new AbortController();
439446
var returnPromise = new Promise(function (res, rej) {
440-
_this2._wKMC.res = res;
441-
_this2._wKMC.rej = rej;
447+
_this3._wKMC.res = res;
448+
_this3._wKMC.rej = rej;
442449
});
443450
this._wLMP = new Promise(function (res) {
444-
var lockId = 'pubkey-bc||' + _this2.broadcastChannel.method.type + '||' + _this2.broadcastChannel.name;
445-
navigator.locks.request(lockId, {
446-
signal: _this2._wKMC.c.signal
451+
navigator.locks.request(_this3.lN, {
452+
signal: _this3._wKMC.c.signal
447453
}, function () {
448-
(0, _leaderElectionUtil.beLeader)(_this2);
454+
(0, _leaderElectionUtil.beLeader)(_this3);
449455
res();
450456
return returnPromise;
451457
});
@@ -457,10 +463,10 @@ LeaderElectionWebLock.prototype = {
457463
// Do nothing because there are no duplicates in the WebLock version
458464
},
459465
die: function die() {
460-
var _this3 = this;
466+
var _this4 = this;
461467
var ret = (0, _leaderElectionUtil.sendLeaderMessage)(this, 'death');
462468
this._lstns.forEach(function (listener) {
463-
return _this3.broadcastChannel.removeEventListener('internal', listener);
469+
return _this4.broadcastChannel.removeEventListener('internal', listener);
464470
});
465471
this._lstns = [];
466472
this._unl.forEach(function (uFn) {

0 commit comments

Comments
 (0)