-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: feed screen after page refresh (#538)
- Loading branch information
1 parent
11aca4c
commit 4c04750
Showing
9 changed files
with
180 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
let channels: Map<string, BroadcastChannel> | undefined; | ||
|
||
export const LOGOUT_CHANNEL = 'logout-channel'; | ||
export const LOGIN_CHANNEL = 'login-channel'; | ||
|
||
/** | ||
* Creates a new broadcast channel with the specified name and callback. The callback is called when a message is received. | ||
* If the channel already exists, the function returns false. | ||
* @param channelName name of the channel | ||
* @param callback function to be called when a message is received | ||
* @returns true if the channel was created, false if the channel already exists | ||
* @see broadcastMessage | ||
*/ | ||
export const createBroadcastChannel = ( | ||
channelName: string, | ||
callback: () => void, | ||
): boolean => { | ||
if (channels === undefined) { | ||
channels = new Map<string, BroadcastChannel>(); | ||
} | ||
let channel = channels.get(channelName); | ||
if (channel !== undefined) { | ||
return false; | ||
} | ||
channel = new BroadcastChannel(channelName); | ||
channel.onmessage = () => { | ||
callback(); | ||
}; | ||
channels.set(channelName, channel); | ||
return true; | ||
}; | ||
|
||
/** | ||
* Broadcasts a message to all subscribers of the channel. The channel must be created before broadcasting. | ||
* If the channel is not found, an error is thrown. | ||
* @param channelName name of the channel | ||
* @param message to be broadcasted or undefined | ||
* @see createDispatchChannel | ||
*/ | ||
export const broadcastMessage = ( | ||
channelName: string, | ||
message?: string, | ||
): void => { | ||
if (channels === undefined) { | ||
throw new Error('No channels created'); | ||
} | ||
const channel = channels.get(channelName); | ||
if (channel === undefined) { | ||
throw new Error(`Channel ${channelName} not found`); | ||
} | ||
channel.postMessage(message); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters