From 294faa0f3d50c838ff6723d3a1b70505d6b960a0 Mon Sep 17 00:00:00 2001 From: Michael Villander Date: Sun, 13 Jan 2019 12:01:02 -0200 Subject: [PATCH 01/11] Makes resetLoadedAssetState log less noisy --- addon-test-support/loaded-asset-state.js | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/addon-test-support/loaded-asset-state.js b/addon-test-support/loaded-asset-state.js index bc32fc8..b486d1e 100644 --- a/addon-test-support/loaded-asset-state.js +++ b/addon-test-support/loaded-asset-state.js @@ -15,6 +15,21 @@ function has(array, item) { return array.indexOf(item) !== -1; } +/** + * Determines if the function already called. + * + * @return {Boolean} + */ +function canOnlyFireOnce() { + let executed = false; + return () => { + if (!executed) { + executed = true; + } + return executed; + }; +} + /** * Removes a DOM Node from the document. * @@ -111,7 +126,9 @@ export function cacheLoadedAssetState() { * @return {Void} */ export function resetLoadedAssetState() { - Ember.Logger.info('Resetting loaded asset state. This will attempt to restore the state of loaded assets to the last cached value. If an asset modified some global state, we cannot guarantee it will be reset. For more information see: https://github.com/trentmwillis/ember-asset-loader#resetting-test-state'); + if (canOnlyFireOnce()) { + Ember.Logger.info('Resetting loaded asset state. This will attempt to restore the state of loaded assets to the last cached value. If an asset modified some global state, we cannot guarantee it will be reset. For more information see: https://github.com/trentmwillis/ember-asset-loader#resetting-test-state'); + } const { requireEntries: currentRequireEntries, From e18445e5a0ac3e34b68bfe98bddbc3134d629183 Mon Sep 17 00:00:00 2001 From: Michael Villander Date: Sun, 13 Jan 2019 12:13:39 -0200 Subject: [PATCH 02/11] Fix once function --- addon-test-support/loaded-asset-state.js | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/addon-test-support/loaded-asset-state.js b/addon-test-support/loaded-asset-state.js index b486d1e..a36b788 100644 --- a/addon-test-support/loaded-asset-state.js +++ b/addon-test-support/loaded-asset-state.js @@ -16,17 +16,19 @@ function has(array, item) { } /** - * Determines if the function already called. + * Returns a function which you only want to run once * * @return {Boolean} */ -function canOnlyFireOnce() { - let executed = false; - return () => { - if (!executed) { - executed = true; +function once(fn, context) { + var result; + + return function () { + if (fn) { + result = fn.apply(context || this, arguments); + fn = null; } - return executed; + return result; }; } @@ -126,9 +128,10 @@ export function cacheLoadedAssetState() { * @return {Void} */ export function resetLoadedAssetState() { - if (canOnlyFireOnce()) { + const canOnlyLogOnce = once(() => { Ember.Logger.info('Resetting loaded asset state. This will attempt to restore the state of loaded assets to the last cached value. If an asset modified some global state, we cannot guarantee it will be reset. For more information see: https://github.com/trentmwillis/ember-asset-loader#resetting-test-state'); - } + }); + canOnlyLogOnce(); const { requireEntries: currentRequireEntries, From fc8105d1c46214f2289c765f2681170da20d70b3 Mon Sep 17 00:00:00 2001 From: Michael Villander Date: Sun, 13 Jan 2019 12:15:30 -0200 Subject: [PATCH 03/11] Fix ES6 sintax --- addon-test-support/loaded-asset-state.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/addon-test-support/loaded-asset-state.js b/addon-test-support/loaded-asset-state.js index a36b788..60f2be7 100644 --- a/addon-test-support/loaded-asset-state.js +++ b/addon-test-support/loaded-asset-state.js @@ -21,9 +21,9 @@ function has(array, item) { * @return {Boolean} */ function once(fn, context) { - var result; + let result; - return function () { + return () => { if (fn) { result = fn.apply(context || this, arguments); fn = null; From e8ae1e7b992da954a3e89da495a4af2c1b30171f Mon Sep 17 00:00:00 2001 From: Michael Villander Date: Sun, 13 Jan 2019 12:24:08 -0200 Subject: [PATCH 04/11] fix jsdoc --- addon-test-support/loaded-asset-state.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/addon-test-support/loaded-asset-state.js b/addon-test-support/loaded-asset-state.js index 60f2be7..16d2b41 100644 --- a/addon-test-support/loaded-asset-state.js +++ b/addon-test-support/loaded-asset-state.js @@ -17,8 +17,9 @@ function has(array, item) { /** * Returns a function which you only want to run once - * - * @return {Boolean} + * @param {Function} fn + * @param {Any} context + * @return {Function|null} */ function once(fn, context) { let result; From 796e2a06253eb12f943badb004f1da113a5de414 Mon Sep 17 00:00:00 2001 From: Michael Villander Date: Sun, 13 Jan 2019 12:01:02 -0200 Subject: [PATCH 05/11] Makes resetLoadedAssetState log less noisy --- addon-test-support/loaded-asset-state.js | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/addon-test-support/loaded-asset-state.js b/addon-test-support/loaded-asset-state.js index 4ef64ea..4d0d2ff 100644 --- a/addon-test-support/loaded-asset-state.js +++ b/addon-test-support/loaded-asset-state.js @@ -15,6 +15,21 @@ function has(array, item) { return array.indexOf(item) !== -1; } +/** + * Determines if the function already called. + * + * @return {Boolean} + */ +function canOnlyFireOnce() { + let executed = false; + return () => { + if (!executed) { + executed = true; + } + return executed; + }; +} + /** * Removes a DOM Node from the document. * @@ -111,7 +126,9 @@ export function cacheLoadedAssetState() { * @return {Void} */ export function resetLoadedAssetState() { - Ember.Logger.info('Resetting loaded asset state. This will attempt to restore the state of loaded assets to the last cached value. If an asset modified some global state, we cannot guarantee it will be reset. For more information see: https://github.com/trentmwillis/ember-asset-loader#resetting-test-state'); + if (canOnlyFireOnce()) { + Ember.Logger.info('Resetting loaded asset state. This will attempt to restore the state of loaded assets to the last cached value. If an asset modified some global state, we cannot guarantee it will be reset. For more information see: https://github.com/trentmwillis/ember-asset-loader#resetting-test-state'); + } const { requireEntries: currentRequireEntries, From ea96e1373ef3289c14d7cc6e91044d6af4ea421d Mon Sep 17 00:00:00 2001 From: Michael Villander Date: Sun, 13 Jan 2019 12:13:39 -0200 Subject: [PATCH 06/11] Fix once function --- addon-test-support/loaded-asset-state.js | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/addon-test-support/loaded-asset-state.js b/addon-test-support/loaded-asset-state.js index 4d0d2ff..e3ed6bf 100644 --- a/addon-test-support/loaded-asset-state.js +++ b/addon-test-support/loaded-asset-state.js @@ -16,17 +16,19 @@ function has(array, item) { } /** - * Determines if the function already called. + * Returns a function which you only want to run once * * @return {Boolean} */ -function canOnlyFireOnce() { - let executed = false; - return () => { - if (!executed) { - executed = true; +function once(fn, context) { + var result; + + return function () { + if (fn) { + result = fn.apply(context || this, arguments); + fn = null; } - return executed; + return result; }; } @@ -126,9 +128,10 @@ export function cacheLoadedAssetState() { * @return {Void} */ export function resetLoadedAssetState() { - if (canOnlyFireOnce()) { + const canOnlyLogOnce = once(() => { Ember.Logger.info('Resetting loaded asset state. This will attempt to restore the state of loaded assets to the last cached value. If an asset modified some global state, we cannot guarantee it will be reset. For more information see: https://github.com/trentmwillis/ember-asset-loader#resetting-test-state'); - } + }); + canOnlyLogOnce(); const { requireEntries: currentRequireEntries, From 4d421a61c6fa92efb62634517aafe230f9350eca Mon Sep 17 00:00:00 2001 From: Michael Villander Date: Sun, 13 Jan 2019 12:15:30 -0200 Subject: [PATCH 07/11] Fix ES6 sintax --- addon-test-support/loaded-asset-state.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/addon-test-support/loaded-asset-state.js b/addon-test-support/loaded-asset-state.js index e3ed6bf..999d394 100644 --- a/addon-test-support/loaded-asset-state.js +++ b/addon-test-support/loaded-asset-state.js @@ -21,9 +21,9 @@ function has(array, item) { * @return {Boolean} */ function once(fn, context) { - var result; + let result; - return function () { + return () => { if (fn) { result = fn.apply(context || this, arguments); fn = null; From 786346289f3a673e1f25f44df12dfcbc1dab5735 Mon Sep 17 00:00:00 2001 From: Michael Villander Date: Sun, 13 Jan 2019 12:24:08 -0200 Subject: [PATCH 08/11] fix jsdoc --- addon-test-support/loaded-asset-state.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/addon-test-support/loaded-asset-state.js b/addon-test-support/loaded-asset-state.js index 999d394..f325564 100644 --- a/addon-test-support/loaded-asset-state.js +++ b/addon-test-support/loaded-asset-state.js @@ -17,8 +17,9 @@ function has(array, item) { /** * Returns a function which you only want to run once - * - * @return {Boolean} + * @param {Function} fn + * @param {Any} context + * @return {Function|null} */ function once(fn, context) { let result; From ec4e296c5af3a8f40012a7fffe942c1fdc23d923 Mon Sep 17 00:00:00 2001 From: Michael Villander Date: Mon, 8 Apr 2019 13:05:19 -0300 Subject: [PATCH 09/11] removes needless warning --- addon-test-support/loaded-asset-state.js | 23 ----------------------- 1 file changed, 23 deletions(-) diff --git a/addon-test-support/loaded-asset-state.js b/addon-test-support/loaded-asset-state.js index f325564..1dd9d1a 100644 --- a/addon-test-support/loaded-asset-state.js +++ b/addon-test-support/loaded-asset-state.js @@ -15,24 +15,6 @@ function has(array, item) { return array.indexOf(item) !== -1; } -/** - * Returns a function which you only want to run once - * @param {Function} fn - * @param {Any} context - * @return {Function|null} - */ -function once(fn, context) { - let result; - - return () => { - if (fn) { - result = fn.apply(context || this, arguments); - fn = null; - } - return result; - }; -} - /** * Removes a DOM Node from the document. * @@ -129,11 +111,6 @@ export function cacheLoadedAssetState() { * @return {Void} */ export function resetLoadedAssetState() { - const canOnlyLogOnce = once(() => { - Ember.Logger.info('Resetting loaded asset state. This will attempt to restore the state of loaded assets to the last cached value. If an asset modified some global state, we cannot guarantee it will be reset. For more information see: https://github.com/trentmwillis/ember-asset-loader#resetting-test-state'); - }); - canOnlyLogOnce(); - const { requireEntries: currentRequireEntries, scripts: currentScriptTags, From ee7b6337538ea5a3f65b84f3037686d3373d990f Mon Sep 17 00:00:00 2001 From: Michael Villander Date: Mon, 8 Apr 2019 13:23:07 -0300 Subject: [PATCH 10/11] removes needless function --- addon-test-support/loaded-asset-state.js | 18 ------------------ 1 file changed, 18 deletions(-) diff --git a/addon-test-support/loaded-asset-state.js b/addon-test-support/loaded-asset-state.js index dc03e57..1dd9d1a 100644 --- a/addon-test-support/loaded-asset-state.js +++ b/addon-test-support/loaded-asset-state.js @@ -15,24 +15,6 @@ function has(array, item) { return array.indexOf(item) !== -1; } -/** - * Returns a function which you only want to run once - * @param {Function} fn - * @param {Any} context - * @return {Function|null} - */ -function once(fn, context) { - let result; - - return () => { - if (fn) { - result = fn.apply(context || this, arguments); - fn = null; - } - return result; - }; -} - /** * Removes a DOM Node from the document. * From 511db7cd8a35d94baed6fdb3212e949f58a5c073 Mon Sep 17 00:00:00 2001 From: Michael Villander Date: Mon, 8 Apr 2019 16:21:05 -0300 Subject: [PATCH 11/11] Removes ember import --- addon-test-support/loaded-asset-state.js | 2 -- 1 file changed, 2 deletions(-) diff --git a/addon-test-support/loaded-asset-state.js b/addon-test-support/loaded-asset-state.js index 1dd9d1a..77cc712 100644 --- a/addon-test-support/loaded-asset-state.js +++ b/addon-test-support/loaded-asset-state.js @@ -1,5 +1,3 @@ -import Ember from 'ember'; - let cachedRequireEntries; let cachedScriptTags; let cachedLinkTags;