-
-
Notifications
You must be signed in to change notification settings - Fork 134
Add support for Preact #129
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Awesome work @davidbailey00
I left a comment/question.
Depending on the approach we take, do you mind adding tests to ensure this library remains at 100% coverage?
Also, could you verify if we need to add any TypeScript definitions here?
README.md
Outdated
|
||
```js | ||
parse('<br>', { | ||
library: 'preact' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like your proposition @davidbailey00
What do you think of passing the library module as an option? For example:
// html to react
parse('<p>', {
library: require('react') // default
});
// html to preact
parse('<p>', {
library: require('preact')
});
// html to custom
parse('<p>', {
library: {
cloneElement: () => { /* ... */ },
createElement: () => { /* ... */ },
isValidElement: () => { /* ... */ }
}
});
This way, the API is flexible in terms of SOLID principles and it's easier to support new libraries in the future.
Also, do you prefer naming the new option library
or react
?
Absolutely! Will check those things when I next work on this PR :)
I like this approach - initially I thought of passing the module as a string, but I like this approach better since it's easier for bundler optimisation + allows using custom functions which aren't from a single module
Don't mind either way - I was debating this myself when creating the PR. Do you have a preference towards one or the other? If not I'll leave as |
Also curious what you think about the |
That's a great question. I'm leaning towards
I'm okay with keeping it named as |
The issue with |
- Update README - Add typings - Add a new test for Preact - Restore old peerDependencies
Just pushed some changes to refactor this - I've made React a peer dependency again, since it's the standard implementation. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for making the updates!
I've made React a peer dependency again, since it's the standard implementation.
Do you think this would be an inconvenience for packages that don't require react
? The only downside would be the warning from npm/yarn install.
Otherwise, I think your changes look good and they will be available in the next release.
Yeah, that's the only downside - slightly annoying but it's probably best to leave it for the majority of people who will use standard React, and not a major inconvenience |
Cool, I'll be merging this PR. Thanks once again for opening this @davidbailey00! |
# update with npm
npm i -S [email protected]
# or with yarn
yarn add [email protected] |
What is the motivation for this pull request?
Support using Preact instead of React
What is the current behavior?
Only React is supported
What is the new behavior?
New option
library
is added to allow using PreactChecklist:
Any other comments?
As far as I'm aware, NPM doesn't allow specifying multiple packages that can satisfy a single peer dependency (i.e. warn if neither React or Preact are missing, but satisfy if one is present) - so I've used an unofficial option
optionalPeerDependencies
. Alternatively,package.json
could be left as-is, assuming most people will want React.