V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
爱意满满的作品展示区。
jswh
V2EX  ›  分享创造

初学 ts,写了个玩具 - yet another toy typescript framework

  •  
  •   jswh · 2016-12-14 11:38:56 +08:00 · 2256 次点击
    这是一个创建于 2683 天前的主题,其中的信息可能已经有所发展或是发生改变。

    一直很喜欢 flask 的路由写法,看到 TS 也有 decorator 就搞了一个。

    import {Router, HttpRequest, BaseController} from "yattsf"
    
    export class HelloController extends BaseController {
          @Router.get('/')
          hello(req:HttpRequest) {
              return 'hello';
          }
    }
    
    第 1 条附言  ·  2016-12-14 13:23:19 +08:00
    3 条回复    2016-12-14 12:01:01 +08:00
    EPr2hh6LADQWqRVH
        1
    EPr2hh6LADQWqRVH  
       2016-12-14 11:56:20 +08:00
    我也写了一个,不过是基于 koa

    ```
    import { RouteHost, Middleware, Controller, ExtendedContext, NextCallback, RouteHub } from 'petropub-dev-lib';

    export class HelloWorldBaseRoutes extends RouteHost {

    @Middleware('/666', { restrict: undefined })
    helloWorld__(ctx: ExtendedContext, next: NextCallback) {
    ctx.body += '333';
    return next();
    }

    };

    export class HelloWorldRoutes extends HelloWorldBaseRoutes {

    @Controller('GET', '/666')
    helloWorld(ctx: ExtendedContext, next: NextCallback) {
    ctx.body += '6666';
    return next();
    }
    @Middleware('/666', { restrict: undefined })
    helloWorld_(ctx: ExtendedContext, next: NextCallback) {
    ctx.body += '5555';
    return next();
    }

    };

    let theHelloWorldHub = new RouteHub();
    new HelloWorldRoutes(theHelloWorldHub);

    export { theHelloWorldHub }
    ```
    jswh
        2
    jswh  
    OP
       2016-12-14 12:00:56 +08:00
    @avastms 😝
    jswh
        3
    jswh  
    OP
       2016-12-14 12:01:01 +08:00
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   2583 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 25ms · UTC 01:34 · PVG 09:34 · LAX 18:34 · JFK 21:34
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.