-
Notifications
You must be signed in to change notification settings - Fork 16
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
Support for Maps in isEmpty function. (refactoring) #26
Conversation
I'm not sure I get the reason for this. Could you please provide a sample of your use case? |
It's about making the code simpler and more explicit. If you're reading
As far as I understood the code it wants to check if something is empty or not. If it is empty it should just continue. So with this PR you can simply use:
In the end you don't care if it's a Map and Object or an Array of styles, you care about if it is empty or not. |
also the |
@webpapaya Yes, I see that isEmpty was untested, and I fully get you code. What I would like to know, is why we need to support Maps? Can you provide a sample of code, that gives me an idea of why Stilr should support Maps. |
"The entries() method returns a new Iterator object that contains the [key, value] pairs for each element in the Map object in insertion order." - from MDN So for CSS where later declared styles might overwrite previously defined styles, it really makes sense to have things rendered in the order of insertion. |
@webpapaya You are still not answering my question :) I know what a Map is, I'm asking for a sample of a use case, where you would create a StyleSheet from a Map. I fully get what your changes does, but I don't see why you would want to change Stilr. Please provide a reason / sample code / anything, that explains to me, why this pull request is needed, and which problem it solves. |
This PR is not a new feature. For me it just enhances the readability of the code. The internals of stilr are heavily using a map Line 9. Line 13 is explicitly checking if the stylesheet passed in to the Also it safes an unnecessary recursion call to render function in Line 96 if the media query styles are empty. And for me calling |
Okay, but is there a real impact? Performance, stability, anything? Or is this simply another code style? |
A slight performance improvement, which is negligible. It's more a side effect of the code style improvement, which should help people contributing to this stilr understand the code better. |
Where do you see the performance improvement? Do you have any benchmark to back this? From reading the code, I would guess the opposite as there is more function calls involved. And to be honest, I prefer To sum it up, I don't think there is any improvements, but if you have a benchmark that says otherwise, I'm willing to have a second look. I also don't agree that the code style is improved, I actual think it is harder to read, as thinks are hidden in functions as mentioned above. |
Adding tests for |
We can probably argue about the name
For me it's more confusing to have an For me this line is really confusing:
As it mixes up technical detail 'isMap' with busines logic So we can also argue about the name of |
Line 93 should check if the styles are empty or not. Until now the
isEmpty
function only supports objects and noMaps
. So this PR adds a Map support to the isEmpty function and replaces:with