reiern70 commented on code in PR #1671:
URL: https://github.com/apache/wicket/pull/1671#discussion_r4296589642


##########
wicket-core/src/main/java/org/apache/wicket/markup/html/form/upload/resource/FileUploadToResourceField.js:
##########
@@ -19,10 +19,21 @@
 
     'use strict';
 
-    if (typeof(Wicket.FileUploadToResourceField) === 'object') {
+    if (typeof(Wicket.FileUploadToResourceField) === 'function') {

Review Comment:
   Note for reviewers: this guard keeps the script from setting itself up a 
second time when it reaches the page twice, for example once on its own and 
once in an aggregated bundle.
   
   On master it compared with `'object'`, which never matches: 
`Wicket.FileUploadToResourceField` is a constructor, so `typeof` gives 
`'function'`. A second run therefore replaced the constructor and all its 
methods. That did no visible harm while the script kept no state of its own.
   
   This PR gives the script state: `lists`, the file lists of each field, which 
`FileListBehavior` registers through `addList()`. With the old guard, a second 
run would start a new, empty `lists`. Lists registered after it would be 
invisible to fields created before it, and those fields would stop collecting 
files. With `'function'`, the second run returns at once and everything shares 
one registry.
   
   The `'object'` check looks copied from scripts whose namespace is a plain 
object, such as `Wicket.FilesSelected` and `Wicket.Head`, where it is right.
   
   The QUnit test "a second run of the script keeps the field and its lists" in 
`upload-to-resource.js` loads the script again. With `'object'`, all three of 
its assertions fail.
   



-- 
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.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to