Last active
December 29, 2015 00:38
-
-
Save narqo/bf7debec89a760e6b007 to your computer and use it in GitHub Desktop.
Yet another concept of async BEMTREE templates
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
block('global').def(function() { | |
var data = this.param('req'), | |
host = this.param('apiHost'), | |
params = {}; | |
return async(function() { | |
try { | |
var result = await(this.httpInvoke({ host : host, path : '/some/api' }); | |
var status = result.status; | |
if(!status) { | |
throw new Error('unknown request!'); | |
} | |
params.login = result.login; | |
params.info = result.info; | |
} catch(e) { | |
console.error('Something happend!', e); | |
} | |
this.ctx.params = params; | |
return applyNext(); | |
}); | |
}); |
Это должен быть аналог текущей реализации на промисах:
block('global').def(function() {
var data = this.param('req'), // ← представим, что это `BEMContext#param()`, по аналогии с i-bem.js
host = this.param('apiHost'),
params = {};
return this.doAsync(function() {
return this.httpInvoke({ host : host, path : '/some/api' }) // ← какой-нибудь `BEMContext#httpInvoke()`
})
.then(function(result) {
var status = result.status;
if(!status) {
throw new Error('unknown request!');
}
params.login = result.login;
params.info = result.info;
return params;
})
.fail(function(e) {
console.error('Something happend!', e);
return {};
})
.then(function(params) {
this.ctx.params = params;
return applyNext();
});
});
про проблемы с контекстами я (долго) не думал пока >_>
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
напиши примерно, во что это должно скомпилироваться?