Ghost/ghost/admin/app/helpers/member-fetcher.js
Kevin Ansfield f78f264982
Fixed PromiseObject related errors thrown from members activity list (#15641)
no issue

- the `memberRecord` getter on the members activity controller was
returning the direct result of `store.findRecord()` which in reality is
a `PromiseObject` that is a type of proxy. Although templates handle
this OK, any JS code using the object needs to know that it's not a
typical type of object and has to use `.get()` for all property access
to avoid errors
- switched `memberRecord` from a getter to a resource so we have more
control over the returned object and loading lifecycle
- added a `MemberFetcher` resource class that awaits the result of the
store find and only then sets the value meaning we always have a fully
resolved model object
- being a resource the fetch will only occur when the `member` id
property changes, unlike the getter which performed the fetch every time
it was accessed
2022-10-17 15:28:34 +02:00

27 lines
576 B
JavaScript

import {Resource} from 'ember-could-get-used-to-this';
import {inject as service} from '@ember/service';
import {tracked} from '@glimmer/tracking';
class MemberFetcher extends Resource {
@service store;
@tracked loadedMember = null;
get value() {
return this.loadedMember;
}
async setup() {
const [memberId] = this.args.positional;
if (!memberId) {
return;
}
const record = await this.store.findRecord('member', memberId);
this.loadedMember = record;
}
}
export default MemberFetcher;