I hereby claim:
- I am andywer on github.
- I am andywer (https://keybase.io/andywer) on keybase.
- I have a public key ASAaseoxu8cFB_1LgQKirVmIAnK46TA20OoMraS114BRwAo
To claim this, I am signing this object:
| /* | |
| * Description: | |
| * | |
| * There are times when we want to re-use some data created/derived in a middleware later in a route handler. | |
| * | |
| * The default Koa way of doing so would be using `context.state`. Unfortunately `context.state` is hard to type and | |
| * quite implicit, since it's an object shared and potentially mutated by all middlewares and the route handler. | |
| */ | |
| /* |
I hereby claim:
To claim this, I am signing this object:
| import { createApp, respond, route } from "koax" | |
| import pkg from "../package.json" | |
| const app = createApp() | |
| app.get("/", async () => { | |
| const body = { | |
| name: pkg.name, | |
| version: pkg.version | |
| } |
| import { Responses as PublisherAPIResponses } from "@satoshipay/publisher-service-api" | |
| import axios from "axios" | |
| import { URL } from "url" | |
| import config from "../config" | |
| export async function getPublisherById (id: string) { | |
| const url = new URL(`/${id}`, config.publisherServiceUrl).toString() | |
| return await axios.get(url) as PublisherAPIResponses["GET /*"] | |
| } |
| import Koa from "koa" | |
| import * as KoaHAL from "$new-hal-koa-package" | |
| import { api, Users } from "./hal" | |
| const app = new Koa() | |
| const koaRouter = KoaHAL.Router(api, router => { | |
| // GET /users | |
| router.get(Users, async ctx => { | |
| const users = await queryAllUsers() |
Thanks to React hooks you have now happily turned all your classes into functional components.
Wait, all your components? Not quite. There is one thing that can still only be implemented using classes: Error boundaries.
There is just no functional equivalent for componentDidCatch and deriveStateFromError yet.
| /******/ (function(modules) { // webpackBootstrap | |
| /******/ // The module cache | |
| /******/ var installedModules = {}; | |
| /******/ | |
| /******/ // The require function | |
| /******/ function __webpack_require__(moduleId) { | |
| /******/ | |
| /******/ // Check if module is in cache | |
| /******/ if(installedModules[moduleId]) { | |
| /******/ return installedModules[moduleId].exports; |