我们在数据访问方面有各种要求。
reference
数据。 LocalStorageAdapter
。 sync changes
(在后台轮询或使用Socket.IO
并更新LocalStorage可以做到这一点)off-line
,并且应该稍后同步更改。 使其更具体:
pre-load
供应商和“最喜欢的产品”进入本地存储。我们与那些人脱机工作。 因此可以从中得出一些问题:
我知道我们必须手动完成很多这样的工作,并将不同的乐高乐器组合在一起,但我想从经验Ember开发者那里寻求一些观点。
答案 0 :(得分:1)
你绝对可以做到这一点。就像你说的那样,你需要做很多乐高乐器才能把它们放在一起。
您需要使用RESTAdapter和LSAdapter并创建混合。我们在工作中做了一些类似的事情,但它只采用了一种方式(从服务器到客户端,而不是反向)。
话虽如此,我只想提出几个问题:
您计划在localStorage中存储多少,并且您是否制定了驱逐计划?对于大多数浏览器来说,本地存储通常很小,但大多数浏览器的实现都是相同的(直到IE8才实现)。 IndexedDB为您提供了更大的空间,但直到IE的更高版本才能实现。
根据性能需求,我建议首先存储localStorage,然后尝试保留到服务器,如果它从localStorage弹出,如果它没有留在那里供你的适配器尝试以后的日期。 (我会考虑使用Ember的日程安排或scheduleOnce或在运行循环中运行的一系列其他方便助手,http://emberjs.com/api/classes/Ember.run.html#method_schedule)。
Called by the store when a newly created record is
`save`d.
It serializes the record, and `POST`s it to a URL generated by `buildURL`.
See `serialize` for information on how to customize the serialized form
of a record.
createRecord: function(store, type, record) {
var data = {};
var serializer = store.serializerFor(type.typeKey);
serializer.serializeIntoHash(data, type, record, { includeId: true });
// build up a model that knows the url, the method, and the data to post
// store it to local storage in some queue to save
// schedule it to save to server later, keep track of the record since you'll
// need to update the record with new information later that could come down
// from the server
return this.ajax(this.buildURL(type.typeKey), "POST", { data: data });
},
老实说,我认为您可能遇到的最困难的事情就是当您没有真正将其保存到服务器时如何处理ID。祝你好运