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

feat(asCore): Convert asCore into getCoreStyles helper #376

Merged
merged 6 commits into from
Mar 13, 2018

Conversation

arahansen
Copy link
Collaborator

Helps reduce the depth of React tree rendering to partially fix #370. Also, some preliminary work that should make the react-native port easier.

@@ -9870,10 +9870,10 @@ exports[`Storyshots Config Provider Spacing Aliases 1`] = `
style={
Object {
"backgroundColor": "#efefef",
"borderBottomWidth": 48,
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I'm stumped why these values changed. When loading storybook in browser, the styles are correct, and screenshot comparisons are passing. Is this a limitation with how context works within storyshots perhaps?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Oh interesting it's only affecting those set by context. It does sound like an enzyme limitation not liking the changes but not sure if there's much we can do about it.

As far as we have this covered with other tests (like the image comparison ones you mentioned) I think we are good

@arahansen arahansen requested a review from obartra February 26, 2018 07:17
Copy link
Collaborator

@obartra obartra left a comment

Choose a reason for hiding this comment

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

We discussed offline a similar approach that would allow us to turn other HOCs in the project into utility functions and retain the HOC export.

The idea is that instead of returning a JSX object they should return a plain object. Something like:

return <Component {...props} style={cssStyle} />

with:

return { ...props, style: cssStyle }

You can then turn a utility function back into a HOC with:

const asCore = Wrapper =>
  (props, context) => <Wrapper {....myUtilAsCore(props, context)} />

We may run into other limitations so not requesting changes but it seemed worth exploring.

@@ -8,17 +8,26 @@ import type {
} from '../types'
import { styles, getCol } from './grid.styles'
import { getValue } from '../utils'
import asCore from '../core/asCore'
import { sharedResolutionProperties, getCoreStyles } from '../core'
Copy link
Collaborator

Choose a reason for hiding this comment

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

there should be only a single default export from core. The goal is that you can either import { x } from 'gymnast or import x from 'gymnast/x' and they are both equivalent.

This allows a consumer to potentially use the babel lodash plugin to reduce the size of gymnast even further.

If these values are meant to be exported they should be available as gymnast/getCoreStyles and if not they should live elsewhere (e.g. gymnast/core/utils).

Because core is not exported, this wasn't caught by these tests but it may be useful to keep the file structure consistent

@@ -27,8 +36,11 @@ export default function asGrid(
justify && styles[`${justify}Justify`],
])

return <Component {...props} ref={innerRef} className={classes.join(' ')} />
return <Component ref={innerRef} {...props} className={classes.join(' ')} />
Copy link
Collaborator

Choose a reason for hiding this comment

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

just curious on whether this change matters for flow or something like that

return asCore(Grid, resolutionProperties)
return withResolution(
Grid,
sharedResolutionProperties.concat(resolutionProperties)
Copy link
Collaborator

Choose a reason for hiding this comment

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

why not keep this responsibility within withResolution?


return withResolution(
Layout,
sharedResolutionProperties.concat(resolutionProperties)
Copy link
Collaborator

Choose a reason for hiding this comment

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

same here

import { combineSpacing, getValue } from '../utils'
import type { ConfigProviderContext, OneResolution } from '../types'

export const sharedResolutionProperties = [
Copy link
Collaborator

Choose a reason for hiding this comment

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

I wouldn't export these and just move them as part of getCoreStyles

Copy link
Collaborator

@obartra obartra left a comment

Choose a reason for hiding this comment

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

Awesome job with these changes! 💯

Thanks for the contribution! Looking forward thr RN implementation

@arahansen arahansen changed the title refactor(asCore): Convert asCore into getCoreStyles helper feat(asCore): Convert asCore into getCoreStyles helper Mar 13, 2018
@arahansen arahansen merged commit 3b781f6 into master Mar 13, 2018
@arahansen arahansen deleted the arahansen/core-utils branch March 13, 2018 16:17
@arahansen arahansen mentioned this pull request Mar 13, 2018
@obartra
Copy link
Collaborator

obartra commented Sep 6, 2018

🎉 This PR is included in version 16.0.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

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.

Reduce React Trace
2 participants