Skip to content

Commit

Permalink
fix: apply requested changes
Browse files Browse the repository at this point in the history
  • Loading branch information
koko57 committed Nov 22, 2023
1 parent d8a1e22 commit c72152c
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 11 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/e2e.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4

- uses: actions/cache@v3
with:
Expand Down
20 changes: 10 additions & 10 deletions lib/ActiveClientManager/index.web.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,18 @@ const clientID = Str.guid();
const subscribers = [];
let timestamp = null;

let activeClient = null;
let resolveSavedSelfPromise = () => {};
const savedSelfPromise = new Promise((resolve) => {
resolveSavedSelfPromise = resolve;
let activeClientID = null;
let setIsReady = () => {};
const isReadyPromise = new Promise((resolve) => {
setIsReady = resolve;
});

/**
* Determines when the client is ready. We need to wait both till we saved our ID in onyx AND the init method was called
* @returns {Promise}
*/
function isReady() {
return savedSelfPromise;
return isReadyPromise;
}

/**
Expand All @@ -34,7 +34,7 @@ function isReady() {
* @returns {Boolean}
*/
function isClientTheLeader() {
return activeClient === clientID;
return activeClientID === clientID;
}

/**
Expand All @@ -61,13 +61,13 @@ function init() {
if (isClientTheLeader() && (isTimestampNewer || (isTimestampEqual && clientID > message.data.clientID))) {
return;
}
activeClient = message.data.clientID;
activeClientID = message.data.clientID;

subscribers.forEach(callback => callback());
break;
}
case REMOVED_LEADER_MESSAGE:
activeClient = clientID;
activeClientID = clientID;
timestamp = Date.now();
Broadcast.sendMessage({type: NEW_LEADER_MESSAGE, clientID, timestamp});
subscribers.forEach(callback => callback());
Expand All @@ -77,11 +77,11 @@ function init() {
}
});

activeClient = clientID;
activeClientID = clientID;
timestamp = Date.now();

Broadcast.sendMessage({type: NEW_LEADER_MESSAGE, clientID, timestamp});
resolveSavedSelfPromise();
setIsReady();

window.addEventListener('beforeunload', () => {
if (!isClientTheLeader()) {
Expand Down

0 comments on commit c72152c

Please sign in to comment.