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

detect observables properly when children are passed as part of props… #4

Merged
merged 2 commits into from
Feb 9, 2017

Conversation

rekotiira
Copy link

… argument to createElement

Right now karet assumes that children are always passed in React.createElement(type, props, [...children])'s argument children, however it is also possible that children are passed in the props object. For example if you take props as an argument for a component and then spread that as a whole to another component:

const Test = (props) => <div {...props} />

const x = <Test>Hello {Kefir.constant('world')}</Test>

This will yield, when transpiled, in:

var Test = function Test(props) {
  return React.createElement('div', props);
};

var x = React.createElement(
  Test,
  null,
  'Hello ',
  Kefir.constant('world')
);

If children is just a single element, karet will actually work properly, but in case children is an array, like in this example, karet will fail to detect the observable in the array.

This PR addresses the issue.

@codecov-io
Copy link

codecov-io commented Feb 8, 2017

Codecov Report

Merging #4 into master will increase coverage by 0.23%.

@@            Coverage Diff             @@
##           master       #4      +/-   ##
==========================================
+ Coverage   91.24%   91.47%   +0.23%     
==========================================
  Files           1        1              
  Lines         217      223       +6     
==========================================
+ Hits          198      204       +6     
  Misses         19       19
Impacted Files Coverage Δ
src/karet.js 91.47% <100%> (+0.23%)

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 aa6103b...9d82e85. Read the comment docs.

@rekotiira
Copy link
Author

Added a test

@polytypic
Copy link
Member

LGTM. Thanks!

@polytypic polytypic merged commit f478b66 into calmm-js:master Feb 9, 2017
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