Bootstrapping app with data

If you only have one store you can access it through DS.get('defaultStore').

Out bootstrap initializer looks something like this:

App.initializer({
    name: 'appBootstrap',
    initialize: function() {
        App.deferReadiness();
        $.get('/user/bootstrap', function(payload) {
            var store = DS.get('defaultStore');
            //User
            store.load(App.User, payload.user);
            App.session.set('user', App.User.find(payload.user.id));
            //Other
            store.loadMany(App.Currency, payload.currencies);
            store.loadMany(App.Country, payload.countries);
            //Initialize app
            App.advanceReadiness();
        });
    }
});

/user/bootstrap returns everything needed to start the app. To save some requests we include all countries and currencies in the bootstrap response. We have an object, App.session which is responsible for holding information about the currently authenticated user.

You should not try to use the store before the app has been initialized.

6 Likes