top | item 4661707

Crashlytics Labs announces the release of Backbone.StateManager

62 points| KB | 13 years ago |crashlytics.com

15 comments

order

zalambar|13 years ago

Seems to me like this is reinventing parts of ember.js on top of Backbone. That's neat but when my apps need this sort of behavior I'm willing to be they will also need solutions to other common problems and I'd rather not reassemble a large framework out of disparate pieces to get that level of functionality. When do you decide that you have so many layers on top of Backbone that you have a custom stack no one else will understand?

ville|13 years ago

Could someone give a practical example of a use case for this? This is probably useful for some typical problems in Backbone applications but not something I knew I would need (having built a couple of non-trivial Backbone apps).

Jare|13 years ago

Useful to manage parts of your application (or the whole thing) as state machines. For example, a simple email app might have top-level states such as:

- list of folders

- contents of a given folder

- contents of a thread

- contents of a message

- compose message

- profile settings

- ...

In a typical MVC app, the 'enter' method of each state would set up the appropriate models, views and controllers, and the 'exit' method would do the corresponding teardown / cleanup. You could tie this to the history API (or history.js) to support URL linking and navigation.

But states can mean anything you want as long as only one of them can be active at any time in a given context (StateManager). In a Vim implementation you could manage the normal / insert / visual editing modes using States. In a space shooter game, you could have the player spaceship be in normal, shielded, dead, etc states.

The link to Backbone is extremely thin and basically limited to using Backbone's event system to trigger state change events.

camachgk|13 years ago

One practical application could be a drop down in a view that is tied to a bunch of functionality and a route update. With two access points (user click or URL changes) to any of the drop down values and the associated behavior ("states"), StateManager provides a modular way for defining each of those states and handling the associated functionality for transitions.

eranation|13 years ago

If I understood correctly, seems it can be useful for a tour/wizard flow, that has a complex graph of options (user can exit at any time and next option is dependant on the previous choice, etc).

politician|13 years ago

You could think of it as an abstraction of the Router mechanism.

devinus|13 years ago

Just use Ember, guys. Your future selves will thank your past selves.