hellosmithy
hellosmithy

Reputation: 279

Ember.js statemanager and router. Ok to use both?

What's the best practice regarding managing different types of state? For example I have an app where some state makes sense to be tied to a route so I'm using the router, but other states can't be reflected in the URL and it wouldn't make sense to do so. Is it ok then to have some state managed by the full router and other state managed by an instance of state manager? Is it acceptable to have multiple state managers or is that a bad idea?

Upvotes: 1

Views: 263

Answers (1)

Ryan
Ryan

Reputation: 3594

Yes - it is perfectly acceptable to use the Ember.StateManager in areas that are not the router.

The router is really good at handling overall application state, wiring models/views/controller together, rendering to outlets, and always being available without a global dependency. However, the router is really just a state manager that can only be in one state at once and sometimes additional states are needed within other objects.

You can use the StateManager inside of your objects. A example of this would be a Car model that would have states like: driving, parked, crashed, repairing. State manager is a good fit here because there is a finiate state and you can control available actions. For example, it wouldn't make sense to go from driving->repairing, only crashed->repairing would be allowed.

Upvotes: 3

Related Questions