Skip to content
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

added properties as functions to free-style #47

Closed
wants to merge 4 commits into from

Conversation

notoriousb1t
Copy link

Added the ability for properties to be provided as functions. This should allow free-style to support helper libraries or properties that can be calculated at the last moment.

@coveralls
Copy link

coveralls commented Dec 13, 2016

Coverage Status

Coverage increased (+0.005%) to 98.805% when pulling 00708f6 on notoriousb1t:master into f37fdc1 on blakeembrey:master.

@@ -170,10 +170,11 @@ function stringifyProperties (properties: Properties) {

for (const [name, value] of properties) {
if (value != null) {
if (Array.isArray(value)) {
result.push(value.filter(x => x != null).map(x => styleToString(name, x)).join(';'))
const value2 = typeof value === 'function' ? value() : value
Copy link
Owner

Choose a reason for hiding this comment

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

I'll tidy it up, but initial issue is that value2 may be null. Should probably be const value = typeof prop === 'function' ? prop() : prop before checking the value.

Copy link
Author

Choose a reason for hiding this comment

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

Alright, one second

Copy link
Owner

@blakeembrey blakeembrey Dec 13, 2016

Choose a reason for hiding this comment

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

The other issue with using functions is that the code is no longer serialisable and there's a minor fear that this will introduce incompatibilities with CSS-in-JS implementation since it can not be statically analysed anymore. For instance, it's possible to use PostCSS with free-style, but this breaks that. It also break other static analysis tooling and infrastructure - vendor prefixing, etc. will all be broken. I'm going to hold off merging this as a result, sorry!

Copy link
Author

Choose a reason for hiding this comment

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

Can you help me understand what would be broken and how? The expectation with this function is that it is only ever called once.

Copy link
Owner

Choose a reason for hiding this comment

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

PostCSS, vendor prefix, things that expect numbers or strings. All modules that can currently augment a style object would need to be notified that this change in expectations has occurred, as it won't be very useful for a style processor to skip a function instance because it doesn't understand it (or worse, crash or omit it altogether thinking it's invalid) and, as a result, not update the style with vendor prefixes.

Copy link
Author

Choose a reason for hiding this comment

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

I will test that out in postcss and autoprefixer and see how they react. In a perfect world they should simply copy the value of each property onto each prefixed property.

Copy link
Owner

@blakeembrey blakeembrey Dec 14, 2016

Choose a reason for hiding this comment

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

And what about vendor prefixing of the value and not the property name? It would be skipped in that case. I don't think it's a worthwhile change to break expectations at this point, that's all.

Copy link
Author

Choose a reason for hiding this comment

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

Alright, well it was worth a try. Will close this PR for now.

Copy link
Owner

Choose a reason for hiding this comment

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

No worries. I thought it was a nice solution too, I'd just rather maintain compatibility with the larger ecosystem. There's also possibilities in the future where we could inline all of free-style, but function calls make that a little trickier.

@coveralls
Copy link

Coverage Status

Coverage decreased (-0.4%) to 98.425% when pulling 500a6c0 on notoriousb1t:master into f37fdc1 on blakeembrey:master.

1 similar comment
@coveralls
Copy link

Coverage Status

Coverage decreased (-0.4%) to 98.425% when pulling 500a6c0 on notoriousb1t:master into f37fdc1 on blakeembrey:master.

@coveralls
Copy link

Coverage Status

Coverage increased (+0.02%) to 98.819% when pulling 359e0b8 on notoriousb1t:master into f37fdc1 on blakeembrey:master.

1 similar comment
@coveralls
Copy link

Coverage Status

Coverage increased (+0.02%) to 98.819% when pulling 359e0b8 on notoriousb1t:master into f37fdc1 on blakeembrey:master.

// check again for null because value could be null
if (value2 == null) {
continue
}
Copy link
Owner

Choose a reason for hiding this comment

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

There's really no need for both these checks. Just moving the one check would have been adequate (two lines changed) as typeof null === 'object'.

Copy link
Author

Choose a reason for hiding this comment

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

That is true

@coveralls
Copy link

coveralls commented Dec 13, 2016

Coverage Status

Coverage increased (+0.005%) to 98.805% when pulling 3b21d89 on notoriousb1t:master into f37fdc1 on blakeembrey:master.

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.

None yet

3 participants