I have recently updated my ember project code from ember 3.16 to ember 5.12 (and ember-data to 5.3.0)
The following piece of code worked fine in ember 3.16 (without even injecting the store service explicitly).
// =========route.ts============
export default class TopologyViewRoute {
// == Dependencies ==========================================================
@service notifier: any
@service store: any // The code worked find w/o this line in ember 3.16
constructor () {
super(...arguments)
this.rFetch = new RFetch(genericTopologyAdapter, genericTopologySerializer, genericTopologyParser)
}
@task({restartable: true})
* _fetchT (): TaskGenerator<object> {
const topologies = yield this.rFetch.fetch({
adapterOptions: {
context: this.contextPayload
},
serializerOptions: {
store: this.store
}
})
return topologies
}
}
// ===========addon/rfetch.ts===============
async fetch (
{adapterOptions = {}, serializerOptions = {}} :
RFetchOptions = {adapterOptions: {}, serializerOptions: {}}
): Promise<RFetchResult> {
const {url, fetchOptions} = this.adapter(adapterOptions)
const response = await fetch(url, fetchOptions || {})
const payload = await response.json()
return {payload, normalized: this.serializer(payload, serializerOptions)}
}
// ============addon/generic-topo.js =================
export function genericTopologySerializer (payload: Document, {store}: {store: Store}) {
const includedHash = _.keyBy(payload.included, 'id')
const formattedIncluded = payload.included?.reduce((currentIncluded, element) => {
_.set(element, 'attributes.externalSource', element.meta?.externalSource)
const updatedElement = _getUpdatedAggregateElement({element, includedHash})
return [...currentIncluded, updatedElement]
}, [])
const includedForStore = formattedIncluded?.filter((object: ResourceIdentifier) => object.type !== 'topologies') || []
if (includedForStore) store.pushPayload({data: includedForStore}) // store is null if not injected in TopologyViewRoute
return {...payload, included: formattedIncluded}
}
But after updating ember, I started getting error “can’t call pushPayload on undefined”, which I resolved by injecting the store service. But since then, I am getting below error
The supplied identifier {“type”:“management-session”,“id”:“19dc2cfe-e028-4bfd-a162-a12b5e352d6b”,“lid”:“@lid:management-session-19dc2cfe-e028-4bfd-a162-a12b5e352d6b”} does not belong to this store instance
I am not sure why is it complaining about the store and I am passing and using the same store. Is there any other deprecation that I might be missing?