angular-hmr
angular-hmr copied to clipboard
Input restoration
Was looking over this code...
export function getInputValues() {
const inputs = document.querySelectorAll('input');
return Array.prototype.slice.call(inputs).map(input => input.value);
}
const inputs = document.querySelectorAll('input');
if ($inputs && inputs.length === $inputs.length) {
$inputs.forEach((value, i) => {
const el: any = inputs[i];
el.value = value;
el.dispatchEvent(new CustomEvent('input', {detail: el.value}));
});
}
And a couple things came to mind:
- The
inputselector won't pick up select menus or textareas - However, it will pick up radios and checkboxes, but the
valueproperty of a checkbox or radio typically isn't as important as itscheckedproperty - checkboxes and radios I believe likewise fire a
changeevent rather than aninputevent CustomEventIIRC is not supported without a polyfill on IE11 or earlier. Probably not a big deal for development but might be worth mentioning in the README
@mattdistefano an you make a PR to update the logic?
@gdi2290 as I had the same requirement I implemented the required code today - see my pull request https://github.com/AngularClass/angular2-hmr/pull/34