Skip to content

Support using constructor property types only, instead of @Inject #26

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
tracker1 opened this issue Mar 8, 2016 · 7 comments
Closed
Assignees

Comments

@tracker1
Copy link

tracker1 commented Mar 8, 2016

I wrote a wrapper using your connect, inside my own store.js file...

...
import Connector from 'ng2-redux/lib/components/connector'

export function Store(reduxStore) {
  const __connector = new Connector(reduxStore);
  return {
    ...reduxStore,
    connect: __connector.connect
  };
}
...
export function createStore() {
  ...
  return Store(createStoreWithMiddleware(reducer, state));
}

Then in my index.js ...

import {Store, createStore} from './store';
...
bootstrap(App, [
  provide(Store, { useValue: createStore() }),
  ...
]);

This way, in my components, I only need constructor(store:Store) to get the store reference, which works with babel/es6 as well as the preferred use for ng2.

Yes, it's explicit and one step removed from the provider, however, it allows for easier integration at the component level... not sure if the provider itself could be changed to support a type reference, but it would be nicer than poluting my constructors with @Inject


Maybe if you separated Connector, and its' dependencies into an ng2-redux-connector module, so it can be used more easily? Either with the provider method this module uses, or the more explicit method I used.

@lanocturne
Copy link

+1

Thanks,
Stanislaus

@e-schultz
Copy link
Member

@tracker1 We are working on some changes for the next major release, and we will include something like this. Thanks for the input/code - much appreciated.

@e-schultz
Copy link
Member

can also use an OpaqueToken

@e-schultz
Copy link
Member

@tracker1 getting ready to have a new release available soon that will support property injection instead of needing @Inject, sorry for the delay on getting this out.

@e-schultz e-schultz self-assigned this Apr 25, 2016
@SethDavenport
Copy link
Member

@e-schultz is this fixed by 2.2.3?

@SethDavenport
Copy link
Member

As of release 2.2.3 you can now do:

class FooComponent {
  constructor(private ngRedux: NgRedux) {}
}

@tracker1
Copy link
Author

tracker1 commented May 7, 2016

Cool... no longer working on the app in question, but nice to see the feature just the same. Really do like working with Redux over the "angular way" of services, etc...

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