简体   繁体   English

ember-data-何时,何地创建持久性存储的方式

[英]ember-data - when, where an how to create the persistent store

With ember data, where is the best place to create the store. 借助余烬数据,创建商店的最佳位置在哪里。

Should I create it before I create the application object? 在创建应用程序对象之前应该创建它吗?

Should I create it as a property of the application object, eg 我是否应该将其创建为应用程序对象的属性,例如

app = Ember.Application.create()
app.set('Store', App.Store.create())

I've been working with Ember for a while but this has often been a point of confusion for me. 我已经与Ember合作了一段时间,但这常常使我感到困惑。

What is the recommended approach? 推荐的方法是什么?

The main problems I have is when it comes to tests. 我遇到的主要问题是测试。 Destroying the store is problematic. 销毁商店是有问题的。

Create a Store (capital s) property on your application namespace before the app initializes. 在应用初始化之前,在您的应用名称空间上创建一个Store(大写)属性。 Ember Data registers an injection that will automatically instantiate the store as well as give both the router and controllers access to it. Ember Data注册了一个注入,该注入将自动实例化商店,并使路由器和控制器都可以访问它。 For example. 例如。

App = Ember.Application.create();
App.Store = DS.Store.extend({
  adapter: DS.RESTAdapter.extend()
});

And later on you can do things like this. 然后,您可以执行以下操作。

router.get('store');
router.get('userController.store');

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM