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

Avoid infinite render on value change #524

Merged
merged 3 commits into from
Aug 31, 2017
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
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