Global Query Params for Deeply Stateful Ember Apps
One perennial issue we run into developing applications at NYC City Planning is the need for persisting deep application state within a URL. It is sometimes an overlooked but powerful feature to share a stateful hyperlink with other colleagues. This is especially true for interactive mapping applications where dozens of map layers and layer-specific filtering logic requires complex and carefully-named query parameters.
Joshua Hornby proposes using Ember Services (global singletons):
Here, a “date” service contains all query parameter state. The developer uses computed aliases to make them more accessible in whichever classes they need.
I’d propose something similar, but much simpler:
Here, we avoid the added cruft of aliasing properties from the service (and therefore re-creating the original problem) and name the controller’s query parameters directly. This approach, combined with the excellent Ember Parachute, will make things much more manageable in situations where deep and complex state must be preserved in the URL.
On top of that, you can even organize query parameters into a nested object. This can help with name-spacing the parameters. Here’s an example of a service:
This way, we are able to reference nested properties. For a working example, see this Ember Twiddle.