Skip to content

Commit

Permalink
fix: Avoid infinite render on value change (#524)
Browse files Browse the repository at this point in the history
  • Loading branch information
steven-ferguson authored and Tim Stirrat committed Aug 31, 2017
1 parent e0248ce commit 7fbe850
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 22 deletions.
18 changes: 4 additions & 14 deletions addon/adapters/firebase.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ import DS from 'ember-data';
import Waitable from '../mixins/waitable';
import toPromise from '../utils/to-promise';

const { assign, RSVP: { Promise } } = Ember;
const { assign, RSVP } = Ember;
const { Promise } = RSVP;

var uniq = function (arr) {
var ret = Ember.A();
Expand Down Expand Up @@ -125,26 +126,15 @@ export default DS.Adapter.extend(Waitable, {


/**
* Promise interface for once('value') that also handle test waiters.
* Promise interface for once('value').
*
* @param {Firebase} ref
* @param {String} log
* @return {Promise<DataSnapshot>}
* @private
*/
_fetch(ref, log) {
this._incrementWaiters();
return new Promise((resolve, reject) => {

ref.once('value', (snapshot) => {
this._decrementWaiters();
Ember.run(null, resolve, snapshot);
}, (err) => {
this._decrementWaiters();
Ember.run(null, reject, err);
});

}, log);
return RSVP.resolve(ref.once('value'), log);
},


Expand Down
28 changes: 28 additions & 0 deletions tests/acceptance/live-connection-test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import { expect } from 'chai';
import startApp from '../helpers/start-app';
import destroyApp from '../helpers/destroy-app';

import {
describe,
it,
beforeEach,
afterEach,
} from 'mocha';

describe('Acceptance: live firebase connection', function () {
beforeEach(function () {
this.application = startApp();
});

afterEach(function () {
destroyApp(this.application);
});

it('handles live connections in testing', function () {
visit('/posts');

andThen(function () {
expect(currentPath()).to.equal('posts.index');
});
});
});
8 changes: 0 additions & 8 deletions tests/integration/finding-records-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,10 +77,6 @@ describe('Integration: FirebaseAdapter - Finding Records', function() {
expect(findRef.toString()).to.match(/blogs\/normalized\/posts\/post_1$/g);
});

it('returns an object', function() {
expect(findPromise).to.be.an('object');
});

it('returns a promise', function() {
expect(findPromise.then).to.be.a('function');
});
Expand Down Expand Up @@ -134,10 +130,6 @@ describe('Integration: FirebaseAdapter - Finding Records', function() {
expect(findAllRef.toString()).to.match(/blogs\/normalized\/posts$/g);
});

it('returns an object', function() {
expect(findAllPromise).to.be.an('object');
});

it('returns a promise', function() {
expect(findAllPromise.then).to.be.a('function');
});
Expand Down

0 comments on commit 7fbe850

Please sign in to comment.