Last active
August 25, 2018 08:55
-
-
Save tswistak/240d6e2a3ffb65a8d5bb8ada4f5188e5 to your computer and use it in GitHub Desktop.
InversifyJS with React, listing 1
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import * as React from "react"; | |
| import { IProvider } from "./providers"; | |
| export class Hello extends React.Component { | |
| private readonly nameProvider: IProvider<string>; | |
| render() { | |
| return <h1>Hello {this.nameProvider.provide()}!</h1>; | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import "reflect-metadata"; | |
| import * as React from "react"; | |
| import { render } from "react-dom"; | |
| import { Hello } from "./Hello"; | |
| const App = () => ( | |
| <div> | |
| <Hello /> | |
| </div> | |
| ); | |
| render(<App />, document.getElementById("root")); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import { Container } from "inversify"; | |
| import { IProvider, NameProvider } from "./providers"; | |
| export const container = new Container(); | |
| container.bind<IProvider<string>>("nameProvider").to(NameProvider); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import { injectable } from "inversify"; | |
| export interface IProvider<T> { | |
| provide(): T; | |
| } | |
| @injectable() | |
| export class NameProvider implements IProvider<string> { | |
| provide() { | |
| return "World"; | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment