Reputation: 7081
I have a couple of Views which do not seem to have logically coherent Models. I can still try to create dummy Models for these (and properly have routers as well) but it seems unnatural to me.
So is having a Backbone View without a corresponding Model an anti-pattern?
What do the experts say on this?
Upvotes: 11
Views: 2622
Reputation: 48167
I don't think it is specifically an anti-pattern. If all you are trying to do is encapsulate view behavior, it might make sense to write a view and attach it to an element. It might not have any business logic or persistable data... it might just be a View that encapsulates view behavior (like something that manages the state of an element based on events). In that case, there is no need for a model.
On the other hand, if you are managing a bunch of variables (persistable or not) and any type of business logic, then it makes sense to break that out into a model.
Upvotes: 5
Reputation: 1777
If you are considering adding a dummy model or any other logic/code to make the architecture fit a pattern, that should be a red herring. The pattern should be there to assist you in designing logically well organized predictable code.
Upvotes: 3
Reputation: 72868
the various components of backbone play well with each other, but there's no need for them to always go together.
i very regularly have models with no views, and views with no models. each of the pieces of a backbone app can be used in many different ways to facilitate what you need your app to do.
Upvotes: 16