Skip to content

Commit

Permalink
[EMBER]: start upgrade to 2.8 and remove DS check
Browse files Browse the repository at this point in the history
  • Loading branch information
snewcomer committed Apr 17, 2017
1 parent 0cacddd commit 8e7c62e
Show file tree
Hide file tree
Showing 22 changed files with 212 additions and 158 deletions.
2 changes: 1 addition & 1 deletion .jshintrc
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,6 @@
"strict": false,
"white": false,
"eqnull": true,
"esnext": true,
"esversion": 6,
"unused": true
}
32 changes: 25 additions & 7 deletions addon/components/infinity-loader.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import Ember from 'ember';
import emberVersionIs from 'ember-version-is';

const InfinityLoaderComponent = Ember.Component.extend({
classNames: ["infinity-loader"],
Expand Down Expand Up @@ -42,6 +41,12 @@ const InfinityLoaderComponent = Ember.Component.extend({
}
},

/**
* determine how far the infinity-loader component is from the top of the
scrollable element
* @method _selfOffset
* @return {Number}
*/
_selfOffset() {
if (this.get('_customScrollableIsDefined')) {
return this.$().offset().top - this.get("_scrollable").offset().top + this.get("_scrollable").scrollTop();
Expand All @@ -50,14 +55,33 @@ const InfinityLoaderComponent = Ember.Component.extend({
}
},

/**
* total pixels where _scrollable's bottom position is from top of screen
* @method _bottomOfScrollableOffset
* @return {Number}
*/
_bottomOfScrollableOffset() {
return this.get('_scrollable').height() + this.get("_scrollable").scrollTop();
},

/**
* distance infinity loader is from top of _scrollable/window's top position
less the buffer amount specified by triggerOffset
* @method _triggerOffset
* @return {Number}
*/
_triggerOffset() {
return this._selfOffset() - this.get('triggerOffset');
},

/**
* is _scrollable's bottom position greater than the distance from the
infinity-loader component to _scrollable's top
* in other words if at top of page and _scrollable's height is 100px and
infinity loader is 200px from the top, has the scrollable traversed 101px to trigger loading more records
* @method _shouldLoadMore
* @return {Boolean}
*/
_shouldLoadMore() {
if (this.get('developmentMode') || typeof FastBoot !== 'undefined' || this.isDestroying || this.isDestroyed) {
return false;
Expand Down Expand Up @@ -103,10 +127,4 @@ const InfinityLoaderComponent = Ember.Component.extend({
})
});

if (emberVersionIs('lessThan', '1.13.0')) {
InfinityLoaderComponent.reopen({
hasBlock: Ember.computed.alias('template')
});
}

export default InfinityLoaderComponent;
16 changes: 4 additions & 12 deletions addon/mixins/route.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import Ember from 'ember';
const { Mixin, computed } = Ember;
import { emberDataVersionIs } from 'ember-version-is';
import { objectAssign } from '../utils';

/**
The Ember Infinity Route Mixin enables an application route to load paginated
Expand Down Expand Up @@ -161,10 +161,6 @@ const RouteMixin = Mixin.create({
@method _ensureCompatibility
*/
_ensureCompatibility() {
if (emberDataVersionIs('greaterThan', '1.0.0-beta.19.2') && emberDataVersionIs('lessThan', '1.13.4')) {
throw new Ember.Error("Ember Infinity: You are using an unsupported version of Ember Data. Please upgrade to at least 1.13.4 or downgrade to 1.0.0-beta.19.2");
}

if (Ember.isEmpty(this.get(this._store)) || Ember.isEmpty(this.get(this._store)[this._storeFindMethod])){
throw new Ember.Error("Ember Infinity: Store is not available to infinityModel");
}
Expand Down Expand Up @@ -202,12 +198,8 @@ const RouteMixin = Mixin.create({
@param {Object} boundParams Optional, any route properties to be included as additional params.
@return {Ember.RSVP.Promise}
*/
infinityModel(modelName, options = {}, boundParams) {
if (emberDataVersionIs('lessThan', '1.13.0')) {
this.set('_storeFindMethod', 'find');
}

options = Object.assign({}, options);
infinityModel(modelName, options, boundParams) {
options = options ? objectAssign({}, options) : {};

this.set('_infinityModelName', modelName);

Expand Down Expand Up @@ -339,7 +331,7 @@ const RouteMixin = Mixin.create({
pageParams[this.get('pageParam')] = nextPage;
}

const params = Object.assign(pageParams, this.get('_extraParams'));
const params = objectAssign(pageParams, this.get('_extraParams'));

const boundParams = this.get('_boundParams');
if (!Ember.isEmpty(boundParams)) {
Expand Down
19 changes: 19 additions & 0 deletions addon/utils.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
export let objectAssign = Object.assign || function objectAssign(target) {
'use strict';
if (target == null) {
throw new TypeError('Cannot convert undefined or null to object');
}

target = Object(target);
for (var index = 1; index < arguments.length; index++) {
var source = arguments[index];
if (source != null) {
for (var key in source) {
if (Object.prototype.hasOwnProperty.call(source, key)) {
target[key] = source[key];
}
}
}
}
return target;
};
8 changes: 3 additions & 5 deletions bower.json
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
{
"name": "ember-infinity",
"dependencies": {
"ember": "~2.4.1",
"ember-cli-shims": "0.1.0",
"ember-cli-test-loader": "0.2.2",
"ember-qunit-notifications": "0.1.0",
"ember": "~2.8.0",
"ember-cli-shims": "0.1.1",
"pretender": "^0.9.0",
"Faker": "~3.0.1",
"babel-polyfill": "~0.0.1"
"ember-cli-test-loader": "0.2.2"
}
}
2 changes: 1 addition & 1 deletion ember-cli-build.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ var EmberAddon = require('ember-cli/lib/broccoli/ember-addon');

module.exports = function(defaults) {
var app = new EmberAddon(defaults, {
// Add options here
});

/*
Expand All @@ -13,5 +12,6 @@ module.exports = function(defaults) {
This build file does *not* influence how the addon or the app using it
behave. You most likely want to be modifying `./index.js` or app's build file
*/

return app.toTree();
};
17 changes: 0 additions & 17 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,23 +1,6 @@
/* jshint node: true */
'use strict';

var checker = require('ember-cli-version-checker');

module.exports = {
name: 'ember-infinity',

init: function() {
if (this._super.init) {
this._super.init.apply(this, arguments);
}
checker.assertAbove(this, '0.2.0');
},

included: function(app) {
this.addons.forEach(function(addon){
if (addon.name === "ember-version-is") {
addon.included.apply(addon, [app]);
}
});
}
};
29 changes: 13 additions & 16 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,37 +19,34 @@
"license": "MIT",
"devDependencies": {
"broccoli-asset-rev": "^2.4.2",
"ember-cli": "2.4.0",
"ember-ajax": "2.5.6",
"ember-cli": "2.8.0",
"ember-cli-app-version": "^1.0.0",
"ember-cli-content-security-policy": "0.4.0",
"ember-cli-dependency-checker": "^1.2.0",
"ember-cli-htmlbars": "^1.0.1",
"ember-cli-htmlbars": "^1.0.3",
"ember-cli-htmlbars-inline-precompile": "^0.3.1",
"ember-cli-ic-ajax": "0.2.4",
"ember-cli-inject-live-reload": "^1.3.1",
"ember-cli-jshint": "2.0.1",
"ember-cli-inject-live-reload": "^1.4.0",
"ember-cli-jshint": "^1.0.0",
"ember-cli-pretender": "0.3.2",
"ember-cli-qunit": "^1.2.1",
"ember-cli-release": "0.2.9",
"ember-cli-sri": "^2.0.0",
"ember-cli-qunit": "~2.1.0",
"ember-cli-release": "^0.2.9",
"ember-cli-sri": "^2.1.0",
"ember-cli-uglify": "^1.2.0",
"ember-data": "^2.4.0",
"ember-data": "^2.8.0",
"ember-disable-prototype-extensions": "^1.1.0",
"ember-disable-proxy-controllers": "^1.0.1",
"ember-export-application-global": "^1.0.4",
"ember-export-application-global": "^1.0.5",
"ember-faker": "1.1.0",
"ember-load-initializers": "^0.5.0",
"ember-load-initializers": "^0.5.1",
"ember-resolver": "^2.0.3",
"ember-try": "^0.2.13",
"loader.js": "^4.0.0"
"loader.js": "^4.0.1"
},
"keywords": [
"ember-addon"
],
"dependencies": {
"ember-cli-babel": "^5.1.5",
"ember-cli-version-checker": "^1.0.2",
"ember-version-is": "0.0.3"
"ember-cli-babel": "^5.1.6"
},
"ember-addon": {
"configPath": "tests/dummy/config",
Expand Down
2 changes: 1 addition & 1 deletion tests/.jshintrc
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,6 @@
"strict": false,
"white": false,
"eqnull": true,
"esnext": true,
"esversion": 6,
"unused": true
}
32 changes: 32 additions & 0 deletions tests/acceptance/infinity-custom-store-test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import { test } from 'qunit';
import moduleForAcceptance from '../../tests/helpers/module-for-acceptance';
import buildServer from '../helpers/fake-album-server';
import assertDetails from '../helpers/assert-acceptance-details';

let server;

moduleForAcceptance('Acceptance: Infinity Route - custom store route', {
beforeEach() {
server = buildServer();
this.customStore = this.application.__container__.lookup('service:custom-store');
for (let x = 0; x <= 5; x++) {
this.customStore.push('custom-model', { id: x });
}
},
afterEach() {
server.shutdown();
delete this.customStore;
}
});

test('it works with custom store', function(assert) {
visit('/custom-store');

andThen(() => {
assertDetails(assert, {
title: 'Listing Posts',
listLength: 6,
reachedInfinity: true
});
});
});
19 changes: 8 additions & 11 deletions tests/acceptance/infinity-route-offset-trigger-test.js
Original file line number Diff line number Diff line change
@@ -1,20 +1,18 @@
import Ember from 'ember';
import { module, test } from 'qunit';
import startApp from '../helpers/start-app';
import { test } from 'qunit';
import moduleForAcceptance from '../../tests/helpers/module-for-acceptance';
import Pretender from 'pretender';
import faker from 'faker';

var App, server;
let server;

module('Acceptance: Infinity Route - offset trigger', {
setup() {
moduleForAcceptance('Acceptance: Infinity Route - offset trigger', {
beforeEach() {
var posts = [];

for (var i = 0; i < 50; i++) {
posts.push({id: i, name: faker.company.companyName()});
}

App = startApp();
server = new Pretender(function() {
this.get('/posts', function(request) {
var body, subset, perPage, startPage, offset;
Expand All @@ -39,8 +37,7 @@ module('Acceptance: Infinity Route - offset trigger', {
});
});
},
teardown() {
Ember.run(App, 'destroy');
afterEach() {
server.shutdown();
}
});
Expand Down Expand Up @@ -77,7 +74,7 @@ function infinityShouldBeReached(assert) {
}

test('it should start loading more items when the scroll is on the very bottom ' +
'when triggerOffset is not set', assert => {
'when triggerOffset is not set', function(assert) {
visit('/test-scrollable');

andThen(() => {
Expand All @@ -102,7 +99,7 @@ test('it should start loading more items when the scroll is on the very bottom '
});

test('it should start loading more items before the scroll is on the very bottom ' +
'when triggerOffset is set', assert => {
'when triggerOffset is set', function(assert) {
visit('/test-scrollable?triggerOffset=200');

andThen(() => {
Expand Down
17 changes: 7 additions & 10 deletions tests/acceptance/infinity-route-with-embedded-route-test.js
Original file line number Diff line number Diff line change
@@ -1,22 +1,19 @@
import Ember from 'ember';
import { module, test } from 'qunit';
import startApp from '../helpers/start-app';
import { test } from 'qunit';
import moduleForAcceptance from '../../tests/helpers/module-for-acceptance';
import buildServer from '../helpers/fake-album-server';

var App, server;
let server;

module('Acceptance: Infinity Route', {
setup() {
App = startApp();
moduleForAcceptance('Acceptance: Infinity Route', {
beforeEach() {
server = buildServer();
},
teardown() {
Ember.run(App, 'destroy');
afterEach() {
server.shutdown();
}
});

test('it works when embedded route is refreshed', assert => {
test('it works when embedded route is refreshed', function(assert) {
visit('/posts/1');
click('button.refreshRoute');

Expand Down
Loading

0 comments on commit 8e7c62e

Please sign in to comment.