-
-
Save rwjblue/9291668 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Ember.runLoadHooks = function(name, object) { | |
loaded[name] = object; | |
if (typeof window === 'object' && typeof window.dispatchEvent === 'function' && typeof CustomEvent === "function") { | |
var event = new CustomEvent(name, {detail: object, name: name}); | |
window.dispatchEvent(event); | |
} | |
if (loadHooks[name]) { | |
forEach.call(loadHooks[name], function(callback) { | |
callback(object); | |
}); | |
} | |
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/packages/ember-runtime/lib/system/lazy_load.js b/packages/ember-runtime/lib/system/lazy_load.js | |
index 3e9285a..4a47a92 100644 | |
--- a/packages/ember-runtime/lib/system/lazy_load.js | |
+++ b/packages/ember-runtime/lib/system/lazy_load.js | |
@@ -1,3 +1,5 @@ | |
+/* globals CustomEvent */ | |
+ | |
var forEach = Ember.ArrayPolyfills.forEach; | |
/** | |
@@ -49,6 +51,11 @@ Ember.onLoad = function(name, callback) { | |
Ember.runLoadHooks = function(name, object) { | |
loaded[name] = object; | |
+ if (typeof window === 'object' && typeof window.dispatchEvent === 'function' && typeof CustomEvent === "function") { | |
+ var event = new CustomEvent(name, {detail: object, name: name}); | |
+ window.dispatchEvent(event); | |
+ } | |
+ | |
if (loadHooks[name]) { | |
forEach.call(loadHooks[name], function(callback) { | |
callback(object); | |
diff --git a/packages/ember-runtime/tests/system/lazy_load_test.js b/packages/ember-runtime/tests/system/lazy_load_test.js | |
index 649487f..0edd83d 100644 | |
--- a/packages/ember-runtime/tests/system/lazy_load_test.js | |
+++ b/packages/ember-runtime/tests/system/lazy_load_test.js | |
@@ -1,3 +1,5 @@ | |
+/* globals CustomEvent */ | |
+ | |
module("Lazy Loading"); | |
test("if a load hook is registered, it is executed when runLoadHooks are exected", function() { | |
@@ -49,3 +51,18 @@ test("hooks in ENV.EMBER_LOAD_HOOKS['hookName'] get executed", function() { | |
equal(window.ENV.__test_hook_count__, 1, "the object was passed into the load hook"); | |
}); | |
+ | |
+if (typeof window === 'object' && typeof window.dispatchEvent === 'function' && typeof CustomEvent === "function") { | |
+ test("load hooks trigger a custom event", function() { | |
+ var eventObject = "super duper awesome events"; | |
+ | |
+ window.addEventListener('__test_hook_for_events__', function(e) { | |
+ ok(true, 'custom event was fired'); | |
+ equal(e.detail, eventObject, 'event details are provided properly'); | |
+ }); | |
+ | |
+ Ember.run(function() { | |
+ Ember.runLoadHooks("__test_hook_for_events__", eventObject); | |
+ }); | |
+ }); | |
+} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
e