KevinGG commented on a change in pull request #11020: [BEAM-7926] Update Data 
Visualization
URL: https://github.com/apache/beam/pull/11020#discussion_r387292177
 
 

 ##########
 File path: 
sdks/python/apache_beam/runners/interactive/interactive_environment.py
 ##########
 @@ -43,6 +43,55 @@
 
 _LOGGER = logging.getLogger(__name__)
 
+# By `format(customized_script=xxx)`, the given `customized_script` is
+# guaranteed to be executed within access to a jquery with datatable plugin
+# configured which is useful so that any `customized_script` is resilient to
+# browser refresh. Inside `customized_script`, use `$` as jQuery.
+_JQUERY_WITH_DATATABLE_TEMPLATE = """
+        if (typeof window.jquery341 == 'undefined') {{
 
 Review comment:
   It's an arbitrary name we give to the jQuery v3.4.1 we imported. It's like a 
namesapce. Note the magic happens in `window.jquery341 = 
jQuery.noConflict(true);`.
   The problem here is that:
   1. A frontend can connect to the kernel at any time: code executed by kernel 
in the past does not have any effect to new frontends.
   2. Multiple frontends can connect to the same kernel: each frontend has its 
own state (browser: HTML and JS), the rendered HTML+JS cannot assume the 
existence of any global variable, function definition or libraries.
   
   This ensures no matter how many jQuery gets imported at any time, the 
interactive notebook always checks and uses the single jQuery configured by 
interactive modules with Datatable plugin initialized.
   And the `function($)` signature ensures that any customized script executed 
will use `$` as the singleton instance  `window.jquery341`. This ensures that 
code reading `$` as jQuery will always work.
   The advantage of doing this isolation is:
   1. The JS imported by interactive modules to any frontend does not alter 
their existing states. Everything in the notebook still works as it was no 
matter what libraries and global vars have been used.
   2. HTML with JS rendered by interactive modules will have determined 
behavior because it always uses the same libraries.
   3. Whether/when a frontend is connected to the kernel doesn't matter now. 
The visualization HTML contains everything it needs to setup and/or execute 
scripts.
   4. Arbitrary DOM changes doesn't matter now. Even if the user screws the 
notebook's HTML, the data visualization broadcast from kernels will always be 
rendered correctly.

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
[email protected]


With regards,
Apache Git Services

Reply via email to