-
Notifications
You must be signed in to change notification settings - Fork 141
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
Higher order component or container component instead of mixin #44
Comments
Turns out there was some misunderstanding on this. Mixins are not going anywhere (at least not soon). The React Router guys reverted their code back to mixins. https://github.com/rackt/react-router/blob/master/UPGRADE_GUIDE.md I prefer to avoid ES6 classes for as long as possible (hopefully forever). I would prefer a ''this-less" style for React. |
@mindjuice could you please elaborate on a this-less style? You can easily use How is
less 'this-less' than
I think it's nicer, if you don't force others to use a certain feature if it's not necessary. To reduce code duplication, you could even use the mixin internally:
|
Programming JS without Anyway, I generally avoid Of course, with React I don't get to avoid My comment was just wishful thinking that React would move to a "thisless" style. It's something that they have thought about based on comments I've see before. Also, there is this "declarative" experiment to create a React component in the react-future repo. I don't follow your comment about forcing others to use a certain feature. Which feature is being forced onto others? |
By only providing a mixin, as a consumer of Nuclear I'm forced to write the components in a certain way. I understand, that this is sometimes necessary when choosing your tools / libraries. You can use the decorators under all circumstances, while mixins are only working with |
I see. Yes, it would be nice if it worked regardless of which way you chose to structure your objects. Decorators would require ES6 though, so perhaps it could provide both mixins and decorators. |
It'd require ES7 even, if you really want to use the
I'd definitely be willing to contribute a PR if there's interest in this. With the approach outlined above it'd result in that the requested bindings are no longer available on |
I will definitely investigate this more, as its my goal to have first class support for use of with React out of the box. However I imagine there are ways to use a Nuclear Reactor to create some sort of The following statement is from the React v0.13.0 Beta 1 blog post
If React adopts a good solution support a more compositional paradigm I believe that would suit Nuclear's functional style. Until then it seems fine for people to create their own @ksmth if you are interested in PRing an example of using this style of NuclearComponent class I would be happy to merge and link from the README as the prescribed way of using NuclearJS with React ES6 classes. |
I'm with @ksmth on this one. While mixins are still the idomatic way of sharing code across React components, it's pretty clear that they're not ideal. It seems to me that the React team is waiting to see what patterns emerge in the community, and I think Nuclear should be making an effort towards contributing to that. I'm not suggesting replacing flux.ReactMixin, but instead proving a second/alternative baked-in manner for sharing store binding logic. I see a few benefits to using a higher order function instead of a mixin: 1 - Leans on composition over inheritance It seems to me that Relay Components are pushing for this sort of pattern, and I think we can substitute graphql with Nuclear getters to achieve something similar. I like a slightly modified API to what @ksmth first wrote. The difference being, I think you can safely rely on the factory living off of the reactor, and I wouldn't pass state down into child components.
A possible, more JSX derived, alternative might look like this: import {NuclearComponent} from 'nuclear-js'
import SomeFluxModule from './some-flux-module'
const dataBindings = {
someValue: SomeFluxModule.Getters.someValue
}
class MyComponent extends React.Component {
render() {
return (
<NuclearComponent dataBindings={dataBindings}>
<MyChildComponent />
</NuclearComponent>
)
}
}
class MyChildComponent extends React.Component {
render() {
return <div>{this.props.someValue}</div>
}
} I strongly encourage more debate on introducing a non-mixin-based way to get Nuclear store data into a component. |
fwiw I find a standardized NuclearComponent to be pretty interesting, for many of the reasons listed above. Mixin's certainly shouldn't go anywhere though. Hopefully once a few members of the community have built & used their own for a bit we can get a PR. I may try this myself. |
One problem with JSX components is they will only work on a particular platform. We'd have to have separate components for DOM, iOS, Android, etc etc. Not to mention other frameworks! |
Don't think that's necessarily true. JSX isn't a templating language like we're used to (handlebars, lodash, etc), because it isn't meant to build up HTML; it's a declarative syntax for building up virtual DOM. That reason is exactly why it can be used to create native iOS UI elements, android elements, and even arbitrary trees representing anything you'd like. Getting a component to work against multiple platforms would/should be an implementation detail in my opinion. |
I definitely agree with having a HoC/decorator/wrapper. |
Having an alternative to Mixins would be great! |
https://github.com/jordangarcia/nuclear-js-react-addons should suit your needs. Let us know what you think. |
Looks awesome @Sinewyk @jordangarcia. Really like that it supports decorators too |
Glad I came across this after it was solved :). |
Closing this as it can be found here: https://github.com/jordangarcia/nuclear-js-react-addons |
As React is moving away from mixins, it might make sense to start talking about alternatives. Maybe something along the lines of:
Which you could then use like:
The text was updated successfully, but these errors were encountered: