preact-markup
preact-markup copied to clipboard
Markup component will not update if the mapping of custom elements change
When using the option to add a map of custom elements the component will not update if said mapping changes.
I think the problem might be here: https://github.com/developit/preact-markup/blob/034c4c6e13029d94db57c8a565191a03b214eb83/src/index.js#L11-L14
Now I don't know if this is intended behaviour or just a oversight.
@d3x7r0 it's an oversight, but I think if we want to add support for updating when the listing changes we'll need to deeply compare the object values within props.components:
- shouldComponentUpdate({ wrap, type, markup }) {
+ shouldComponentUpdate({ wrap, type, markup, components }) {
let p = this.props;
+ if (Object.keys(components).join()!=Object.keys(p.components).join()) return true;
+ for (let i in Object(components)) if (components[i]!==p.components[i]) return true;
return wrap!==p.wrap || type!==p.type || markup!==p.markup;
}
That looks like it might be a good enough solution yes. I'm also going to steal that key comparison for my toolset. I never thought of doing it that way but it's such a great idea I'm going to keep it handy :)