Move `connect` logic to a Mixin
See original GitHub issueThis is contingent on #39 or something similar.
I think the next logical step would be to move the whole thing to a mixin, keeping the connect function in skeletal form, e.g.:
import ReduxComponentMixin from '../mixins';
export default function connect(mapStateToComputed, mapDispatchToActions) {
return Ember.Component.extend(ReduxComponentMixin, {
mapStateToComputed,
mapDispatchToActions
});
}
This would be a big win I think because it would allow users to continue using the connect function as advertised, or they could opt for idomatic Ember which I think would greatly increase adoption and decrease churn.
Users could basically do in their component files the same thing the connect function would have done for them, e.g.:
import ReduxComponentMixin from 'ember-redux/mixins/redux-component';
export default Ember.Component.extend(ReduxComponentMixin, {
mapStateToComputed(state) {
const { users } = state;
return { users };
}
});
Issue Analytics
- State:
- Created 7 years ago
- Comments:7 (3 by maintainers)
Top Results From Across the Web
Mixins - Vue.js
A mixin object can contain any component options. When a component uses a mixin, all options in the mixin will be “mixed” into...
Read more >How to Use Mixins in Sass and Pass Arguments – With Code ...
But an argument allows you to define different styles by turning them into variables. It's like customizing each style for each element. Let's...
Read more >DRY-ing Out Your Sass Mixins - A List Apart
We could do this by using a placeholder selector instead of a mixin, but that means the selectors will be moved in our...
Read more >Is it possible to add one mixin to every view in file automatically?
This makes it explicit that you are using a mixin, but you do not repeat yourself with the test_func logic. This is implemented...
Read more >Create and use Sass Functions - OpenClassrooms
Right now, the heading-shadow mixin has a block of logic that controls ... To do this, you need to move the if/else block...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@dustinfarris thanks for the discussion regarding the wider topic of functional programing (and asking if it should be required for ember devs who want to adopt redux).
I think the challenge I had with this issue originally is that as the project maintainer my preference for a refactor/or change comes 1 of 2 ways.
In this situation it felt as if you were unhappy with the public connect api and you wanted to change it. And in doing so it’s possible the new component we create as a result would appeal to the traditional ember developer (more generally people who don’t think functional first).
This is challenging for me as I don’t plan to use that api and in turn wouldn’t want to maintain it. I left this issue open in hopes of hearing from others in the community who agreed/ or disagreed about its value. As someone who wants to keep the api surface area minimal and education regarding that api simple, I’m still trying to understand if having more than one way to do the same exact thing is good for the project (functional or not).
@dustinfarris short of asking Lauren Tan to define that already fuzzy term “idiomatic ember” 😃
Here are a few that show the migration away from mixins/ toward functions and functional programming for reuse.
https://github.com/DockYard/ember-changeset https://github.com/cibernox/ember-power-select https://github.com/cafreeman/ember-object-update https://github.com/dgeb/ember-engines
Ignoring my subjective bias, the functional approach in software does lend itself to more clarity in my experience. When I call a function, I get a result - no side effects (predictable/repeatable). With mixins (from my experience using them in med/large ember projects) you quickly start reaching for some shared state on the component/controller or you introduce some -that others tap into. Over time it’s easy to lose trace-ability regarding “why” something changed/or what one mixin might have assumed about the given state of another (especially because this is all shared mutable state we are talking about)
Although my initial response seemed to focus in on “no mixin -they are dead” the main point I wanted to share was that keeping this addon constrained to “one look” is it’s strategic advantage/ or what sets it apart from the other redux ember addons. I realize not everyone will be happy with constraints /opinions like this but they are at the heart of what people tell me they love most about using it.