Ember 2 runtime Router.map mystery - ember.js

I have a specific case where I need to add Ember routes during the application run-time (Chrome extension).
I have access to the App.Router.map(), but the given callback does not load.
Is there an official way, or even a dirty hack, to add additional routes during the application's lifespan?
Edit 1:
It's now clear there's no 'official' way to plug into the routing service during runtime.
If just someone found a reasonable clean way in (version ~2.3)...

Related

Single callback in Router, to access previous/current url + Route information?

I've been looking around on Google and Stack Overflow for an answer to this: with Ember-cli 2.10, how can I set up a single callback in the Router, which gives me information about the previous and current URL, as well as the name of the Route about to be called? I'd like to pass all 3 of those to an analytics platform.
Every example I've found has either depended on deprecated Ember features, or just plain hasn't worked as expected. Love to hear an answer on this. Also happy to hear what a better design might be, given the above analytics requirements.
All your requirements will be covered in Public Router Service pull request. It includes properties currentRouteName, currentURL, location, rootURL and transitionTo method.
It's in canary build, not yet production ready. to play you need to enable this feature config/environment.js
"FEATURES": {
"ember-routing-router-service": true
}
You can just inject router service anywhere and get the properties.
router: Ember.inject.service(),
Twiddle Copied From Miguel Camba

Route without page reload on bookmark or manual URL edit

If I'm on a page in my Ember app, and edit the URL manually or use a bookmark that identifies another route within the same app, by default the page gets reloaded, losing any transient state it had, rather than just transitioning as it would have if I'd followed an Ember-controlled link within the app. Is there a built-in feature of Ember that's well integrated into its routing features which can prevent that and just transition instead?
Details:
With Ember's default routing, the URL itself changes rather than just the fragment identifier ("hash"). E.g., in the Quick Start example, if you're on http://server/scientists and want to look at the list of programmers instead, you go to http://server/programmers.
If you do that by clicking a link handled by Ember, that works within the loaded page just fine (I'm assuming Ember uses the History API under the covers to replace state without page reload). No page reload is caused.
But if you're on http://server/scientists and click a bookmark to take you to http://server/programmers (or edit the URL manually), it reloads the page, losing any transient state the page contained.
In contrast, in an app that uses fragment identifiers for routing (like Gmail), the equivalent change of (say) http://server/#scientists to http://server/#programmers does not cause page reload, even if you manually edit the address bar or use a bookmark. (Of course; it's just a change to the fragment identifier, not the actual URL.)
Is there built-in handling in Ember that's well integrated into its routing features that can make it handle that use case without reloading? Either by using a fragment identifier instead of changing the URL, or with some History API feature? (Although I can't think of a History API feature that could do it.)
In config/environment.js file, include ENV.locationType= 'hash'; by default it would be set to auto.
For more information - http://emberjs.com/api/classes/Ember.Location.html

Ember.js change route without page reload

I am planning an Ember web app which I want to operate on one page without page reloads.
However, I also want to be able to share the state of the app at any time, and therefore make use of Ember's URL-centric design.
As a total Ember noob, I am wondering if and how Ember accomplishes this (relying on routes, but without page reloads).
Any info is greatly appreciated!
I would recommend reading up on "Query Parameters" (see here) as that is the feature it sounds like you are looking for.

Proper way of implementing HATEOAS with ServiceStack

I know how mythz generally feels about HATEOAS, but let's say that I have to follow the HATEOAS principles in my REST services and add links ("self", "parent", and other possible relations) to my DTOs.
Links like "self" and "parent" contains paths to the resources and those paths are of course related to my routes.
I'm using the following project/deployment structure for my ServiceStack REST service. If that matters, I'm using ServiceStack 3.9.71.
Service Gateway Assembly:
defines my DTOs. Each DTO has a factory creating that DTO from the corresponding domain object
defines operations and their routes
Service Implementation Assembly:
uses ServiceGateway to get DTO definitions and access their factories
does whatever domain logic requires and create the corresponding DTOs through the afore mentioned factories
Service Interface Assembly:
define my REST services and
calls ServiceImplementation from ServiceStack's HttpHandler, according to REST verbs (GET, POST, ...)
WHERE would be the proper place to add link information to my DTOs?
Option1:
In my Service Gateway, when I build the DTOs themselves. It seems logical:
I know what I need to know about my domain objects and I can easily
build the links. Except that my DTOs are now all including an
additional member (Links) and building those links forces me to
explicitly provide paths/routes (i.e. hard code them). Seems to lead
to a maintenance nightmare.
Option2:
In my Service Interface assembly, where I have the request context and
I know my routes. I can encapsulate whatever my Service Implementation
returns in a meta-object containing the response and a link
collection. However, to build that link collection, I sometimes need
information available at the domain (i.e. Service Implementation)
level. The big "con" side for me is that it creates a new additional
and artificial level in all my responses. Could be seen as a way to
standardize response formats but I don't like it.
Option3:
My hope is that I can write a wrapper generically "injecting" a "Links" member to all the DTOs
I return by hooking somewhere into ServiceStack in my Service Interface assembly. I haven't
investigated much in that direction because I feel I could be wrong on
the whole approach here.
Any advise / suggestion welcome. Thanks to all.
I'm not sure If I'm suggesting you option1 or option3, but this Is what I came out after trying to do the same thing.
I started from this answer.
Now you can access route metadata directly from filters.
So my current approach is:
=> Services create the dto responses and the next collection of hypermedia links that will be attached to the response. In this level you know the "operations" by type but not "how" you will build the routes. I think it is coherent that domain level deals with workflows of operations.
=> Within a response filter I get the available routes from Metadata, and build the routes from dto properties by convention. Finally routes are added to http header.
Caveats:
I'm mapping 1 dto - 1 route. This approach could be more difficult in other cases.

How to make form data a part of the application state? (Alternative approach to managing state in an Ember Application?)

I am currently looking for a feasible approach to store form data globally in my Ember Application. The state of the form must get reflected in the URL. I have not yet seen an Ember example managing this kind of state, since routes always revolved around certain entities/models that get displayed by an Application.
Soo.. what is my Usecase?
When the user enters my app, he may modify some settings of my app in a form (e.g. location and time). I would like to have this information as part of the application state. Why? The state of the settings could be shared by the user with others users easily, as he could share the current URL of the application.
This is my current idea for an implementation:
I could store the current settings in a global location, e.g. in my router.
This enables me to access the stored settings in the methods serialize and deserialize of my main route (and potential other routes).
What's your opinion on my current idea for a solution approach? Is there maybe a appropriate Ember feature i have missed?