@@ -4,6 +4,7 @@ const Retool = ({ data, url, height, width }) => {
44 const embeddedIframe = useRef ( null ) ;
55 const [ elementWatchers , setElementWatchers ] = useState ( { } ) ;
66
7+ /* Retool passes up the list of elements to watch on page load */
78 useEffect ( ( ) => {
89 for ( const key in elementWatchers ) {
910 const watcher = elementWatchers [ key ] ;
@@ -19,7 +20,9 @@ const Retool = ({ data, url, height, width }) => {
1920 }
2021 } , [ data , elementWatchers ] ) ;
2122
23+ /* On page load, add event listener to listen for events from Retool */
2224 useEffect ( ( ) => {
25+ /* Handle events - if PWQ then create/replace watchers -> return result */
2326 const handler = ( event ) => {
2427 if ( ! embeddedIframe ?. current ?. contentWindow ) return ;
2528 if ( event . data . type === "PARENT_WINDOW_QUERY" ) {
@@ -37,6 +40,7 @@ const Retool = ({ data, url, height, width }) => {
3740 return ( ) => window . removeEventListener ( "message" , handler ) ;
3841 } , [ ] ) ;
3942
43+ /* Creates or updates the list of values for us to watch for changes */
4044 const createOrReplaceWatcher = ( selector , pageName , queryId ) => {
4145 const watcherId = pageName + "-" + queryId ;
4246 const updatedState = elementWatchers ;
@@ -51,6 +55,7 @@ const Retool = ({ data, url, height, width }) => {
5155 setElementWatchers ( updatedState ) ;
5256 } ;
5357
58+ /* Checks for selectors for data and posts message for Retool to read */
5459 const postMessageForSelector = ( messageType , eventData ) => {
5560 const maybeData = data [ eventData . selector ] ;
5661
0 commit comments