-
Notifications
You must be signed in to change notification settings - Fork 55
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
Don't pass undefined arguments through to Flatpickr config #777
Don't pass undefined arguments through to Flatpickr config #777
Conversation
Hi @gitKrystan thanks for the PR! I could be wrong, but I think ember-flatpickr is setup to not pass anything you did not pass to it, so this issue only arises for your case because you are explicitly passing things like |
@rwwagner90 it's basically an Ember/Glimmer limitation right now. When writing a wrapper component, there is no way to "optionally pass an argument", like you can't say So when writing a wrapper component you have to bind all of the possible arguments, but that means anything that is not passed from the invoker will become Don't love any of these, but those are the limitations we have to work with right now; having "splat args" would fix all of these. |
@chancancode wouldn't |
@rwwagner90 |
Ahhh, thank you, I understand now. |
Yeah, it's an unfortunate reality at this moment. Usually, For example:
So if anything, Unfortunately in the specific case someone ultimately cares about the difference between |
The problem
We would like to wrap
<EmberFlatpickr>
in a component to DRY up some of the config options that we pass to every instance. Because Ember doesn't have "splargs" (a la splattributes), this means we end up having to pass through every possible Ember Flatpickr arg like so:Even when an argument is
undefined
, Ember still passes it through. Thus, Ember Flatpickr passesundefined
into theflatpickr
function. Eventually, this makes its way to this line in Flatpickr:https://github.com/flatpickr/flatpickr/blob/07cf1b1ba5ec71da511c295f622d60eed3bf3eb7/src/index.ts#L2039
Object.assign
will overwrite all named properties from the target object even if the value isundefined
, so this overwrites the default config with invalidundefined
config. Eventually, this results in type errors while trying to initialize the Flatpickr object. For example, this is the error thrown in my "it will not override Flatpickr defaults with undefined" test if you remove the code that fixes the issue in_setFlatpickrOptions
:My solution
Filter
undefined
values from the config object before passing it through to theflatpickr
function. For the most part,undefined
seems to be an invalid config option in Flatpickr (per https://flatpickr.js.org/options/), withnull
preferred for turning things "off." The one exception seems to be theenable
property, which defaults toundefined
(so not passing inundefined
to overrideundefined
is probably OK.)Other notes
yarn install
, I got an error because one of the dependencies has deprecated Node 10, which is what's specified in the volta config for this project. To fix, I upgraded node for the project locally but did not commit this change.