Emberjs - 两个定制适配器

时间:2014-06-05 10:29:52

标签: ember.js ember-data indexeddb web-sql

我正在开发一个需要使用indexedDB来离线存储某些信息的应用程序,但在Safari的情况下,它还没有(还),所以我需要使用webSQL。

我已经使用this适配器用于indexedDB,而enter link description here polyfill用于不支持indexedDB的浏览器。

不幸的是,我在Shim上遇到了一些重大问题,例如,在iOS Safari和Safari上,在我的应用程序中,我需要获取数据库中的一些数据以查看它是否存在它会给我带来错误。

喜欢这个和那个:

throwDOMException@http://localhost/Dev/Websites/myWebsite/js/libs/IndexedDBShim.js:40:16

Error: Assertion Failed: 0: The operation failed because the requested database object could not be found. For example, an object store did not exist but was being opened

这是因为他们正在使用某种黑客来返回某些价值,甚至在填充物中他们也这么说:

// The IndexedDB Specification needs us to return an Object Store immediatly, but WebSQL does not create and return the store immediatly // Hence, this can technically be unusable, and we hack around it, by setting the ready value to false

所以我的问题是,使用indexedDB适配器,我可以并行为webSQL添加其他适配器吗?

1 个答案:

答案 0 :(得分:1)

我认为你最好的选择是在运行时选择正确的适配器(你的意思是并行吗?)。应该这么简单:

var App = Ember.Application.create();
App.deferReadiness();

if (window.indexedDB) {
    App.ApplicationAdapter = IndexedDBAdapter;
} else {
    App.ApplicationAdapter = WebSQLAdapter;
}

App.advanceReadiness();
相关问题