-
Notifications
You must be signed in to change notification settings - Fork 102
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Destroy #338
Conversation
@homm what do you think? |
This is not a problem because user removes the widget for a reason: he wants to remove entire HTML fragment or reinitialize the widget. |
I added new method I create usage example in https://github.com/Zmoki/try-uploadcare-widget/tree/destroy <script>
UPLOADCARE_LIVE = false;
</script> import React, {Component} from "react";
import uploadcare from "uploadcare-widget";
class Uploader extends Component {
componentDidMount() {
uploadcare.start({
publicKey: "demopublickey"
});
uploadcare.Widget("#Uploadcare2");
uploadcare.Widget("#Uploadcare3");
}
reset() {
uploadcare.reset();
}
initialize() {
uploadcare.initialize();
}
destroyAll() {
uploadcare.reset();
let widgetInputs = document.querySelectorAll("[id^=Uploadcare");
widgetInputs.forEach(input => {
(uploadcare.Widget(input)).destroy();
});
}
resurrectAll() {
uploadcare.initialize();
uploadcare.Widget("#Uploadcare2");
uploadcare.Widget("#Uploadcare3");
}
render() {
return (
<div>
<input type="hidden" role="uploadcare-uploader"/>
<input type="hidden" id="Uploadcare2" data-images-only/>
<input type="hidden" id="Uploadcare3" data-multiple/>
<hr/>
<button onClick={this.reset}>reset</button>
<button onClick={this.initialize}>initialize</button>
<button onClick={this.destroyAll}>destroy all!</button>
<button onClick={this.resurrectAll}>resurrect all!</button>
</div>
)
}
}
export default Uploader; |
@homm bump |
|
||
api: -> | ||
if not @__api | ||
@__api = utils.bindAll(this, [ | ||
'openDialog' | ||
'reloadInfo' | ||
'value' | ||
'validators' | ||
'validators', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the comma is unnecessary
I don't like it for three reasons:
|
I've added memory leaks test. Looks like there are no memory leaks, but memory was freed only after major GCs. |
Stay on widget's method |
Ok, if it is requested, let's give it the better name |
No, |
I added the destroy method to the widget. This method remove an element
uploadcare-widget
from DOM and flush a uploadcare's data in the input element.But we have a problem 😣. If uploadcare initialized on the default input with
role="uploadcare-uploader
, afteruploadcare-widget
will be removed, it returns anyway. Becauselive
is true and uploadcare initialized as a widget after about ~100 ms. So, we need setUPLOADCARE_LIVE = false;
.Example 1
Example 2
doesn't work, because live = true
Example 3
Related with #328