Title:
Bug: Uploader.Inputs.RemoveById(sElementId) attempts removal from _UnderlyingSet instead of _UnderlyingArray
Description:
I encountered a bug when calling the RemoveById method on the Uploader.Inputs class to remove an input by ID. The function is designed to operate on a data structure _UnderlyingSet, but the class uses _UnderlyingArray for its other operations.
Code Details:
The RemoveById function implementation is as follows:
/**
* Remove HTML element from input Controls by id.
* @api
* @param {string} sElementId Id of HTML element.
*/
RemoveById: function(sElementId) {
var oInput = this.GetById(sElementId);
if (oInput) {
delete this._UnderlyingSet[sElementId];
this._RaiseOnCollectionChanged([], [oInput]);
}
},
However, in the Uploader.Inputs class:
- Initialization:
constructor: function(oUploader) {
this._UnderlyingArray = [];
this._Uploader = oUploader;
},
_UnderlyingArray is initialized as an array, not a set.
- Other Methods:
AddById and GetById correctly reference _UnderlyingArray:
AddById: function(sElementId) {
var oInput = new ITHit.WebDAV.Client.Upload.Controls.Input(sElementId);
this._UnderlyingArray[sElementId] = oInput;
this._RaiseOnCollectionChanged([oInput], []);
return oInput;
},
GetById: function(sElementId) {
return this._UnderlyingArray[sElementId];
},
- The
_UnderlyingSet is not initialized anywhere in the constructor, leading to the following declaration:
/**
* @private
* @type {Object.<string, ITHit.WebDAV.Client.Upload.Controls.Input>}
*/
_UnderlyingSet: null,
Error Details:
The bug throws this error:
ITHitWebDAVClient.js:22956 Uncaught TypeError: Cannot convert undefined or null to object
at childClass.RemoveById (ITHitWebDAVClient.js:22956:48)
at HTMLButtonElement.<anonymous> (main.ts:113:46)
Possible Fix:
Change RemoveById to correctly reference _UnderlyingArray instead of _UnderlyingSet:
RemoveById: function(sElementId) {
var oInput = this.GetById(sElementId);
if (oInput) {
delete this._UnderlyingArray[sElementId];
this._RaiseOnCollectionChanged([], [oInput]);
}
},
Additional Context:
The DropZoneCollection class uses _UnderlyingSet consistently for similar operations, which suggests that the issue in Inputs might stem from incomplete refactoring or mismatched design between these two collections.
Steps to Reproduce:
- Initialize an uploader instance.
- Bind inputs using
Uploader.Inputs.AddById.
- Attempt to remove an input using
Uploader.Inputs.RemoveById.
Expected Behavior:
Inputs should be correctly removed from _UnderlyingArray without errors.
Actual Behavior:
The method references an uninitialized _UnderlyingSet, causing a TypeError.
Title:
Bug:
Uploader.Inputs.RemoveById(sElementId)attempts removal from_UnderlyingSetinstead of_UnderlyingArrayDescription:
I encountered a bug when calling the
RemoveByIdmethod on theUploader.Inputsclass to remove an input by ID. The function is designed to operate on a data structure_UnderlyingSet, but the class uses_UnderlyingArrayfor its other operations.Code Details:
The
RemoveByIdfunction implementation is as follows:However, in the
Uploader.Inputsclass:_UnderlyingArrayis initialized as an array, not a set.AddByIdandGetByIdcorrectly reference_UnderlyingArray:_UnderlyingSetis not initialized anywhere in the constructor, leading to the following declaration:Error Details:
The bug throws this error:
Possible Fix:
Change
RemoveByIdto correctly reference_UnderlyingArrayinstead of_UnderlyingSet:Additional Context:
The
DropZoneCollectionclass uses_UnderlyingSetconsistently for similar operations, which suggests that the issue inInputsmight stem from incomplete refactoring or mismatched design between these two collections.Steps to Reproduce:
Uploader.Inputs.AddById.Uploader.Inputs.RemoveById.Expected Behavior:
Inputs should be correctly removed from
_UnderlyingArraywithout errors.Actual Behavior:
The method references an uninitialized
_UnderlyingSet, causing aTypeError.