Skip to content

Commit 831aa20

Browse files
committed
Add comments to javascript
1 parent e730eea commit 831aa20

File tree

1 file changed

+37
-6
lines changed

1 file changed

+37
-6
lines changed

src/js/src/index.js

Lines changed: 37 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,19 @@ export function bind(node) {
1212
};
1313
}
1414

15+
/**
16+
* History component that captures browser "history go back" actions and notifies the server.
17+
*
18+
* @param {Object} props - The properties object.
19+
* @param {Function} props.onHistoryChangeCallback - Callback function to notify the server about history changes.
20+
* @returns {null} This component does not render any visible output.
21+
* @description
22+
* This component uses the `popstate` event to detect when the user navigates back in the browser history.
23+
* It then calls the `onHistoryChangeCallback` with the current pathname and search parameters.
24+
* Note: Browsers do not allow detection of "history go forward" actions.
25+
* @see https://github.com/reactive-python/reactpy/pull/1224
26+
*/
1527
export function History({ onHistoryChangeCallback }) {
16-
// Capture browser "history go back" action and tell the server about it
17-
// Note: Browsers do not allow us to detect "history go forward" actions.
1828
React.useEffect(() => {
1929
// Register a listener for the "popstate" event and send data back to the server using the `onHistoryChange` callback.
2030
const listener = () => {
@@ -32,8 +42,10 @@ export function History({ onHistoryChangeCallback }) {
3242
});
3343

3444
// Tell the server about the URL during the initial page load
35-
// FIXME: This currently runs every time any component is mounted due to a ReactPy core rendering bug.
45+
// FIXME: This code is commented out since it currently runs every time any component
46+
// is mounted due to a ReactPy core rendering bug.
3647
// https://github.com/reactive-python/reactpy/pull/1224
48+
3749
// React.useEffect(() => {
3850
// onHistoryChange({
3951
// pathname: window.location.pathname,
@@ -44,10 +56,20 @@ export function History({ onHistoryChangeCallback }) {
4456
return null;
4557
}
4658

47-
// FIXME: The Link component is unused due to a ReactPy core rendering bug
48-
// which causes duplicate rendering (and thus duplicate event listeners).
49-
// https://github.com/reactive-python/reactpy/pull/1224
59+
60+
/**
61+
* Link component that captures clicks on anchor links and notifies the server.
62+
*
63+
* @param {Object} props - The properties object.
64+
* @param {Function} props.onClickCallback - Callback function to notify the server about link clicks.
65+
* @param {string} props.linkClass - The class name of the anchor link.
66+
* @returns {null} This component does not render any visible output.
67+
*/
5068
export function Link({ onClickCallback, linkClass }) {
69+
// FIXME: This component is currently unused due to a ReactPy core rendering bug
70+
// which causes duplicate rendering (and thus duplicate event listeners).
71+
// https://github.com/reactive-python/reactpy/pull/1224
72+
5173
// This component is not the actual anchor link.
5274
// It is an event listener for the link component created by ReactPy.
5375
React.useEffect(() => {
@@ -79,6 +101,15 @@ export function Link({ onClickCallback, linkClass }) {
79101
return null;
80102
}
81103

104+
/**
105+
* Client-side portion of the navigate component, that allows the server to command the client to change URLs.
106+
*
107+
* @param {Object} props - The properties object.
108+
* @param {Function} props.onNavigateCallback - Callback function that transmits data to the server.
109+
* @param {string} props.to - The target URL to navigate to.
110+
* @param {boolean} props.replace - If true, replaces the current history entry instead of adding a new one.
111+
* @returns {null} This component does not render anything.
112+
*/
82113
export function Navigate({ onNavigateCallback, to, replace }) {
83114
React.useEffect(() => {
84115
if (replace) {

0 commit comments

Comments
 (0)