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 backendApi from "./path/to/backendApi"; | |
| import history from "./path/to/configureHistory"; | |
| export function* saveProduct( | |
| action: ISaveProductAction | |
| ) { | |
| const productResult = backendApi.saveProduct(action.productId, action.productData); | |
| yield put(saveUserDetails(userDetails)); | |
| history.push("/products"); | |
| return true; |
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
| /* | |
| /ProductUpdatePage | |
| - connected.ts | |
| - ProductUpdatePage.ts | |
| - index.ts | |
| - saga.ts | |
| - reducer.ts | |
| */ | |
| // ProductUpdatePage.ts |
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
| export default function* configureSagas() { | |
| yield all([ | |
| watchLoadProducts(), | |
| watchSaveProduct(), | |
| // all the watchers that we need from all | |
| // parts of our app | |
| ]); | |
| } | |
| // and a specfic saga will look like |
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
| // now I wanna make a snapshot testing | |
| it("renders home page", () => { | |
| const push = jest.fn() | |
| const mockHistory = { push } as unknown as History; | |
| const page = mount( | |
| <HomePage history={mockHistory}/> | |
| ); | |
| expect(page).toMatchSnapshot(); | |
| // when you need to test a push |
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 DIContext from "./DIContext"; | |
| import { IDIContainer } from "rsdi"; | |
| interface DIResolutionConfig { | |
| [propName: string]: string; | |
| } | |
| type Without<T, K> = { |
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
| /HomePage/HomePage.tsx | |
| import { History } from "history"; | |
| interface IProps { | |
| label: string; | |
| history: History; | |
| } | |
| class HomePage extends PureComponent<IProps> { | |
| render() { | |
| return ( |
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
| // DIContext.ts | |
| import React from "react"; | |
| import DIContainer, { IDIContainer } from "rsdi"; | |
| const DIContext = React.createContext<IDIContainer>(new DIContainer()); | |
| export default DIContext; | |
| // App.ts | |
| // build container only once |
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 DIContainer, { object, get, value, factory, IDIContainer } from "rsdi"; | |
| const config = { | |
| "ENV": value("PRODUCTION"), // define raw value | |
| "Storage": object(CookieStorage), // will instantiate an object of class CookieStorage without arguments | |
| "AuthStorage": object(AuthStorage).construct( | |
| get("Storage") // refer to dependency described above | |
| ), | |
| "BrowserHistory": factory(configureHistory), // factory callback | |
| }; |
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
| @injectable() | |
| export class Client { | |
| constructor(@inject("SuperService") private service: SuperService) {} | |
| } | |
| container.register("SuperService", { | |
| useClass: TestService | |
| }); | |
| const client = container.resolve(Client); |
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
| export default | |
| @withCookies | |
| @withRouter | |
| @connect( | |
| state => { | |
| return { | |
| token: state.auth.token, | |
| currentUser: state.auth.currentUser | |
| }; | |
| }, |