dfilatov / vidom

Library to build UI based on virtual DOM
MIT License
415 stars 16 forks source link

Object.freeze error in ie11 #328

Closed Urkass closed 6 years ago

Urkass commented 6 years ago

https://github.com/dfilatov/vidom/blob/2355f72c8da810dfa57f2d88406fb58b406eb5f1/src/createComponent.js#L199 while using super() in constructor of a component, Object.freeze(rootNodeCtx) receives undefined. It causes an Error in ie11 Object.freeze: argument is not an Object

dfilatov commented 6 years ago

@Urkass Could you provide a minimal example reproducing error? because I couldn't (

Urkass commented 6 years ago

@dfilatov reproducing example:

class Hello extends vidom.Component {

  constructor(a) {
    super(a);
    this.setState({ counter : 1 });
  }

    onRender() {
        return (
            <div>
                <h1>Hello, { this.attrs.name }!</h1>
                <div>I see you { this.state.counter } time</div>
            </div>
        );
    }

    onMount() {
        setInterval(() => {
            this.setState({ counter : this.state.counter + 1 });
        }, 1000);
    }
}

vidom.mount(document.body, <Hello name="World"/>);

After attent look at docs I found that for this purposes i should use onInit that removes the need in constructor and super. One more question, what ie browsers does vidom support?

dfilatov commented 6 years ago

Constructor has following signature: constructor(attrs, children, context). You was trying to pass attrs only so base constructor had been broken. And yes, much better to avoid constructor overriding and use onInit hook.

dfilatov commented 6 years ago

what ie browsers does vidom support?

>= IE9