In a Backbone.Marionette application I'm building, we have an authentication which returns a user
object, which we in turn stash at App.User
(so it's not truly global).
The problem I'm having is that I don't want to make a call to an API endpoint to access the various properties of the returned user
object. The specific use case I'm working through right now is that the returned user
object contains data about which modules in the app the user is permitted to access (no worries about security, we've clarified that it's OK that the user can spoof a var in their console to gain access to the UI, the services layer will prevent their actions in such an area from being meaningful).
My goal is to avoid a scenario where every time I need access to users.appAccess
(a hypothetical array that lists the modules I can access) in order to instantiate it as a model I have to call out to a URL / API endpoint by declaring it in the collection's definition like this:
Entities.Access = Backbone.Collection.extend({
url: 'http://example.com/users/:id/access/',
}
});
Removing the url
property from the above code throws an error, and I can pass it a function which returns empty but this doesn't play nice with
var access = new Entities.Access()
access.fetch();
when attempting to pass the fetched collection to a Marionette CollectionView. Should I simply avoid using the fetch()
method and keep it otherwise a typical (albeit hack-ish) Backbone collection definition?