Egg: V2

Created on 25 Oct 2017  ·  32Comments  ·  Source: eggjs/egg

There is no roadmap now, and I don't know when will be released.

We can record ideas in this issue for the next major release, I create v2 project to manage the ideas.

List of Action

BTW: whether egg change core to koa v2 or not, you could use async and koa2 middleware fast from egg first version 1.0.0 .

discussion

Most helpful comment

should we rewrite with TS 🙃

All 32 comments

should we still support koa1 and generator?
if not, how to help user mergate, codemod?

发自我的 iPhone

在 2017年10月26日,01:00,Haoliang Gao notifications@github.com 写道:

There is no roadmap now, and I don't know when will be released.

We can record ideas in this issue for the next major release, I create v2 project to manage the ideas.


You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub, or mute the thread.

I think we should support generator function, but we can improve performance for async function without co wrapper.

Node@8 LTS is coming.
It's meaningless for support generator function, and Koa@3 will abandone it.
If you guy still need to support, should throw an wanning infomation when they are using.

It should be backward compatible with all applications, generator function is widely used in several years.

@axetroy Koa3 is just remove the older signature of middleware.(https://github.com/koajs/koa/pull/1011)

in egg, generator is not only use at middleware, but service / schedule / etc..

so we don't need to drop support of generator, we just need to remove co wrapper for async function to improve the performance as @popomore mentions upper.

We can start working at egg@2 now.

  • migrate koa 1.x to koa 2.x
  • completely compatible with egg 1.x generator functions
  • codemod tool to help applications' migration (co to async function)

Any breaking changes should we land in 2.x ?

Remove sticky from egg-cluster, and integrate to egg-socket.io @ngot

We add toAsyncFunction wrapper in egg v1 first, it's compatible with the usage of generator function.

// wrap generator function and async function
await toAsyncFunction(function*() {})();
await toAsyncFunction(async () => {})(); 

// wrap array supported in co
const [ foo, bar ] = yield [ fooFn(), barFn() ];
const [ foo, bar ] = await toAsyncFunction([ fooFn(), barFn() ]);

// wrap object supported in co
const { foo, bar } = yield { foo: fooFn(), bar: barFn() };
const { foo, bar } = await toAsyncFunction({ foo: fooFn(), bar: barFn() });

should we rewrite with TS 🙃

@atian25

1430

409

我肯定是籽池的,Typescript免除了多少潜在的BUG,用过的人都说好

should we rewrite with TS 🙃

egg core won't rewrite by ts, but we can support ts more friendly, @popomore already has a draft for this.

  • Docs: use async to replace generator at docs
  • does our guide need different version?

强烈建议基于TS

defaultConfig.ts:

export interface IDefaultConfig {
    idc: {
        dllTxt: string;
        dllImage: string;
    };
    img: {
        width: number;
        height: number;
    };
}

export class DefaultConfig implements IDefaultConfig {
    idc = {
        dllTxt: 'c:/sdtapi.dll',
        dllImage: 'c:/wltrs.dll',
    };
    img = {
        width: 344,
        height: 435,
    };
}

export default new DefaultConfig();

declare module 'egg' {
    export interface Application {
        config: EggAppConfig & IDefaultConfig;  // <-------
    }

    export interface AjaxResp {
        err: number;
        dat?: null | any;
        msg?: string | null;
    }

}

controller/img.ts:

import {Controller} from 'egg';
import * as fs from 'fs';
import * as path from 'path';

export default class ImgController extends Controller {
    public read(): void {
     //.....
    }

}

declare module 'egg' {
    export interface IController {
        img: ImgController;    // <---------
    }
} 

需要在declare module 'egg'中重复定义导出,有点蛋蛋的忧伤。基于TS源码,应该就可以实现类型的自动挂接(注入?)了

@atian25 强烈建议出一个TS的脚手架选项!

@waitingsong egg 现在通过 loader 自动注入的,现在 ts 是没有动态注入,直接用 ts 也需要 declare module 'egg' 的。ts 通过源码拿到类型,据我所知只有两种方式

  1. import
  2. declaration merging https://www.typescriptlang.org/docs/handbook/declaration-merging.html

egg 本身是否基于 ts 来写,是不影响 ts 使用方式的。只要有合适的类型描述文件,库本身是否基于 ts 是无所谓的。

vue 的插件扩展也是这样写的 https://vuejs.org/v2/guide/typescript.html

大概什么时候发布基于koa2的egg next啊?

We will add some codemod for transforming generator function to async function

we should provide ability for user to custom router, such as https://github.com/eggjs/egg/issues/882 (maybe need a new Router RFC)

egg-multipart:

  • in async function:
const parts = ctx.multipart();
while ((part = await parts()) != null) {
  // do something
}
  • in generator function:
const parts = ctx.multipart();
while ((part = yield parts) != null) {
  // do something
}

// yield parts() also work
while ((part = yield parts()) != null) {
  // do something
}

not built-in plugin list:

edit this, change the text to PR link, then assign to yourself.

  • [ ] [egg-mock](https://github.com/eggjs/egg-mock)
  • [ ] egg-utils
  • [ ] [egg-boilerplate-simple](https://github.com/eggjs/egg-boilerplate-simple)
  • [ ] [egg-boilerplate-plugin](https://github.com/eggjs/egg-boilerplate-plugin)
  • [ ] [egg-cookies](https://github.com/eggjs/egg-cookies)
  • [ ] [egg-cors](https://github.com/eggjs/egg-cors)
  • [ ] [egg-alinode](https://github.com/eggjs/egg-alinode)
  • [ ] [egg-validate](https://github.com/eggjs/egg-validate)
  • [ ] [egg-userservice](https://github.com/eggjs/egg-userservice)
  • [ ] [egg-userrole](https://github.com/eggjs/egg-userrole)
  • [x] https://github.com/eggjs/egg-view-nunjucks/pull/22 @atian25
  • [ ] [egg-rest](https://github.com/eggjs/egg-rest)
  • [ ] [egg-oss](https://github.com/eggjs/egg-oss)
  • [ ] [egg-dingtalk](https://github.com/eggjs/egg-dingtalk)
  • [ ] [egg-tracer](https://github.com/eggjs/egg-tracer)
  • [ ] [egg-mysql](https://github.com/eggjs/egg-mysql)
  • [ ] [egg-ots](https://github.com/eggjs/egg-ots)
  • [ ] [egg-etag](https://github.com/eggjs/egg-etag)
  • [ ] [egg-boilerplate-framework](https://github.com/eggjs/egg-boilerplate-framework)
  • [ ] [egg-knex](https://github.com/eggjs/egg-knex)
  • [ ] [egg-showcase-aliyun-blog](https://github.com/eggjs/egg-showcase-aliyun-blog)
  • [ ] [egg-dns-client](https://github.com/eggjs/egg-dns-client)
  • [ ] [egg-host](https://github.com/eggjs/egg-host)
  • [ ] [egg-boilerplate-empty](https://github.com/eggjs/egg-boilerplate-empty)
  • [ ] [egg-path-matching](https://github.com/eggjs/egg-path-matching)
  • [ ] [egg-logview](https://github.com/eggjs/egg-logview)
  • [ ] [egg-development-proxyagent](https://github.com/eggjs/egg-development-proxyagent)
  • [ ] [egg-instrument](https://github.com/eggjs/egg-instrument)
  • [ ] [egg-view-vue](https://github.com/eggjs/egg-view-vue)
  • [ ] [egg-view-react](https://github.com/eggjs/egg-view-react)
  • [ ] [egg-sequelize](https://github.com/eggjs/egg-sequelize)
  • [ ] [egg-websocket](https://github.com/eggjs/egg-websocket)
  • [x] [egg-socket.io](https://github.com/eggjs/egg-socket.io)
  • [ ] [egg-redis](https://github.com/eggjs/egg-redis)
  • [ ] [egg-zookeeper](https://github.com/eggjs/egg-zookeeper)
  • [ ] [egg-mongoose](https://github.com/eggjs/egg-mongoose)
  • [ ] [egg-view-xtpl](https://github.com/eggjs/egg-view-xtpl)
  • [ ] [egg-watcher-chokidar](https://github.com/eggjs/egg-watcher-chokidar)
  • [ ] [egg-passport-weibo](https://github.com/eggjs/egg-passport-weibo)
  • [ ] [egg-passport-twitter](https://github.com/eggjs/egg-passport-twitter)
  • [ ] [egg-passport-github](https://github.com/eggjs/egg-passport-github)
  • [ ] [egg-passport-bitbucket](https://github.com/eggjs/egg-passport-bitbucket)
  • [ ] [egg-view-handlebars](https://github.com/eggjs/egg-view-handlebars)
  • [x] [egg-graphql](https://github.com/eggjs/egg-graphql)
  • [ ] [egg-session-redis](https://github.com/eggjs/egg-session-redis)
  • [ ] [egg-async-validator](https://github.com/eggjs/egg-async-validator)
  • [ ] [egg-development-proxyworker](https://github.com/eggjs/egg-development-proxyworker)
  • [ ] [egg-view-swig](https://github.com/eggjs/egg-view-swig)
  • [ ] [egg-leancloud](https://github.com/eggjs/egg-leancloud)
  • [ ] [egg-grpc](https://github.com/eggjs/egg-grpc)
  • [ ] [egg-opentracing](https://github.com/eggjs/egg-opentracing)
  • [ ] [egg-development-stub](https://github.com/eggjs/egg-development-stub)
  • [ ] [egg-passport-taobao](https://github.com/eggjs/egg-passport-taobao)
  • [ ] [egg-validate-schema](https://github.com/eggjs/egg-validate-schema)
  • [ ] [egg-ons](https://github.com/eggjs/egg-ons)
  • [ ] [egg-toshihiko](https://github.com/eggjs/egg-toshihiko)

The differences between generator function style and async function style

这种操作支持了吗

app.namespace('/sub', middleware, router => {
  router.get('/test1', 'test1');
  router.get('/test2', 'test2');
});

closing this due to egg@2 is publish, not built-in plugin's upgrade will be left to developers, PR is welcome.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

Webjiacheng picture Webjiacheng  ·  3Comments

Leungkingman picture Leungkingman  ·  3Comments

wujianling picture wujianling  ·  3Comments

skyyangpeng picture skyyangpeng  ·  3Comments

popomore picture popomore  ·  3Comments