Draft: Add guide for incremental adoption
Description
Working on guides for incremental adoption of new APIs of EmberData
Notes for the release
guide for incremental adoption
-
ember-data/store(without the @) does not exportCacheHandler, only@ember-data/storedoes, so theimport { CacheHandler }line in theRequestManagerservice should be changed -
import { setBuildURLConfig }seems to be unused and get marked as such by the linter
I also do not know how much hand-holding is needed here, but maybe it should be mentioned that the RequestManager service must be in the file app/services/request-manager.js or the @service declaration in the Store service won't find it without explicitly referring to it (e.g. @service('requests') for app/service/requests.js).
hey @fry69 thanks for review and testing, good inputs - I will update accordingly Also please keep in mind there code here not works just yet, some fixes were made, but not yet released, especially around service injection area.
The goal is to get this working, right? IMHO nothing is more frustrating that simple sample code which does not work. I just want to point out some pitfalls, here are some others:
-
@ember-data/json-apiin the version 4.12.x does not seem to have aquery()in the/request->Could not find module @ember-data/json-api/request imported from (require) -
@ember-data/request-utilsdoes not exist for 4.12.x -
host: config.api.hostinside the JSON:APIquery()(using EmberData 5.3) does not set the host for said query, it still talks tolocalhost(my old styleadapterbased queries work fine with the same config) -
host: config.api.hostseems to get respected if I put it into a call tosetBuildURLConfig()inside theconstructor()of/app/app.js -
console.log()fromTestHandlernever show up even if my request now flows through this new service (and fails because of a missing API key, so it is clearly not using the old, working flow/store)? - even if I completely clear the
this.use()array in theRequestManager, my request still comes through (and fails because of missing said API key), which leads me to believe thestoreservice is not using the newRequestManagerat all, but a different one, the@servicedoes not seem to be enough in this case? - it seems to work with 5.3.0 and current
alpha.22preview release IF the code fromRequestManagergets moved into thestoreservice, otherwise I getRequestManager.useCache(<handler>) May only be invoked onceerrors
This the store.js that works for me:
// eslint-disable-next-line ember/use-ember-data-rfc-395-imports
import Store from 'ember-data/store';
import { CacheHandler } from '@ember-data/store';
import RequestManager from '@ember-data/request';
import Fetch from '@ember-data/request/fetch';
import { LegacyNetworkHandler } from '@ember-data/legacy-compat';
const APIKeyHandler = {
request({ request }, next) {
console.log('APIKeyHandler() called');
const headers = new Headers(request.headers);
headers.append(
// see AuthHandler example
);
return next(Object.assign({}, request, { headers }));
}
}
export default class MyStore extends Store {
requestManager: RequestManager;
constructor(args) {
super(args);
this.requestManager = new RequestManager;
this.requestManager.use([LegacyNetworkHandler, APIKeyHandler, Fetch]);
this.requestManager.useCache(CacheHandler);
}
}
Latest version looks great, thank you @Baltazore
@runspired where do we put it? I need to update the location of file, and then fix nav links. But overall I think this is ready
@sly7-7 thanks for review, would need to finalize some questions
@runspired apparently I don't know how to use github (only gitlab on work 😄 ) I left some questions last week, but to submit those questions I should have click a button that only visible in diff view 🤦
@Baltazore One more time I want to thank you for this work. I've just migrated to ED 5.3.3, and got my app working with the Legacy Store. Now I'm trying to switch to the new paradigm (ie using @ember-data/json-api/request instead of adapter/serializer. I really think this work will help me to move forward. Eventually if I find something missing, or don't understand something I'll let you know here.
@Baltazore Did you just do a rebase ?
@Baltazore Did you just do a rebase ?
yes, have I lost something ?
I don't think so, actually I was speaking with @runspired and he asked me if I could make the rebase, because he wanted to merge :)
@runspired, @Baltazore has been quickier 😄 so I guess you can merge