Skip to content

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

Merged
merged 3 commits into from
Nov 9, 2019
Merged

Add support for Preact #129

merged 3 commits into from
Nov 9, 2019

Conversation

vtenfys
Copy link
Contributor

@vtenfys vtenfys commented Nov 4, 2019

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 Preact

Checklist:

  • Tests
  • Documentation

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.

@coveralls
Copy link

coveralls commented Nov 4, 2019

Coverage Status

Coverage remained the same at 100.0% when pulling 6c6b8ec on davidbailey00:support-preact into b103aae on remarkablemark:master.

@remarkablemark remarkablemark added the feature New feature or request label Nov 6, 2019
@remarkablemark remarkablemark self-assigned this Nov 6, 2019
@remarkablemark remarkablemark self-requested a review November 6, 2019 00:31
Copy link
Owner

@remarkablemark remarkablemark left a 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'
Copy link
Owner

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?

@vtenfys
Copy link
Contributor Author

vtenfys commented Nov 7, 2019

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?

Absolutely! Will check those things when I next work on this PR :)

What do you think of passing the library module as an option?

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

Also, do you prefer naming the new option library or react?

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 library

@vtenfys
Copy link
Contributor Author

vtenfys commented Nov 7, 2019

Also curious what you think about the optionalPeerDependencies approach, since NPM doesn't have a nice "official" way to handle this

@remarkablemark
Copy link
Owner

Also curious what you think about the optionalPeerDependencies approach, since NPM doesn't have a nice "official" way to handle this

That's a great question. I'm leaning towards optionalDependencies (see description for npm and yarn). The only thing we lose out is the client warning us if the peerDependency is not installed.

Do you prefer naming the new option library or react?

I'm okay with keeping it named as library.

@vtenfys
Copy link
Contributor Author

vtenfys commented Nov 7, 2019

I'm leaning towards optionalDependencies

The issue with optionalDependencies is it forces installing a particular version - the name is a bit misleading since it always installs packages specified unelss there's an error during their installation

- Update README
- Add typings
- Add a new test for Preact
- Restore old peerDependencies
@vtenfys
Copy link
Contributor Author

vtenfys commented Nov 7, 2019

Just pushed some changes to refactor this - I've made React a peer dependency again, since it's the standard implementation.

Copy link
Owner

@remarkablemark remarkablemark left a 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.

@vtenfys
Copy link
Contributor Author

vtenfys commented Nov 9, 2019

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.

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

@remarkablemark
Copy link
Owner

Cool, I'll be merging this PR. Thanks once again for opening this @davidbailey00!

@remarkablemark remarkablemark merged commit 2998742 into remarkablemark:master Nov 9, 2019
@remarkablemark
Copy link
Owner

[email protected] has been released and published:

# update with npm
npm i -S [email protected]

# or with yarn
yarn add [email protected]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants