PatrickJS / angular-hmr

:fire: Angular Hot Module Replacement for Hot Module Reloading
https://patrickjs.com
Apache License 2.0
506 stars 45 forks source link

Input restoration #27

Open mattdistefano opened 8 years ago

mattdistefano commented 8 years ago

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:

  1. The input selector won't pick up select menus or textareas
  2. However, it will pick up radios and checkboxes, but the value property of a checkbox or radio typically isn't as important as its checked property
  3. checkboxes and radios I believe likewise fire a change event rather than an input event
  4. CustomEvent IIRC 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
PatrickJS commented 7 years ago

@mattdistefano an you make a PR to update the logic?

actra-gschuster commented 7 years ago

@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