@
yimity 用异步没啥不好,不想异步么用async搞。
我觉得关键的问题不是在异步上,而是在怎么让这个过程自动化。不要让回调充斥整个代码,打乱逻辑。
我自己给express写了个扩展,最后的话控制器大概是这样的:
app.post('/api/create',Run(
web.IF(Form.isValidated('createuser'))(
'createuser'
),
Http.notFoundIf(Form.isPending('createuser')),
Form.doJsonErrors('createuser')
));
app.post('/api/update',Run(
web.IF(Form.isValidated('updateuser'))(
'updateuser'
),
Http.notFoundIf(
Form.isPending('updateuser'),
Form.isError('updateuser','id')
),
Form.doJsonErrors('updateuser')
));
app.post('/api/toggle',Run(
web.IF(Form.isValidated('toggleuser'))(
'toggleuser'
),
Http.notFoundIf(
Form.isPending('toggleuser'),
Form.isError('toggleuser','id')
),
Form.doJsonErrors('toggleuser')
));
app.post('/api/setpassword',Run(
web.IF(Form.isValidated('setpassword'))(
'setpassword'
),
Http.notFoundIf(
Form.isPending('setpassword'),
Form.isError('setpassword','uid')
),
Form.doJsonErrors('setpassword')
));
app.get('/api/users',Run(
Http.notFoundIfNot(Form.isValidated('listuser')),
MVC.doJsonData('usersjson')
));
app.get('/api/admin_history_recently',Run(
MVC.doJsonData('adminHistoryRecently')
));
app.load(__dirname+'/role/routers');
app.use(Run(Http.doNotFound('Page not found')));
//app.get('/index',Runtime(MVC.doRender('listuser')));
app.use(HttpError(404)(MVC.doRender('404')));