Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

remove unnecessary mentions of RSVP #546

Merged
merged 2 commits into from
Mar 1, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 6 additions & 13 deletions guides/release/routing/asynchronous-routing.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ heavy use of the concept of Promises. In short, promises are objects that
represent an eventual value. A promise can either _fulfill_
(successfully resolve the value) or _reject_ (fail to resolve the
value). The way to retrieve this eventual value, or handle the cases
when the promise rejects, is via the promise's [`then()`](https://www.emberjs.com/api/ember/release/classes/Promise/methods/then?anchor=then) method, which
when the promise rejects, is via the promise's [`then()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/then) method, which
accepts two optional callbacks, one for fulfillment and one for
rejection. If the promise fulfills, the fulfillment handler gets called
with the fulfilled value as its sole argument, and if the promise rejects,
Expand All @@ -19,13 +19,13 @@ sole argument. For example:
```javascript
let promise = fetchTheAnswer();

promise.then(fulfill, reject);
promise.then(fulfillCallback, rejectCallback);

function fulfill(answer) {
function fulfillCallback(answer) {
console.log(`The answer is ${answer}`);
}

function reject(reason) {
function rejectCallback(reason) {
console.log(`Couldn't get the answer! Reason: ${reason}`);
}
```
Expand All @@ -52,11 +52,6 @@ asynchronous form of try-catch statements that prevent the rightward
flow of nested callback after nested callback and facilitate a saner
approach to managing complex asynchronous logic in your applications.

This guide doesn't intend to fully delve into all the different ways
promises can be used, but if you'd like a more thorough introduction,
take a look at the readme for [RSVP](https://github.com/tildeio/rsvp.js),
the promise library that Ember uses.

### The Router Pauses for Promises

When transitioning between routes, the Ember router collects all of the
Expand All @@ -82,12 +77,11 @@ A basic example:

```javascript {data-filename=app/routes/tardy.js}
import Route from '@ember/routing/route';
import RSVP from 'rsvp';
import { later } from '@ember/runloop';

export default Route.extend({
model() {
return new RSVP.Promise(function(resolve) {
return new Promise(function(resolve) {
later(function() {
resolve({ msg: 'Hold Your Horses' });
}, 3000);
Expand Down Expand Up @@ -126,11 +120,10 @@ along the way, e.g.:

```javascript {data-filename=app/routes/good-for-nothing.js}
import Route from '@ember/routing/route';
import RSVP from 'rsvp';

export default Route.extend({
model() {
return RSVP.reject("FAIL");
return Promise.reject("FAIL");
},

actions: {
Expand Down
16 changes: 6 additions & 10 deletions guides/release/tutorial/autocomplete-component.md
Original file line number Diff line number Diff line change
Expand Up @@ -347,7 +347,6 @@ import { module, test } from 'qunit';
import { setupRenderingTest } from 'ember-qunit';
import { render } from '@ember/test-helpers';
import hbs from 'htmlbars-inline-precompile';
import { resolve } from 'rsvp';

const ITEMS = [{city: 'San Francisco'}, {city: 'Portland'}, {city: 'Seattle'}];
const FILTERED_ITEMS = [{city: 'San Francisco'}];
Expand All @@ -358,7 +357,7 @@ module('Integration | Component | list-filter', function(hooks) {
test('should initially load all listings', async function (assert) {
// we want our actions to return promises,
//since they are potentially fetching data asynchronously
this.set('filterByCity', () => resolve({ results: ITEMS }));
this.set('filterByCity', () => Promise.resolve({ results: ITEMS }));
});

});
Expand All @@ -371,7 +370,7 @@ Our `filterByCity` function is going to pretend to be the action function for ou
We are not testing the actual filtering of rentals in this test, since it is focused on only the capability of the component.
We will test the full logic of filtering in application tests, described in the next section.

Since our component is expecting the filter process to be asynchronous, we return promises from our filter, using [Ember's RSVP library](https://www.emberjs.com/api/ember/release/modules/rsvp).
Since our component is expecting the filter process to be asynchronous, we return promises from our filter.

Next, we'll add the call to render the component to show the cities we've provided above.

Expand All @@ -380,7 +379,6 @@ import { module, test } from 'qunit';
import { setupRenderingTest } from 'ember-qunit';
import { render } from '@ember/test-helpers';
import hbs from 'htmlbars-inline-precompile';
import { resolve } from 'rsvp';

const ITEMS = [{city: 'San Francisco'}, {city: 'Portland'}, {city: 'Seattle'}];
const FILTERED_ITEMS = [{city: 'San Francisco'}];
Expand All @@ -391,7 +389,7 @@ module('Integration | Component | list-filter', function(hooks) {
test('should initially load all listings', async function (assert) {
// we want our actions to return promises,
//since they are potentially fetching data asynchronously
this.set('filterByCity', () => resolve({ results: ITEMS }));
this.set('filterByCity', () => Promise.resolve({ results: ITEMS }));

// with an integration test,
// you can set up and use your component in the same way your application
Expand Down Expand Up @@ -428,7 +426,6 @@ import { module, test } from 'qunit';
import { setupRenderingTest } from 'ember-qunit';
import { render, settled } from '@ember/test-helpers';
import hbs from 'htmlbars-inline-precompile';
import { resolve } from 'rsvp';

const ITEMS = [{city: 'San Francisco'}, {city: 'Portland'}, {city: 'Seattle'}];
const FILTERED_ITEMS = [{city: 'San Francisco'}];
Expand All @@ -438,7 +435,7 @@ module('Integration | Component | list-filter', function(hooks) {

test('should initially load all listings', async function (assert) {
// we want our actions to return promises, since they are potentially fetching data asynchronously
this.set('filterByCity', () => resolve({ results: ITEMS }));
this.set('filterByCity', () => Promise.resolve({ results: ITEMS }));

// with an integration test,
// you can set up and use your component in the same way your application will use it.
Expand Down Expand Up @@ -477,7 +474,6 @@ import { module, test } from 'qunit';
import { setupRenderingTest } from 'ember-qunit';
import { render, settled, triggerKeyEvent, fillIn } from '@ember/test-helpers';
import hbs from 'htmlbars-inline-precompile';
import { resolve } from 'rsvp';
```

Now use it to simulate the user typing a key into the search field.
Expand All @@ -486,11 +482,11 @@ Now use it to simulate the user typing a key into the search field.
test('should update with matching listings', async function (assert) {
this.set('filterByCity', (val) => {
if (val === '') {
return resolve({
return Promise.resolve({
query: val,
results: ITEMS });
} else {
return resolve({
return Promise.resolve({
query: val,
results: FILTERED_ITEMS });
}
Expand Down
12 changes: 4 additions & 8 deletions guides/release/tutorial/service.md
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,6 @@ In our test below we are passing in our fake map utility object in the first tes
```javascript {data-filename="tests/unit/services/map-element-test.js" data-diff="+3,+5,-10,-11,-12,-13,-14,+16,+17,+18,+19,+20,+21,+22,+23,+24,+25,+26,+27,+28,+29,+30,+31,+32,+33,+34,+35,+37,+38,+39,+40,+41,+42,+43,+44,+45"}
import { module, test } from 'qunit';
import { setupTest } from 'ember-qunit';
import { resolve } from 'rsvp';

const DUMMY_ELEMENT = {};

Expand All @@ -248,7 +247,7 @@ module('Unit | Service | maps', function(hooks) {
let stubGeocodeService = {
fetchCoordinates(location) {
assert.equal(location, 'San Francisco', 'fetchCoordinates called with location');
return resolve([0, 0]);
return Promise.resolve([0, 0]);
}
}
let mapService = this.owner.factoryFor('service:map-element').create({map: stubMapService, geocode: stubGeocodeService});
Expand Down Expand Up @@ -298,14 +297,13 @@ import { module, test } from 'qunit';
import { setupRenderingTest } from 'ember-qunit';
import { render } from '@ember/test-helpers';
import hbs from 'htmlbars-inline-precompile';
import { resolve } from 'rsvp';

let StubMapsService = Service.extend({
getMapElement(location) {
this.set('calledWithLocation', location);
let element = document.createElement('div');
element.className = 'map';
return resolve(element);
return Promise.resolve(element);
}
});

Expand Down Expand Up @@ -364,11 +362,10 @@ import { render, click } from '@ember/test-helpers';
import hbs from 'htmlbars-inline-precompile';
import EmberObject from '@ember/object';
import Service from '@ember/service';
import { resolve } from 'rsvp';

let StubMapsService = Service.extend({
getMapElement() {
return resolve(document.createElement('div'));
return Promise.resolve(document.createElement('div'));
}
});

Expand Down Expand Up @@ -428,11 +425,10 @@ import {
fillIn,
triggerKeyEvent
} from '@ember/test-helpers'
import { resolve } from 'rsvp';

let StubMapsService = Service.extend({
getMapElement() {
return resolve(document.createElement('div'));
return Promise.resolve(document.createElement('div'));
}
});

Expand Down
Loading