Skip to content
This repository has been archived by the owner on Apr 29, 2021. It is now read-only.

Adds option that allows passing component tags as reference #43

Merged
merged 5 commits into from
Apr 26, 2016

Conversation

mairatma
Copy link
Contributor

I'm not sure if this is something that you'd want to merge, but I added an option on my fork of babel-incremental-dom to enable passing upper case tags by reference to incremental dom calls, even though that doesn't work without extra code. I need this for a project I'm working on, where we already handle this case internally, but needed the compiler to work as expected.

I saw that you already have an issue (#9) for working on this feature, but since it seems to waiting for some changes on incremental dom's side I think this option I've added could be useful for some people, so sending it in case you agree as well :)

@@ -18,5 +18,6 @@ export default function elementCloseCall(t, path, plugin) {
}
}

return toFunctionCall(t, iDOMMethod("elementClose", plugin), [toReference(t, node.name)]);
const isComponent = /^[A-Z]/.test(node.name.name);
Copy link
Owner

Choose a reason for hiding this comment

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

Can you create a helper specifically for this? isComponent sounds perfect.

@jridgewell
Copy link
Owner

Yay contributions! I think the only thing missing is a test for <namespace.Component />.

@mairatma
Copy link
Contributor Author

Thanks for considering and reviewing this! I've added the changes you've requested, so let me know if they're what you meant :)

@@ -4,7 +4,7 @@ import toReference from "./ast/to-reference";
import iDOMMethod from "./idom-method";

// Returns the closing element's function call.
export default function elementCloseCall(t, path, plugin) {
export default function elementCloseCall(t, path, plugin, { components, isComponent }) {
Copy link
Owner

Choose a reason for hiding this comment

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

Almost, I was aiming for a isComponent helper function like iDOMMethod and similar:

# helpers/is-component.js
export default function isComponent(tag) {
  return /^[A-Z]/.test(tag);
}

# helpers/element-close-call.js
import isComponent from './is-component';

//...

@mairatma
Copy link
Contributor Author

Makes sense, done :)

@jridgewell jridgewell merged commit b4c9fd1 into jridgewell:master Apr 26, 2016
@jridgewell
Copy link
Owner

Thanks!

@jridgewell jridgewell mentioned this pull request Apr 26, 2016
2 tasks
@mairatma
Copy link
Contributor Author

Thank you! Could you also release an npm version with these changes so I can use them instead of my fork? :)

@jridgewell
Copy link
Owner

I'll try to get to that tomorrow.

@jridgewell
Copy link
Owner

Published v3.1.0

@anilanar
Copy link

anilanar commented Sep 4, 2016

@mairatma What kind of extra code is needed to be able to use this?

@mairatma
Copy link
Contributor Author

mairatma commented Sep 5, 2016

@anilanar you just need to make sure that you're using babel-plugin-incremental-dom version >= 3.1.0 when building your code.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants