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

defcomponent #254

Closed
GetContented opened this issue Oct 13, 2014 · 9 comments
Closed

defcomponent #254

GetContented opened this issue Oct 13, 2014 · 9 comments

Comments

@GetContented
Copy link

Would you consider creating an extremely thin defcomponent (to clean up repetition usage) and putting it into om proper? Pretty much same syntax as om-tools, but without all of the extra validation (and other) stuff they have?

The other thing that I think would be useful is not having to specify the options hash and the #js literals. Not having to do these has been really handy.

@brendonjohn
Copy link

Hey @JulianLeviston, have you seen the component macro https://github.com/swannodette/om/wiki/Documentation#component ?

(defn my-component [app owner]
  (reify
    om/IRender
    (render [this]
            (dom/div nil nil))))

would become...

(defn my-component [app owner]
  (om/component (dom/div nil nil)))

@GetContented
Copy link
Author

Yeah I have, thanks... it only implements render, though. it's not what I'm asking for. (Most of my components use at least render-state & init-state and quite a few of them use the prop change methods like will-receive-props).

@swannodette
Copy link
Member

I have no plans for any macro sugar at this time.

@GetContented
Copy link
Author

@swannodette thanks for your consideration. Doesn't it bother you that you write a lot of repeated code?

@swannodette
Copy link
Member

It does not bother me. om-tools exists for people who find value in sugar.

@GetContented
Copy link
Author

@swannodette Thank you.

@loganlinn
Copy link
Member

Pretty much same syntax as om-tools, but without all of the extra validation (and other) stuff they have?

For the record, om-tools does not force extra validation upon you. The schema features are there for you to use if you wish for either runtime validation or code documentation, but if you don't use them the defcomponent macro does not emit any code with mentionable overhead inside the component. Please let me know if you find otherwise. In the current version of om-tools, the only thing that's added is just a wrapping let and an conditional to lookup if validation is enabled (since it can be turned on at runtime) -- and we are working to remove this. Upcoming version of om-tools will even remove the small amount of code that goes unused (and removed by optimizer) this to be exactly what you're looking for.

@loganlinn
Copy link
Member

@JulianLeviston Actually, it just occurred to me that what you're asking for already exists in om-tools. See om-tools.core/component. It's very similar to om.core/component in that it expands to (reify ...) (ie not def'ing anything), but supports the other lifecycle methods.

@GetContented
Copy link
Author

Thank you for taking the time to write to me, @loganlinn I'll definitely check it out. I appreciate your response a lot.

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

No branches or pull requests

4 participants