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

Support nodes whose tag is a function. #77

Merged
merged 1 commit into from Feb 11, 2017
Merged

Conversation

jorgebucaran
Copy link
Owner

@jorgebucaran jorgebucaran commented Feb 10, 2017

HyperApp's architecture is largely based in Flux/Redux and/or the Elm Architecture. There's a single state shared by all the views. Another way to put that, views can't have a local state.

But what about components? The answer is stateless components.

<MyComponent props=...></MyComponent>

Related

This makes it possible to create jsx components
in this way: <MyComponent props=...></MyComponent>
@codecov
Copy link

codecov bot commented Feb 10, 2017

Codecov Report

Merging #77 into master will decrease coverage by -0.32%.

@@            Coverage Diff             @@
##           master      #77      +/-   ##
==========================================
- Coverage   72.72%   72.41%   -0.32%     
==========================================
  Files           3        3              
  Lines         143      145       +2     
==========================================
+ Hits          104      105       +1     
- Misses         39       40       +1
Impacted Files Coverage Δ
src/h.js 94.11% <66.66%> (-5.89%)

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 f29647b...7bc45ec. Read the comment docs.

@danigb
Copy link
Contributor

danigb commented Feb 10, 2017

That's a really nice addition 👏👏

@tunnckoCore
Copy link

tunnckoCore commented Feb 10, 2017

Cool!

But i believe it would be better to pass data directly and append the children, it is how is done in React and etc? I played with this and mich-h stuff and kinda don't liked to add children "special property" to the props.

	if (typeof tag === "function") {
		tree = tree || []
		data.children = tree
		return tag(data, tree)
	}

So

const Foo = (props) =>
  <div id={props.id} className={props.cls}>{props.children}</div>

const Foo2 = (props, children) =>
  <div id={props.id} className={props.cls}>{children}</div>

const foo = <Foo cls="baz qux" id="hi">
  <strong>hello</strong>
</Foo>

Because what you proposed is a bit nested/more typing, i believe it would be something like

const Foo2 = (ctx) =>
  <div id={ctx.props.id} className={ctx.props.cls}>{ctx.children}</div>

@tunnckoCore
Copy link

tunnckoCore commented Feb 10, 2017

Hm... No, no, nevermind. Kinda like more your approach when rethink it. It is more clean and explicit.

const Foo2 = ({ props, children }) =>
  <div id={props.id} className={props.cls}>{children}</div>

It won't be react compatible directly, but who cares, it is more clean :))

@tunnckoCore
Copy link

tunnckoCore commented Feb 11, 2017

Don't know, I like them either way. Current, no-react-compatible is more cleaner.

@jorgebucaran jorgebucaran merged commit 6316557 into master Feb 11, 2017
@jorgebucaran jorgebucaran deleted the jsx-components branch February 15, 2017 10:42
jorgebucaran added a commit that referenced this pull request Jan 7, 2018
This makes it possible to create jsx components
in this way: <MyComponent props=...></MyComponent>
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

4 participants