admin管理员组文章数量:1126296
I have a model Post
that used a @computed
decorator like this
@hasMany('comment', {async: true}) comments;
@computed('[email protected]')
get authorNames(){
let comments = thisments;
let authorNames = comments.mapBy('authorName');
return authorNames.join(', ');
}
I want to migrate this so it no longer uses @computed
. Instead I want to use @tracked
and getters. The problem I am having is that the relationship @hasMany('comment', {async: true}) comments;
is asynchronous but the get
is not. For example:
@tracked names
get authorNames(){
let comments = thisments;
if(!comments.isFulfilled){
this.names = 'loading';
return this.names;
}
this.names = comments.mapBy('authorName').join(',');
return this.names;
}
does not work. Any idea?
I have a model Post
that used a @computed
decorator like this
@hasMany('comment', {async: true}) comments;
@computed('[email protected]')
get authorNames(){
let comments = this.comments;
let authorNames = comments.mapBy('authorName');
return authorNames.join(', ');
}
I want to migrate this so it no longer uses @computed
. Instead I want to use @tracked
and getters. The problem I am having is that the relationship @hasMany('comment', {async: true}) comments;
is asynchronous but the get
is not. For example:
@tracked names
get authorNames(){
let comments = this.comments;
if(!comments.isFulfilled){
this.names = 'loading';
return this.names;
}
this.names = comments.mapBy('authorName').join(',');
return this.names;
}
does not work. Any idea?
Share Improve this question asked Jan 8 at 22:14 mate89mate89 1566 bronze badges1 Answer
Reset to default 1Ended up using
get authorNames(){
return this.comments?.content?.map(i => i.authorName).join(', ') || '';
}
That also removes a deprecation about accessing PromiseManyArray
directly.
本文标签: javascriptProper way to migrate computed decoratorsStack Overflow
版权声明:本文标题:javascript - Proper way to migrate @computed decorators - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1736684964a1947612.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论