简体   繁体   English

如何在运行时检测余烬应用程序

[英]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 . 我正在尝试寻找一种比搜索ember-applicationwindow.ember更好的检测ember应用ember-application

Any ideas? 有任何想法吗?

Unfortunately, there's no guaranteed way to detect Ember or an Ember Application. 不幸的是,没有保证的方法来检测Ember或Ember应用程序。 Javascript is fairly malleable, so you could have either on a page and not know where. Javascript具有很好的延展性,因此您可能只在页面上就不知道在哪里。

To detect Ember, just check for window.Ember . 要检测Ember,只需检查window.Ember Nothing fancy here, it's pretty much the only way to know (until Ember is no longer global that is). 这里没什么好想的,这几乎是唯一知道的方法(直到Ember不再是全球性的)。 I would say this works in most scenarios (both Ember global and Ember CLI apps). 我想说这适用于大多数情况(Ember全局和Ember CLI应用程序)。

Detecting an Ember application is much more difficult. 检测Ember应用程序要困难得多。 The last time I checked, the Ember Inspector does this by checking every property on the window object using Ember.Application.detectInstance() . 我上次检查时,Ember Inspector通过使用Ember.Application.detectInstance()检查window对象上的每个属性来执行此操作。 However, given the gaining popularity of Ember CLI, that will no longer work much of the time. 但是,鉴于Ember CLI的日益普及,它将在很多时间不再起作用。 Maybe you could override Ember.Application.create() and keep track of the instances? 也许您可以重写Ember.Application.create()并跟踪实例?

In any case, I certainly wouldn't rely on being able to do either of these. 无论如何,我当然不会依赖于能够做到这两个方面。 It's simply not feasible. 这根本不可行。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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