简体   繁体   中英

How do I detect an ember application at runtime

I'm trying to find a better way of detecting an ember application than searching for ember-application or window.ember .

Any ideas?

Unfortunately, there's no guaranteed way to detect Ember or an Ember Application. Javascript is fairly malleable, so you could have either on a page and not know where.

To detect Ember, just check for window.Ember . Nothing fancy here, it's pretty much the only way to know (until Ember is no longer global that is). I would say this works in most scenarios (both Ember global and Ember CLI apps).

Detecting an Ember application is much more difficult. The last time I checked, the Ember Inspector does this by checking every property on the window object using Ember.Application.detectInstance() . However, given the gaining popularity of Ember CLI, that will no longer work much of the time. Maybe you could override Ember.Application.create() and keep track of the instances?

In any case, I certainly wouldn't rely on being able to do either of these. It's simply not feasible.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM