quiver-react-support
v0.2.6
Published
React support package for quiver-framework
Downloads
3
Maintainers
Readme
React support package for Quiver framework
Extending Quiver framework in order to bring support for Dependency injection, View-models of MVVM and event driven architecture into React.
How to use Injector
Configure application context:
import {ApplicationContext} from "quiver-react-support";
const {injector} = new ApplicationContext(/*List of app modules, if any go here*/);
/**
* Create service mapping that'll create new instance of a service for each consumer
*/
injector.map(SomeService);
/**
* Create a singleton service - first instance created will be served to each following consumer
*/
injector.map(SomeService).asSingleton();
/**
* Or we can split service interface from it's implementation, creating strong abstraction
* between interface and implementation.
*/
injector.map(AbstractService).toType(AbstractServiceImplementation);
/**
* Or we can map anything to pre-fabricated value, like this:
*/
injector.map(SomeService).toValue({foo: 1, bar: 2, lee: 3});
Access injected values from React component:
import {Component, Inject} from "quiver-react-support";
export class DisplayComponent extends Component {
@Inject()
private service: SomeService;
render() {
return `SomeService is accessible like: ${this.service}`;
}
}