eggjs / egg

🥚 Born to build better enterprise frameworks and apps with Node.js & Koa
https://eggjs.org
MIT License
18.88k stars 1.81k forks source link

V2 #1564

Closed popomore closed 6 years ago

popomore commented 6 years ago

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 commented 6 years ago

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.

popomore commented 6 years ago

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

axetroy commented 6 years ago

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 commented 6 years ago

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

atian25 commented 6 years ago

@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.

dead-horse commented 6 years ago

We can start working at egg@2 now.

Any breaking changes should we land in 2.x ?

popomore commented 6 years ago

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

popomore commented 6 years ago

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 commented 6 years ago

should we rewrite with TS 🙃

axetroy commented 6 years ago

@atian25

1430

409

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

dead-horse commented 6 years ago

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 commented 6 years ago
waitingsong commented 6 years ago

强烈建议基于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 commented 6 years ago

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

shepherdwind commented 6 years ago

@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 commented 6 years ago

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

kaoding commented 6 years ago

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

popomore commented 6 years ago

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

atian25 commented 6 years ago

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

dead-horse commented 6 years ago

https://github.com/node-modules/koa-override/pull/4

dead-horse commented 6 years ago

egg@2.0.0-beta.1 released https://github.com/eggjs/egg/pull/1637

atian25 commented 6 years ago

https://github.com/eggjs/egg-schedule/pull/29

dead-horse commented 6 years ago

https://github.com/koajs/onerror/pull/27

dead-horse commented 6 years ago

egg-multipart:

const parts = ctx.multipart();
while ((part = await parts()) != null) {
  // do something
}
const parts = ctx.multipart();
while ((part = yield parts) != null) {
  // do something
}

// yield parts() also work
while ((part = yield parts()) != null) {
  // do something
}
atian25 commented 6 years ago

https://github.com/eggjs/egg-development/pull/12

atian25 commented 6 years ago

https://github.com/eggjs/benchmark/pull/14

atian25 commented 6 years ago

not built-in plugin list:

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

dead-horse commented 6 years ago

The differences between generator function style and async function style

acodercat commented 6 years ago

这种操作支持了吗

app.namespace('/sub', middleware, router => {
  router.get('/test1', 'test1');
  router.get('/test2', 'test2');
});
atian25 commented 6 years ago

https://github.com/eggjs/egg-core/pull/134

ngot commented 6 years ago

https://github.com/eggjs/egg-socket.io/pull/28

atian25 commented 6 years ago

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