I’m having issues with props not updating on time for the render function. I believe this wasn’t an issue before the refactor of how AC handles updating the DOM(but I might be wrong).
this.props.text is empty for when it’s going to be rendered for the first time(which is expected) but when the data is available it won’t rerun and AC won’t refresh the DOM.
Will this work? I think you mentioned something that the update function no longer works or shouldn’t be used?
update: function (props) {
if (this.props.text && (props.text != this.props.text)) {
this.$node.innerHTML = window.markdownit().use(window.markdownItAnchor, {
slugify: s => slugify(s),
permalink: window.markdownItAnchor.permalink.headerLink({ renderHref: function (slug) { return `${window.location.pathname}#${slug}` } })
}).render(this.props.text);
this.dispatchEvent('rendered');
}
}
All is good Patrick. I mixed in my head several concepts that were making the component behave in unwanted ways and I thought it could have something to do with the last updates de AC framework to avoid updating components more than strictly needed.
The update method has indeed 2 arguments, previous it only had 1.
update: function(oldProps, changed) { ... }
In the update function you can access the properties of the component with this.props. The oldProps argument are the previous properties, you can use it to compare the values. New is the changed argument which contains a Set of changed properties, you can use this to see if a property was changed, so you don’t need to compare the values yourself anymore.
I was able to finalise a markdown rendered and a table-of-contents that autogenerates by reading headings of the html. Extremely useful for blogs, documentation, etc.