Closed popomore closed 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.
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.
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
我肯定是籽池的,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.
强烈建议基于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 通过源码拿到类型,据我所知只有两种方式
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@2.0.0-beta.1 released https://github.com/eggjs/egg/pull/1637
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
}
not built-in plugin list:
edit this, change the text to PR link, then assign to yourself.
await parts()
instead of yield parts
(yield parts()
also worked). https://github.com/eggjs/egg-multipart#upload-multiple-filesrole
plugin's handler change to ctx
and don't support generator function now. https://github.com/koajs/koa-roles/pull/13 , https://github.com/eggjs/egg-userrole/pull/9await
an object or nested array. (which co
supported)这种操作支持了吗
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.
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
toAsyncFunction
andtoPromise
. https://github.com/eggjs/egg-core/pull/124BTW: whether
egg
change core to koa v2 or not, you could useasync
andkoa2 middleware
fast from egg first version 1.0.0 .