Skip to content
This repository has been archived by the owner on Mar 4, 2020. It is now read-only.

fix(factories): styles defined as func are not working #470

Merged
merged 4 commits into from
Nov 14, 2018

Conversation

mnajdova
Copy link
Contributor

@mnajdova mnajdova commented Nov 13, 2018

TODO

  • update CHANGELOG

This PR fixes #415

@codecov
Copy link

codecov bot commented Nov 13, 2018

Codecov Report

Merging #470 into master will not change coverage.
The diff coverage is n/a.

Impacted file tree graph

@@           Coverage Diff           @@
##           master     #470   +/-   ##
=======================================
  Coverage   88.96%   88.96%           
=======================================
  Files          41       41           
  Lines        1387     1387           
  Branches      177      202   +25     
=======================================
  Hits         1234     1234           
  Misses        149      149           
  Partials        4        4

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 55c6f6a...cc71111. Read the comment docs.

@mnajdova mnajdova added 🧰 fix Introduces fix for broken behavior. 🚀 ready for review labels Nov 13, 2018
test('deep merges overrideProps styles as function onto styles prop', () => {
expect.assertions(1)

const overrideProps = {
Copy link
Contributor

Choose a reason for hiding this comment

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

it might be a bit easier to reason about expected results if these two props objects will be swapped

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I would rather leave this tests the same as the previous ones for consistency, as the only difference is changing the objects to functions.

@@ -106,7 +107,13 @@ export function createShorthand(

// Merge styles
if (defaultProps.styles || overrideProps.styles || usersProps.styles) {
props.styles = _.merge(defaultProps.styles, usersProps.styles, overrideProps.styles)
props.styles = (...args) => {
return _.merge(
Copy link
Contributor

@kuzhelov kuzhelov Nov 13, 2018

Choose a reason for hiding this comment

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

don't we want to have mergeStyles function that would encapsulate this logic? Similar semantics is expressed in the mergeThemes file:

// mergeComponentStyles() {
...
return _.merge(callable(originalTarget)(styleParam), callable(originalSource)(styleParam))

maybe we could encapsulate and reuse this logic in the following way:

mergeStyles(target: ComponentSlotStyle, ...styles: ComponentSlotStyle[]) {
  ...
}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Agreed, will encapsulate this logic.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Introduced, please review again.

Copy link
Contributor

@kuzhelov kuzhelov left a comment

Choose a reason for hiding this comment

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

it would be great if we'll be able to encapsulate this logic for merging styles, to prevent similar mistakes from happening in future

@kuzhelov kuzhelov added needs author feedback Author's opinion is asked and removed 🚀 ready for review labels Nov 13, 2018
@mnajdova mnajdova merged commit 61ee332 into master Nov 14, 2018
@layershifter layershifter deleted the fix/styles-as-function-in-shorthands branch January 10, 2019 11:26
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
🧰 fix Introduces fix for broken behavior. needs author feedback Author's opinion is asked
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Styles defined as functions in shorthand are not working
3 participants