Skip to content

Use with .component syntax? #80

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

Closed
dmackerman opened this issue May 18, 2016 · 2 comments
Closed

Use with .component syntax? #80

dmackerman opened this issue May 18, 2016 · 2 comments

Comments

@dmackerman
Copy link

Is it possible to use this library with .component in Angular 1.5? I'm getting the error warning.js:14 Store does not have a valid reducer. Make sure the argument passed to combineReducers is an object whose values are reducers., which seems odd. Here's some code

home.component.js

import * as PhotoActions from 'actions/photo.actions';
import template from './home.component.html';

class HomeController {
    constructor($ngRedux, $scope) {
        const unsubscribe = $ngRedux.connect(this.mapStateToThis, PhotoActions)(this);
        $scope.$on('$destroy', unsubscribe);
    }

    // Which part of the Redux global state does our component want to receive?
    mapStateToThis(state) {
        return {
            photos: state.photos
        };
    }
}

export const homeComponent = {
    template: template,
    controller: HomeController
};

This is attached to a module, .component('homeComponent', homeComponent). All registers just fine, and if I remove the ngRedux code it renders fine.

I have a photos.reducer, which is exported using combineReducers:

import { LOAD_PHOTOS } from 'actions/photo.actions';

export default function photos(state = [], action) {
    switch (action.type) {
        case LOAD_PHOTOS:
            return action.payload;
        default:
            return state;
    }
}

...and then exported as rootReducer from reducers/index.js here.

import { combineReducers } from 'redux';
import photos from './photos.reducer';

const rootReducer = combineReducers({
    photos
});

export default rootReducer;

And in the config phase, I register everything.

import rootReducer from './reducers'
// ...
.config($ngReduxProvider => {
    $ngReduxProvider.createStoreWith(rootReducer, [loggerMiddleware]);
})

Am I doing something wrong, or can this library just not be used with .component and only directive?

@dmackerman
Copy link
Author

Ok, so for whatever reason, it seems to have been a version thing. Everything works with the following versions:

+    "angular": "^1.5.5",
+    "ng-redux": "^3.0.0",
+    "react-redux": "^4.0.1",
+    "redux": "^3.0.0",
+    "redux-devtools": "^3.0.0",
+    "redux-thunk": "^1.0.2"

Copied from the counter example.

@nalejandroveron
Copy link

Hey, i wrote a new featute for this one #121 for being more precise, stay tuned to see if someone reivews the pull request!

@deini deini closed this as completed Sep 1, 2017
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

3 participants