在每个Ember环境中保留具有多个适配器的固定装置 [英] Retain fixtures with multiple adapters per Ember environment

查看:85
本文介绍了在每个Ember环境中保留具有多个适配器的固定装置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

虽然自然进程会用其他适配器更换夹具适配器,我会喜欢为开发环境保留固定装置,同时利用不同的Ember数据适配器进行生产。

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.

这是由于:


  • 逐步增强的重迭迭代

  • 为了在iOS应用程序中嵌入UIWebView中,生产配置与本地程序集的数据交换紧密耦合。

Ember CLI 资产编译是基于西兰花加载Web或Native API:

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.

为了开发,我想使用模拟数据或http服务在浏览器中启用测试。

For development, I want to use mock data or http services to enable testing in browser.

因此,在开发环境中启动Ember服务器可以利用灯具。

Therefore, launching Ember server in development environment leverages fixtures.

ember server --environment=development

此配置将扩展 FixtureAdapter 进行开发:

This configuration would extend FixtureAdapter for development:

var ApplicationAdapter = DS.FixtureAdapter.extend({
    /* ... */
});
export default ApplicationAdapter;



生产环境



然而,复杂度是需要不同适配器的生产环境。

Production Environment

However, the complexity is production environment where different adapters are needed.

在生产中启动Ember服务器时,服务通过一个bridge://方案提供,其中原生iOS应用程序正在管理传输层和数据模型。

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;

如何在Ember应用程序中使用多个适配器?应用程序如何交换适配器,或者路由中的​​商店可能会定义不同的适配器?

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;

希望能帮助

这篇关于在每个Ember环境中保留具有多个适配器的固定装置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆