quiver-react-support
TypeScript icon, indicating that this package has built-in type declarations

0.2.6 • Public • Published

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}`;
    }
    
}

Package Sidebar

Install

npm i quiver-react-support

Weekly Downloads

1

Version

0.2.6

License

ISC

Unpacked Size

57.7 kB

Total Files

26

Last publish

Collaborators

  • janis-r