Вопрос

Can a local storage adapter and a data storage adapter be used simultaneously? Here's some example code.

VpcYeoman.ApplicationAdapter = DS.LSAdapter.extend({
      namespace: 'viewpoint-emberjs'
    });

vs.

VpcYeoman.Store = DS.Store.extend({
    revision: 12,
    adapter: DS.FixtureAdapter.extend({
        queryFixtures: function(fixtures, query, type) {            
            return fixtures.filter(function(item) {
                for(prop in query) {
                    if( item[prop] != query[prop]) {
                        return false;
                    }
                }
                return true;
            });
        }
    })

});

Fight! Or coexist??

Это было полезно?

Решение

Yes, absolutely. You can create per-type adapters, so you can have:

App.PostAdapter = DS.FixtureAdapter.extend({
    queryFixtures: function(fixtures, query, type) {            
        return fixtures.filter(function(item) {
            for(prop in query) {
                if( item[prop] != query[prop]) {
                    return false;
                }
            }
            return true;
        });
    }
});
App.Post.FIXTURES = [];

Your other non-fixture types can omit an Adapter and instead use the ApplicationAdapter, which could be an instance of DS.RESTAdapter or LocalStorageAdapter. Optionally, you could define that adapter on the DS.Store instance.

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top