mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-12-22 10:21:36 +03:00
f78f264982
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
27 lines
576 B
JavaScript
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;
|