Closed xaviervia closed 8 years ago
Interesting... I'm curious about what the implementation would look like, as there would be three different signatures to support:
HTML2React(content)
HTML2React({ a: Link }, content)
HTML2React({ a: Link })(content)
Any suggestion?
As I see it, internally it would always be partially applied and take content from a passed content or from a default, and then the externally exposed one decides according to the arguments. So in pseudo JS it would be something like:
const defaultElementOverrides = { a: <a> , ... }
const html2react = (elementOverrides = defaultElementOverrides) => (content) => {
// do stuff
}
export default function (...args) {
if (args.length == 2) {
const elementOverrides = args[0]
const content = args[1]
return html2react(elementOverrides)(content)
} else if (typeof args[0] === 'string') { // called with only content
return html2react()(args[0])
} else { // called with only elementOverrides returns partially applied
return html2react(args[1])
}
}
Cool, I like it. I would prefer keeping the content as the first argument, though, so that it's not a breaking update. The only change would be to switch the arguments to html2react
in the if (args.length === 2) { ... }
block. What do you think?
Sure!
It could look like this:
for the regular API it would imply only reverting the order of the arguments:
This way it's easy to provide a common wrapping when makes sense to use the same setup in multiple places.