Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

V2 #1564

Closed
26 of 29 tasks
popomore opened this issue Oct 25, 2017 · 32 comments
Closed
26 of 29 tasks

V2 #1564

popomore opened this issue Oct 25, 2017 · 32 comments

Comments

@popomore
Copy link
Member

popomore commented Oct 25, 2017

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 .

@atian25
Copy link
Member

atian25 commented Oct 25, 2017 via email

@popomore
Copy link
Member Author

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

@axetroy
Copy link

axetroy commented Oct 26, 2017

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.

@popomore
Copy link
Member Author

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

@atian25
Copy link
Member

atian25 commented Oct 26, 2017

@axetroy Koa3 is just remove the older signature of middleware.(koajs/koa#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.

@dead-horse
Copy link
Member

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 ?

@popomore
Copy link
Member Author

popomore commented Nov 1, 2017

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

@popomore
Copy link
Member Author

popomore commented Nov 1, 2017

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() });

@atian25
Copy link
Member

atian25 commented Nov 2, 2017

should we rewrite with TS 🙃

@axetroy
Copy link

axetroy commented Nov 2, 2017

@atian25
#1430
#409

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

@dead-horse
Copy link
Member

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.

@atian25
Copy link
Member

atian25 commented Nov 2, 2017

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

@waitingsong
Copy link
Contributor

waitingsong commented Nov 3, 2017

强烈建议基于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源码,应该就可以实现类型的自动挂接(注入?)了

@shyser
Copy link

shyser commented Nov 4, 2017

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

@shepherdwind
Copy link
Contributor

shepherdwind commented Nov 6, 2017

@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 是无所谓的。

@shepherdwind
Copy link
Contributor

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

@kaoding
Copy link

kaoding commented Nov 6, 2017

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

@popomore
Copy link
Member Author

popomore commented Nov 7, 2017

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

@atian25
Copy link
Member

atian25 commented Nov 7, 2017

we should provide ability for user to custom router, such as #882 (maybe need a new Router RFC)

@dead-horse
Copy link
Member

eggjs/koa-override#4

@dead-horse
Copy link
Member

[email protected] released #1637

@atian25
Copy link
Member

atian25 commented Nov 9, 2017

eggjs/egg-schedule#29

@dead-horse
Copy link
Member

koajs/onerror#27

@dead-horse
Copy link
Member

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
}

@atian25
Copy link
Member

atian25 commented Nov 9, 2017

eggjs/egg-development#12

@atian25
Copy link
Member

atian25 commented Nov 17, 2017

eggjs/benchmark#14

@eggjs eggjs unlocked this conversation Nov 22, 2017
@dead-horse
Copy link
Member

dead-horse commented Nov 23, 2017

The differences between generator function style and async function style

@acodercat
Copy link

这种操作支持了吗

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

@atian25
Copy link
Member

atian25 commented Dec 1, 2017

eggjs/egg-core#134

@ngot
Copy link
Member

ngot commented Dec 4, 2017

eggjs/egg-socket.io#28

@atian25
Copy link
Member

atian25 commented Dec 11, 2017

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

@atian25 atian25 closed this as completed Dec 11, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

10 participants