Although the natural progression would replace the fixture adapter with another adapter, I'd like to retain fixtures for development environment while leveraging a different Ember data adapter for production.
This is due to:
Ember CLI asset compilation is based on broccoli to load either a Web or Native API:
app.import({
development: 'vendor/company/WebAPI.js',
production: 'vendor/company/NativeAPI.js'
});
However, I'm unsure how to leverage this pattern to change adapters.
For development, I want to use mock data or http services to enable testing in browser.
Therefore, launching Ember server in development environment leverages fixtures.
ember server --environment=development
This configuration would extend FixtureAdapter for development:
var ApplicationAdapter = DS.FixtureAdapter.extend({
/* ... */
});
export default ApplicationAdapter;
However, the complexity is production environment where different adapters are needed.
When launching Ember server in production, services are provided via a bridge:// scheme where the native iOS app is managing transport layer and data models.
ember server --environment=production
This configuration would extend the base Adapter for production:
var ApplicationAdapter = DS.Adapter.extend({
/* ... */
});
export default ApplicationAdapter;
How can multiple adapters be used in an Ember app? How is the adapter swapped in the App, or perhaps the store from the route would define a different adapter?
You could provide a global application adapter that will be aware of your environment and export the best suited adapter depending on the current environment (same thing for your serializer if needed):
+-- app
| |-- adapters
| | `-- application.js
| | `-- custom-adapter.js
| |-- ...
| |
| |-- serializers
| `-- application.js
| `-- custom-serializer.js
application.js:
import DS from 'ember-data';
import config from '../config/environment';
import CustomAdapter from './custom-adapter';
var adapter = DS.FixtureAdapter.extend({});
if (config.environment === 'production') {
adapter = CustomAdapter;
}
export default adapter;
custom-adapter.js:
import Ember from 'ember';
import DS from 'ember-data';
var adapter = DS.RESTAdapter.extend({
// your custom RESTAdapter
});
export default adapter;
Hope it will help
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With