Skip to content

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

Closed
@tracker1

Description

@tracker1

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.

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions