Skip to content

Conversation

@vicb
Copy link

@vicb vicb commented Oct 31, 2020

@realiarthur
This PR is a work in progress to get feedback.
Let me know if you're happy with the updates here and the plan.
Thanks !

Done:

  • Conversion to typescript - still needs validation but ok for a preview,
  • Fixed a bug in withValue.js - disconectedCallback -> disconnectedCallback (nn)
  • Fixed a bug in utils.js - the parsed variable was in the global namespace
  • Fixed a bug in withForm.js handleBlur() - missing return type. Fixed by removing recursion.

ToDo:

  • regression on the minified size. Was 5.49 kB before this update. Probably related to terser config,
  • add a TS version of the example,
  • add some inline doc on types,
  • update the doc,
  • Add a changelog with breaking changes (polyfill, API) & other changes
  • mention the Element.closest polyfill in the docs,
  • Build cjs, esm, umd, and .d.ts - make sure umd bundle has the same path as before,
  • Add ESLint to format the code (as a last commit as it will make review harder).

@vicb vicb marked this pull request as draft October 31, 2020 22:04
@vicb vicb changed the title First draft Converting to Typescript: first draft Nov 2, 2020
@vicb
Copy link
Author

vicb commented Nov 2, 2020

I have played a little more with that.

My conclusion is that some of the construct do not play well with typescript:

In the end I feel like converting to TS would only make sense with a few breaking changes. So I am wondering if it should be done in this repo (with a new major release) or if it is better done in a fork.

What do you think ?

@realiarthur
Copy link
Owner

realiarthur commented Nov 3, 2020 via email

@vicb
Copy link
Author

vicb commented Nov 3, 2020

  • As I said my point about closest polyfill is that builtin function may works faster. But if there is no other way, we can make a js function

The JS function would be actually be the same as the polyfill, just not on the prototype.

  • handleChange and handleBlur is more like inner functions, so we can do make whatever we want with this. But somehow formik support both typescript and arguments like nameOrEvent (at least version 1.x.x)

It's probably possible to make a working typing with some effort.
Is it worth it ? I don't think so. We know which or name or event we will pass so having different function would make things clearer (and simpler) IMO.
On the other it's a breaking change if someone rely on it.

  • why do not pass options to withForm? I’m always use withForm with options like “validationSchema” or “onSubmit”. It looks like standard HOC pattern and make code more readable. Or i’m wrong? The way I use it is to implement validationSchema or onSubmit in my Lit Element class.

With TS, you have to use class MyComponent extends withForm(LitElement) {...} to be able to reference handle... anyway so passing options as little sense here.

Dropping the options would allow to simplify the logic (i.e. no more need for withFormExtended and simplify this._onSubmit = (onSubmit || this.onSubmit || function () {}).bind(this)). But if there are use cases no need to remove it.

If you don't want to deal with it further, of course you can fork it and do it like you want

I think forking should be last resort. It would be better if can discuss/agree on how to evolve this lib.

@realiarthur
Copy link
Owner

realiarthur commented Nov 4, 2020 via email

@vicb
Copy link
Author

vicb commented Nov 4, 2020

Great.
Let's recap

For 1) I am not sure if you want to keep the closest() code without patching on Element.proto or if the code should be dropped and users should explicitly load a polyfill (the latter is a breaking change).

  1. methods that accept nameOrElement are split in 2 different methods each - this is a breaking change.

  2. we keep the ability to pass options to withForm and withField.

We need to clarify 1 - and make sure my understanding of 2 and 3 is correct.

@realiarthur
Copy link
Owner

realiarthur commented Nov 4, 2020 via email

Copy link
Author

@vicb vicb left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey,

Could you please take a look at the updates here ?

Copy link
Author

@vicb vicb 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 your review.

I have added some suggestion in withForm they should also be applicable to withField.
That will be breaking changes.
It is also possible to not include those breaking change and keep the former behavior.
Let me know what you prefer.

As noted in the comments the current setup does not bundle lodash (to stay consistent with your setup). Bundling lodash increases the bundle size by a lot. It should be possible to come with implementation of get, set and cloneDeep that are much lighter. I don't think this should be a priority of this CL though. There are probably libs on npm.

Copy link
Owner

@realiarthur realiarthur left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you! Please see few my comments

@vicb
Copy link
Author

vicb commented Nov 11, 2020

I have implemented the changes we discussed.

I'll update the description of this PR to list the remaining tasks.

Copy link
Owner

@realiarthur realiarthur left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you! Please see few my comments

@vicb
Copy link
Author

vicb commented Nov 15, 2020

@realiarthur Thanks for the great feedback.

I have integrated your feedback.

I'll work on the remaining tasks later today.

@vicb
Copy link
Author

vicb commented Nov 17, 2020

Quick update on this CL: I need to be able to block some time to finish the remaining tasks here. I will probably not be able to dedicate this time before December. Do not expect any big process in the next 2 weeks.
Thanks.

@realiarthur realiarthur changed the base branch from master to 2.0 May 8, 2021 09:05
@realiarthur realiarthur marked this pull request as ready for review May 8, 2021 09:06
@realiarthur
Copy link
Owner

@vicb I plan to merge your PR and finish the remaining (build and documentation) tasks in the "2.0" branch. You do not mind?

@vicb
Copy link
Author

vicb commented May 8, 2021

Oh sorry I completely forgot about this PR.

I'll be out for a week and can give a hand after that.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants