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

Sun, 29 Apr 2018 12:20:55 GMT logic deprecated logic's __after method is deprecated, it will be discarded in the next version at node_modules\_bluebird@3.3.5@bluebird\js\release\util.js:16:23 #1146

Closed
newcomein opened this issue Apr 29, 2018 · 28 comments

Comments

@newcomein
Copy link

DESC

ENV

OS Platform:

Node.js Version: 10.0

ThinkJS Version:3.2.7

code

// your code here

error message

// your error message here

more description

// your detail description

@lizheming
Copy link
Contributor

你有用 __after 魔术方法?

@newcomein
Copy link
Author

@lizheming 有用

@lizheming
Copy link
Contributor

你是什么场景用的?因为几乎没有场景,__after 魔术方法下个大版本会废弃掉。

@newcomein
Copy link
Author

newcomein commented Apr 29, 2018

@lizheming 我去 居然要废掉... 我是用这个方法来对所有的logic层进行最后的处理 跟我controller里面继承的base __after一致

例如,所有的logic层的__before都会有下面的处理方法

const pathName = this.ctx.path.slice(this.ctx.path.lastIndexOf('/') + 1);
        this.ctx.state.data = this.ctx.post() || this.ctx.param();
        this.ctx.state.pathName = pathName;

获取到请求的路径名,获取提交或请求的数据;

base的__after会这样写

this.body = {
            [this.ctx.state.pathName]: await this.ctx.state.result
        }

按照请求的路径名输出json
结果会是:

{
    pathName:data
}

@lizheming
Copy link
Contributor

唔?你说的好像是 __before() ?

@newcomein
Copy link
Author

@lizheming

this.body = { [this.ctx.state.pathName]: await this.ctx.state.result }

这个是__after

@lizheming
Copy link
Contributor

你不写控制器的咩?控制器里有返回的话就会被魔术方法覆盖掉诶

@newcomein
Copy link
Author

newcomein commented Apr 29, 2018

@lizheming

let error;
try {
            await transporter.sendMail(mailOptions);
            this.model('verify/verify').addMailcode(field);
        } catch (err) {
            error = err.message
        }

        this.ctx.state.result = error || {verify_id: field.verify_id};

最终会执行__after就可以了,反正我__after就是统一用来处理最后返回给客户端的数据

@lizheming
Copy link
Contributor

那你在 controller 中间件后面加一个中间件来处理吧,效果是一样的感觉~

@newcomein
Copy link
Author

这.....但是不清真啊 🙄

@newcomein
Copy link
Author

@lizheming

@lizheming
Copy link
Contributor

为啥不清真?其实本来就是一回事... 在 controller 的控制器之后做一些事情而已。而且你这个操作真的好奇怪,控制器里不返回,把数据存到 state 里面,然后魔术方法里去返回。。。
其实你就只是想要包装下返回的数据而已,完全可以直接复写 this.success() 方法去做,放 __after 来做感觉更不清真...万一控制器里提前返回了真是 gg 了。

@newcomein
Copy link
Author

@lizheming 有点儿道理

@newcomein
Copy link
Author

@lizheming

(node:13488) [DEP0095] DeprecationWarning: timers.enroll() is deprecated. Please use setTimeout instead. (node:13488) [DEP0096] DeprecationWarning: timers.unenroll() is deprecated. Please use clearTimeout instead.

升级了node之后 就报这个错

@newcomein
Copy link
Author

@lizheming 在使用this.add()的时候

@lizheming
Copy link
Contributor

你用 timers.enroll() 啦?

@newcomein
Copy link
Author

@lizheming 完全没用

@newcomein
Copy link
Author

是一个很清真的

async addMailcode(data) { this.add(data); }

@lizheming
Copy link
Contributor

你的数据库用的是什么 handle ?

@newcomein
Copy link
Author

@
"think-model": "^1.2.2",
"think-model-mysql": "^1.0.6",

mysql 5.7

@lizheming
Copy link
Contributor

那可能是哪个依赖模块用了吧,think-model 也没有使用过,摊手~ 哎呀 warning 忽略就好啦~

@newcomein
Copy link
Author

@lizheming 啦样子 很烦耶 又不能try catch

@lizheming
Copy link
Contributor

lizheming commented Apr 29, 2018

依赖(甚至可能是依赖的依赖)写的,这个我们也很难办诶~ 摊手 ~

@newcomein
Copy link
Author

😂 好吧

@lizheming
Copy link
Contributor

安啦,时间会解决一切的(逃。。。
ps. 这个issue我先关闭啦,有新的问题的话可以新开 issue 继续讨论~ ✧(≖ ◡ ≖)

@newcomein
Copy link
Author

@lizheming 你们能在官网上加个页面 用来公布提前公布下一个版本的计划目标和阶段吗

@lizheming
Copy link
Contributor

太长远的计划不敢列诶,因为指不定就坑了... 2333
不过偶尔可以看看 project https://github.com/thinkjs/thinkjs/projects/2 虽然很久没更新了,之后我慢慢补起来吧~

@zy445566
Copy link

@newcomein @lizheming
是mysql库用了timers.enroll,而在node10里面把这个废弃了
mysqljs/mysql#2003

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants