Skip to content

Commit

Permalink
repro of issue machty#273.
Browse files Browse the repository at this point in the history
  • Loading branch information
jasonmit committed Jan 29, 2019
1 parent 293353e commit 65e7b1c
Show file tree
Hide file tree
Showing 7 changed files with 2,243 additions and 747 deletions.
9 changes: 2 additions & 7 deletions .ember-cli
@@ -1,9 +1,4 @@
{
/**
Ember CLI sends analytics information by default. The data is completely
anonymous, but there are times when you might want to disable this behavior.

Setting `disableAnalytics` to true will prevent any data from being sent.
*/
"disableAnalytics": false
"disableAnalytics": false,
"open-browser-uri": "http://localhost:4200/docs/examples/autocomplete"
}
10 changes: 1 addition & 9 deletions ember-cli-build.js
@@ -1,7 +1,6 @@
'use strict';

const EmberAddon = require('ember-cli/lib/broccoli/ember-addon');
const urls = require('./lib/prember-urls');

module.exports = function(defaults) {
var includePolyfill = process.env.EMBER_ENV === 'production' || process.env.CI;
Expand All @@ -17,21 +16,14 @@ module.exports = function(defaults) {
minifyJS: {
enabled: false
},

snippetPaths: ['tests/dummy/snippets'],
snippetSearchPaths: ['app', 'tests/dummy/app', 'addon'],

emberCliFontAwesome: {
useScss: true
},

babel: babelOptions,

prember: {
urls,
// GitHub Pages uses this filename to serve 404s
emptyFile: '404.html'
}
// babel: babelOptions
});

/*
Expand Down
24 changes: 11 additions & 13 deletions package.json
Expand Up @@ -24,19 +24,17 @@
"documentation": "^3.0.4",
"ember-ajax": "3.0.0",
"ember-cli": "~3.1.2",
"ember-cli-app-version": "^1.0.0",
"ember-cli-app-version": "^3.2.0",
"ember-cli-dependency-checker": "^2.0.0",
"ember-cli-deploy": "^1.0.2",
"ember-cli-deploy-build": "^1.1.1",
"ember-cli-deploy-git": "^1.3.3",
"ember-cli-eslint": "^4.2.1",
"ember-cli-fastboot": "^2.0.0",
"ember-cli-fastclick": "1.4.1",
"ember-cli-fastclick": "1.5.0",
"ember-cli-github-pages": "0.0.6",
"ember-cli-htmlbars": "^2.0.1",
"ember-cli-htmlbars-inline-precompile": "^1.0.0",
"ember-cli-inject-live-reload": "^1.4.1",
"ember-qunit": "^4.1.2",
"ember-cli-release": "1.0.0-beta.2",
"ember-cli-sass": "^7.1.3",
"ember-cli-shims": "^1.2.0",
Expand All @@ -47,17 +45,18 @@
"ember-export-application-global": "^2.0.0",
"ember-load-initializers": "^1.0.0",
"ember-maybe-import-regenerator": "^0.1.6",
"ember-notify": "~5.2.1",
"ember-notify": "~5.3.0",
"ember-open-browser": "^1.0.0",
"ember-qunit": "^4.1.2",
"ember-resolver": "^4.0.0",
"ember-sinon": "^2.1.0",
"ember-source": "~3.6.0",
"ember-source": "~3.7.2",
"ember-source-channel-url": "^1.0.1",
"ember-try": "^1.1.0",
"jsdom": "^11.6.2",
"eslint-plugin-node": "^6.0.1",
"eslint-plugin-ember": "^5.1.0",
"loader.js": "^4.2.3",
"prember": "0.3.0-alpha.3"
"eslint-plugin-node": "^6.0.1",
"jsdom": "^11.6.2",
"loader.js": "^4.2.3"
},
"keywords": [
"ember-addon",
Expand All @@ -68,9 +67,8 @@
"cancelation"
],
"dependencies": {
"babel-core": "^6.24.1",
"ember-cli-babel": "^6.8.2",
"ember-maybe-import-regenerator": "^0.1.5"
"ember-cli-babel": "^7.4.0",
"ember-maybe-import-regenerator": "^0.1.6"
},
"resolutions": {
"ember-qunit/@ember/test-helpers": "1.0.1"
Expand Down
10 changes: 6 additions & 4 deletions tests/dummy/app/application/route.js
Expand Up @@ -5,11 +5,13 @@ import Ember from 'ember';
export default Route.extend({
fastboot: inject(),

beforeModel() {
if (!Ember.testing && !this.get('fastboot.isFastBoot')) {
this.router.on('didTransition', () => {
actions: {
didTransition() {
if (!Ember.testing && !this.get('fastboot.isFastBoot')) {
window.scrollTo(0,0);
});
}

return true;
}
}
});
53 changes: 20 additions & 33 deletions tests/dummy/app/docs/examples/autocomplete/controller.js
@@ -1,47 +1,34 @@
import $ from 'jquery';
import { isBlank } from '@ember/utils';
import Controller from '@ember/controller';
import { task, timeout } from 'ember-concurrency';
import { readOnly } from '@ember/object/computed';
import { task } from 'ember-concurrency';
import { computed } from '@ember/object';

// BEGIN-SNIPPET debounced-search-with-cancelation
const DEBOUNCE_MS = 250;
export default Controller.extend({
lastSuccessful: readOnly('searchRepo.lastSuccessful.value'),

// // Uncomment this block and bug will not be present
// lastSuccessful: computed('searchRepo.lastSuccessful.value', function() {
// return this.get('searchRepo.lastSuccessful.value');
// }).readOnly(),

hasResults: computed('lastSuccessful', 'searchRepo.isRunning', function() {
// accessing a prop triggers the bug (happens with isIdle as well)
this.get('searchRepo.isRunning');

return this.get('lastSuccessful.length') > 0;
}),

searchRepo: task(function * (term) {
if (isBlank(term)) { return []; }

// Pause here for DEBOUNCE_MS milliseconds. Because this
// task is `restartable`, if the user starts typing again,
// the current search will be canceled at this point and
// start over from the beginning. This is the
// ember-concurrency way of debouncing a task.
yield timeout(DEBOUNCE_MS);

let url = `https://api.github.com/search/repositories?q=${term}`;
let res = yield fetch(url);
let json = yield res.json();

// We yield an AJAX request and wait for it to complete. If the task
// is restarted before this request completes, the XHR request
// is aborted (open the inspector and see for yourself :)
let json = yield this.get('getJSON').perform(url);
return json.items.slice(0, 10);
}).restartable(),

getJSON: task(function * (url) {
let xhr;
try {
xhr = $.getJSON(url);
let result = yield xhr.promise();
return result;

// NOTE: could also write this as
// return yield xhr;
//
// either way, the important thing is to yield before returning
// so that the `finally` block doesn't run until after the
// promise resolves (or the task is canceled).
} finally {
xhr.abort();
}
}),
})
});
// END-SNIPPET

10 changes: 5 additions & 5 deletions tests/dummy/app/docs/examples/autocomplete/template.hbs
Expand Up @@ -32,15 +32,15 @@

<p>
{{! BEGIN-SNIPPET debounced-search-with-cancelation-template }}
<input type="text" oninput={{perform searchRepo value="target.value"}}
<input type="text" oninput={{action (perform searchRepo) value="target.value"}}
placeholder="Search GitHub..." />

{{#if searchRepo.isRunning}}
{{loading-spinner}}
{{/if}}
<div>Has Results:</div>
<div>{{hasResults}}</div>

<div>Results (bug - nothing will appear):</div>
<ul>
{{#each searchRepo.lastSuccessful.value as |repo|}}
{{#each lastSuccessful as |repo|}}
<li>{{repo.full_name}}</li>
{{/each}}
</ul>
Expand Down

0 comments on commit 65e7b1c

Please sign in to comment.