Adding route-idle helper
MODIFY
.eslintrc.js
.eslintrc.js
module.exports = {
root: true,
+ parser: 'babel-eslint',
parserOptions: {
ecmaVersion: 2017,
sourceType: 'module',

ADD
addon/helpers/route-idle.js
+import Helper from '@ember/component/helper';
+import { whenRouteIdle } from '../scheduler';
+
+export default class RouteIdle extends Helper {
+ isIdle = false;
+
+ compute() {
+ if (this.isIdle) {
+ return true;
+ }
+
+ whenRouteIdle().then(() => {
+ this.isIdle = true;
+ this.recompute();
+ });
+
+ return false;
+ }
+}

ADD
app/helpers/route-idle.js
+export { default, routeIdle } from 'ember-app-scheduler/helpers/route-idle';

MODIFY
package.json
package.json
"@types/ember-test-helpers": "^1.0.3",
"@types/ember-testing-helpers": "^0.0.4",
"@types/ember__test-helpers": "^0.7.5",
+ "babel-eslint": "^10.0.3",
"broccoli-asset-rev": "^3.0.0",
"ember-cli": "~3.18.0",
"ember-cli-addon-docs": "^0.7.0",

MODIFY
tests/dummy/app/router.js
tests/dummy/app/router.js
@@ -12,6 +12,7 @@ Router.map(function() {
this.route('how-it-works');
this.route('when-route-painted');
this.route('when-route-idle');
+ this.route('route-idle-helper');
this.route('testing');
this.route('fastboot');
});

MODIFY
tests/dummy/app/templates/docs.hbs
tests/dummy/app/templates/docs.hbs
{{nav.item "How it works" "docs.how-it-works"}}
{{nav.item "whenRoutePainted" "docs.when-route-painted"}}
{{nav.item "whenRouteIdle" "docs.when-route-idle"}}
+ {{nav.item "route-idle helper" "docs.route-idle-helper"}}
{{nav.item "Testing" "docs.testing"}}
{{nav.item "Fastboot" "docs.fastboot"}}
{{/nav.subnav}}

ADD
tests/dummy/app/templates/docs/route-idle-helper.md
+# route-idle helper
+
+The `route-idle` helper allows you to use `ember-app-scheduler`'s `whenRouteIdle` functionality directly in your template. Using this helper will allow you to add hidden content that is to be deferred until the route is considered idle.
+
+```hbs
+{{#if (route-idle)}}
+ <span id="content-to-defer">Content to only show once the route is idle</span>
+{{/if}}
+```

ADD
tests/integration/helpers/route-idle-test.js
+import { module, test } from 'qunit';
+import { setupRenderingTest } from 'ember-qunit';
+import { render, settled } from '@ember/test-helpers';
+import hbs from 'htmlbars-inline-precompile';
+import { beginTransition, endTransition } from 'ember-app-scheduler';
+
+module('Integration | Helper | route-idle', function(hooks) {
+ setupRenderingTest(hooks);
+
+ test('deferred content is visible following whenRouteIdle', async function(assert) {
+ beginTransition();
+
+ await render(hbs`
+ {{#if (route-idle)}}
+ <span id="i-exist">Idle content</span>
+ {{/if}}
+ `);
+
+ assert.dom('#i-exist').doesNotExist();
+
+ endTransition();
+
+ await settled();
+
+ assert.dom('#i-exist').exists();
+
+ await settled();
+ });
+});

MODIFY
yarn.lock
yarn.lock
dependencies:
"@babel/highlight" "^7.8.3"
+"@babel/code-frame@^7.10.1":
+ version "7.10.1"
+ resolved "https://registry.yarnpkg.com/@babel/code-frame/-/code-frame-7.10.1.tgz#d5481c5095daa1c57e16e54c6f9198443afb49ff"
+ integrity sha512-IGhtTmpjGbYzcEDOw7DcQtbQSXcG9ftmAXtWTu9V936vDye4xjjekktFAtgZsWpzTj/X01jocB46mTywm/4SZw==
+ dependencies:
+ "@babel/highlight" "^7.10.1"
+
"@babel/compat-data@^7.8.6", "@babel/compat-data@^7.9.0":
version "7.9.0"
resolved "https://registry.yarnpkg.com/@babel/compat-data/-/compat-data-7.9.0.tgz#04815556fc90b0c174abd2c0c1bb966faa036a6c"
semver "^5.4.1"
source-map "^0.5.0"
+"@babel/generator@^7.10.1":
+ version "7.10.2"
+ resolved "https://registry.yarnpkg.com/@babel/generator/-/generator-7.10.2.tgz#0fa5b5b2389db8bfdfcc3492b551ee20f5dd69a9"
+ integrity sha512-AxfBNHNu99DTMvlUPlt1h2+Hn7knPpH5ayJ8OqDWSeLld+Fi2AYBTC/IejWDM9Edcii4UzZRCsbUt0WlSDsDsA==
+ dependencies:
+ "@babel/types" "^7.10.2"
+ jsesc "^2.5.1"
+ lodash "^4.17.13"
+ source-map "^0.5.0"
+
"@babel/generator@^7.4.0":
version "7.4.0"
resolved "https://registry.yarnpkg.com/@babel/generator/-/generator-7.4.0.tgz#c230e79589ae7a729fd4631b9ded4dc220418196"
"@babel/template" "^7.1.0"
"@babel/types" "^7.0.0"
+"@babel/helper-function-name@^7.10.1":
+ version "7.10.1"
+ resolved "https://registry.yarnpkg.com/@babel/helper-function-name/-/helper-function-name-7.10.1.tgz#92bd63829bfc9215aca9d9defa85f56b539454f4"
+ integrity sha512-fcpumwhs3YyZ/ttd5Rz0xn0TpIwVkN7X0V38B9TWNfVF42KEkhkAAuPCQ3oXmtTRtiPJrmZ0TrfS0GKF0eMaRQ==
+ dependencies:
+ "@babel/helper-get-function-arity" "^7.10.1"
+ "@babel/template" "^7.10.1"
+ "@babel/types" "^7.10.1"
+
"@babel/helper-function-name@^7.8.3":
version "7.8.3"
resolved "https://registry.yarnpkg.com/@babel/helper-function-name/-/helper-function-name-7.8.3.tgz#eeeb665a01b1f11068e9fb86ad56a1cb1a824cca"
dependencies:
"@babel/types" "^7.0.0"
+"@babel/helper-get-function-arity@^7.10.1":
+ version "7.10.1"
+ resolved "https://registry.yarnpkg.com/@babel/helper-get-function-arity/-/helper-get-function-arity-7.10.1.tgz#7303390a81ba7cb59613895a192b93850e373f7d"
+ integrity sha512-F5qdXkYGOQUb0hpRaPoetF9AnsXknKjWMZ+wmsIRsp5ge5sFh4c3h1eH2pRTTuy9KKAA2+TTYomGXAtEL2fQEw==
+ dependencies:
+ "@babel/types" "^7.10.1"
+
"@babel/helper-get-function-arity@^7.8.3":
version "7.8.3"
resolved "https://registry.yarnpkg.com/@babel/helper-get-function-arity/-/helper-get-function-arity-7.8.3.tgz#b894b947bd004381ce63ea1db9f08547e920abd5"
"@babel/template" "^7.8.3"
"@babel/types" "^7.8.3"
+"@babel/helper-split-export-declaration@^7.10.1":
+ version "7.10.1"
+ resolved "https://registry.yarnpkg.com/@babel/helper-split-export-declaration/-/helper-split-export-declaration-7.10.1.tgz#c6f4be1cbc15e3a868e4c64a17d5d31d754da35f"
+ integrity sha512-UQ1LVBPrYdbchNhLwj6fetj46BcFwfS4NllJo/1aJsT+1dLTEnXJL0qHqtY7gPzF8S2fXBJamf1biAXV3X077g==
+ dependencies:
+ "@babel/types" "^7.10.1"
+
"@babel/helper-split-export-declaration@^7.4.0":
version "7.4.0"
resolved "https://registry.yarnpkg.com/@babel/helper-split-export-declaration/-/helper-split-export-declaration-7.4.0.tgz#571bfd52701f492920d63b7f735030e9a3e10b55"
dependencies:
"@babel/types" "^7.8.3"
+"@babel/helper-validator-identifier@^7.10.1":
+ version "7.10.1"
+ resolved "https://registry.yarnpkg.com/@babel/helper-validator-identifier/-/helper-validator-identifier-7.10.1.tgz#5770b0c1a826c4f53f5ede5e153163e0318e94b5"
+ integrity sha512-5vW/JXLALhczRCWP0PnFDMCJAchlBvM7f4uk/jXritBnIa6E1KmqmtrS3yn1LAnxFBypQ3eneLuXjsnfQsgILw==
+
"@babel/helper-validator-identifier@^7.9.0":
version "7.9.0"
resolved "https://registry.yarnpkg.com/@babel/helper-validator-identifier/-/helper-validator-identifier-7.9.0.tgz#ad53562a7fc29b3b9a91bbf7d10397fd146346ed"
"@babel/traverse" "^7.9.6"
"@babel/types" "^7.9.6"
+"@babel/highlight@^7.10.1":
+ version "7.10.1"
+ resolved "https://registry.yarnpkg.com/@babel/highlight/-/highlight-7.10.1.tgz#841d098ba613ba1a427a2b383d79e35552c38ae0"
+ integrity sha512-8rMof+gVP8mxYZApLF/JgNDAkdKa+aJt3ZYxF8z6+j/hpeXL7iMsKCPHa2jNMHu/qqBwzQF4OHNoYi8dMA/rYg==
+ dependencies:
+ "@babel/helper-validator-identifier" "^7.10.1"
+ chalk "^2.0.0"
+ js-tokens "^4.0.0"
+
"@babel/highlight@^7.8.3":
version "7.8.3"
resolved "https://registry.yarnpkg.com/@babel/highlight/-/highlight-7.8.3.tgz#28f173d04223eaaa59bc1d439a3836e6d1265797"
esutils "^2.0.2"
js-tokens "^4.0.0"
+"@babel/parser@^7.10.1", "@babel/parser@^7.7.0":
+ version "7.10.2"
+ resolved "https://registry.yarnpkg.com/@babel/parser/-/parser-7.10.2.tgz#871807f10442b92ff97e4783b9b54f6a0ca812d0"
+ integrity sha512-PApSXlNMJyB4JiGVhCOlzKIif+TKFTvu0aQAhnTvfP/z3vVSN6ZypH5bfUNwFXXjRQtUEBNFd2PtmCmG2Py3qQ==
+
"@babel/parser@^7.3.4", "@babel/parser@^7.5.5":
version "7.5.5"
resolved "https://registry.yarnpkg.com/@babel/parser/-/parser-7.5.5.tgz#02f077ac8817d3df4a832ef59de67565e71cca4b"
"@babel/parser" "^7.4.0"
"@babel/types" "^7.4.0"
+"@babel/template@^7.10.1":
+ version "7.10.1"
+ resolved "https://registry.yarnpkg.com/@babel/template/-/template-7.10.1.tgz#e167154a94cb5f14b28dc58f5356d2162f539811"
+ integrity sha512-OQDg6SqvFSsc9A0ej6SKINWrpJiNonRIniYondK2ViKhB06i3c0s+76XUft71iqBEe9S1OKsHwPAjfHnuvnCig==
+ dependencies:
+ "@babel/code-frame" "^7.10.1"
+ "@babel/parser" "^7.10.1"
+ "@babel/types" "^7.10.1"
+
"@babel/template@^7.8.3":
version "7.8.3"
resolved "https://registry.yarnpkg.com/@babel/template/-/template-7.8.3.tgz#e02ad04fe262a657809327f578056ca15fd4d1b8"
globals "^11.1.0"
lodash "^4.17.11"
+"@babel/traverse@^7.7.0":
+ version "7.10.1"
+ resolved "https://registry.yarnpkg.com/@babel/traverse/-/traverse-7.10.1.tgz#bbcef3031e4152a6c0b50147f4958df54ca0dd27"
+ integrity sha512-C/cTuXeKt85K+p08jN6vMDz8vSV0vZcI0wmQ36o6mjbuo++kPMdpOYw23W2XH04dbRt9/nMEfA4W3eR21CD+TQ==
+ dependencies:
+ "@babel/code-frame" "^7.10.1"
+ "@babel/generator" "^7.10.1"
+ "@babel/helper-function-name" "^7.10.1"
+ "@babel/helper-split-export-declaration" "^7.10.1"
+ "@babel/parser" "^7.10.1"
+ "@babel/types" "^7.10.1"
+ debug "^4.1.0"
+ globals "^11.1.0"
+ lodash "^4.17.13"
+
"@babel/traverse@^7.8.3":
version "7.8.4"
resolved "https://registry.yarnpkg.com/@babel/traverse/-/traverse-7.8.4.tgz#f0845822365f9d5b0e312ed3959d3f827f869e3c"
lodash "^4.17.11"
to-fast-properties "^2.0.0"
+"@babel/types@^7.10.1", "@babel/types@^7.10.2", "@babel/types@^7.7.0":
+ version "7.10.2"
+ resolved "https://registry.yarnpkg.com/@babel/types/-/types-7.10.2.tgz#30283be31cad0dbf6fb00bd40641ca0ea675172d"
+ integrity sha512-AD3AwWBSz0AWF0AkCN9VPiWrvldXq+/e3cHa4J89vo4ymjz1XwrBFFVZmkJTsQIPNk+ZVomPSXUJqq8yyjZsng==
+ dependencies:
+ "@babel/helper-validator-identifier" "^7.10.1"
+ lodash "^4.17.13"
+ to-fast-properties "^2.0.0"
+
"@babel/types@^7.3.2", "@babel/types@^7.3.4", "@babel/types@^7.5.5":
version "7.5.5"
resolved "https://registry.yarnpkg.com/@babel/types/-/types-7.5.5.tgz#97b9f728e182785909aa4ab56264f090a028d18a"
@@ -2907,6 +2999,18 @@ babel-core@^6.24.1, babel-core@^6.26.0, babel-core@^6.26.3:
slash "^1.0.0"
source-map "^0.5.7"
+babel-eslint@^10.0.3:
+ version "10.1.0"
+ resolved "https://registry.yarnpkg.com/babel-eslint/-/babel-eslint-10.1.0.tgz#6968e568a910b78fb3779cdd8b6ac2f479943232"
+ integrity sha512-ifWaTHQ0ce+448CYop8AdrQiBsGrnC+bMgfyKFdi6EsPLTAWG+QfyDeM6OH+FmWnKvEq5NnBMLvlBUPKQZoDSg==
+ dependencies:
+ "@babel/code-frame" "^7.0.0"
+ "@babel/parser" "^7.7.0"
+ "@babel/traverse" "^7.7.0"
+ "@babel/types" "^7.7.0"
+ eslint-visitor-keys "^1.0.0"
+ resolve "^1.12.0"
+
babel-generator@^6.26.0:
version "6.26.1"
resolved "https://registry.yarnpkg.com/babel-generator/-/babel-generator-6.26.1.tgz#1844408d3b8f0d35a404ea7ac180f087a601bd90"
@@ -6310,9 +6414,11 @@ ember-angle-bracket-invocation-polyfill@^2.0.2:
ember-app-scheduler@^1.0.5:
version "0.0.0"
+ uid ""
"ember-app-scheduler@link:./":
version "0.0.0"
+ uid ""
ember-assign-polyfill@^2.5.0, ember-assign-polyfill@^2.6.0:
version "2.6.0"
@@ -7817,7 +7923,7 @@ eslint-utils@^2.0.0:
dependencies:
eslint-visitor-keys "^1.1.0"
-eslint-visitor-keys@^1.1.0, eslint-visitor-keys@^1.2.0:
+eslint-visitor-keys@^1.0.0, eslint-visitor-keys@^1.1.0, eslint-visitor-keys@^1.2.0:
version "1.2.0"
resolved "https://registry.yarnpkg.com/eslint-visitor-keys/-/eslint-visitor-keys-1.2.0.tgz#74415ac884874495f78ec2a97349525344c981fa"
integrity sha512-WFb4ihckKil6hu3Dp798xdzSfddwKKU3+nGniKF6HfeW6OLd2OUDEPP7TcHtB5+QXOKg2s6B2DaMPE1Nn/kxKQ==

Adding route-idle helper (#728)