Skip to content

Commit

Permalink
Merge pull request #275 from fivetanley/fix-deprecations
Browse files Browse the repository at this point in the history
Fix deprecations
  • Loading branch information
broerse committed Aug 30, 2019
2 parents 871f08c + f8f74a2 commit aefb735
Show file tree
Hide file tree
Showing 7 changed files with 283 additions and 42 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ language: node_js
node_js:
# we recommend testing addons with the same minimum supported node version as Ember CLI
# so that your addon works for all apps
- "4"
- "6"

sudo: required
dist: trusty
Expand Down
15 changes: 12 additions & 3 deletions addon/components/page-numbers.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import Util from 'ember-cli-pagination/util';
import PageItems from 'ember-cli-pagination/lib/page-items';
import Validate from 'ember-cli-pagination/validate';
import layout from '../templates/components/page-numbers';
import { get } from '@ember/object';

export default Ember.Component.extend({
layout,
Expand All @@ -15,11 +16,19 @@ export default Ember.Component.extend({
const c = this.get('content');
if (c && c.on) {
c.on('invalidPage', (e) => {
this.sendAction('invalidPageAction',e);
this._runAction('invalidPageAction', e);
});
}
}),

// only run if a closure action has been passed
_runAction(key, ...args) {
const action = get(this, key);
if (typeof action === 'function') {
action(...args);
}
},

truncatePages: true,
numPagesToShow: 10,

Expand Down Expand Up @@ -66,7 +75,7 @@ export default Ember.Component.extend({
pageClicked: function(number) {
Util.log("PageNumbers#pageClicked number " + number);
this.set("currentPage", number);
this.sendAction('action',number);
this._runAction('action', number);
},
incrementPage: function(num) {
const currentPage = Number(this.get("currentPage")),
Expand All @@ -77,7 +86,7 @@ export default Ember.Component.extend({
this.incrementProperty('currentPage', num);

const newPage = this.get('currentPage');
this.sendAction('action',newPage);
this._runAction('action', newPage);
}
}
});
6 changes: 3 additions & 3 deletions addon/remote/controller-mixin.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ import Ember from 'ember';
export default Ember.Mixin.create({
queryParams: ["page", "perPage"],

page: Ember.computed.alias("content.page"),
page: Ember.computed.alias("model.page"),

totalPages: Ember.computed.alias("content.totalPages"),
totalPages: Ember.computed.alias("model.totalPages"),

pagedContent: Ember.computed.alias("content")
pagedContent: Ember.computed.alias("model")
});
6 changes: 4 additions & 2 deletions addon/remote/route-mixin.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import Ember from 'ember';
import PagedRemoteArray from './paged-remote-array';
import Util from '../util';
import { camelize } from '@ember/string';
import { singularize } from 'ember-inflector';

export default Ember.Mixin.create({
perPage: 10,
Expand All @@ -11,8 +13,8 @@ export default Ember.Mixin.create({
},

_findModelName: function(routeName) {
return Ember.String.singularize(
Ember.String.camelize(routeName)
return singularize(
camelize(routeName)
);
},

Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@
"dependencies": {
"ember-cli-babel": "^6.8.2",
"ember-cli-htmlbars": "^2.0.3",
"ember-cli-version-checker": "^2.1.0"
"ember-cli-version-checker": "^2.1.0",
"ember-inflector": "^3.0.1"
},
"devDependencies": {
"active-model-adapter": "2.0.3",
Expand Down
50 changes: 19 additions & 31 deletions tests/unit/components/page-numbers-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -125,8 +125,6 @@ paramTest("truncation with showFL = true", {content: {page: 2, totalPages: 10},
assert.deepEqual(pages,[1,2,3,4,5,6,10]);
});



paramTest("pageClicked sends default event", {content: makePagedArray([1,2,3,4,5])}, function(s,assert) {
var actionCounter = 0;
var clickedPage = null;
Expand All @@ -136,17 +134,13 @@ paramTest("pageClicked sends default event", {content: makePagedArray([1,2,3,4,5
clickedPage = n;
}
};

s.set('targetObject',containingObject);
s.set('action','doThing');

assert.equal(s.get('totalPages'),3);
s.set('action', (arg) => containingObject.doThing(arg));
Ember.run(function() {
s.send('pageClicked',2);
s.send('pageClicked', 2);
});
assert.equal(s.get('currentPage'),2);
assert.equal(actionCounter,1);
assert.equal(clickedPage,2);
assert.equal(s.get('currentPage'), 2);
assert.equal(actionCounter, 1, 'works with function/action');
assert.equal(clickedPage, 2, 'works with function/action');
});

paramTest("incrementPage sends default event", {content: makePagedArray([1,2,3,4,5])}, function(s,assert) {
Expand All @@ -159,16 +153,15 @@ paramTest("incrementPage sends default event", {content: makePagedArray([1,2,3,4
}
};

s.set('targetObject',containingObject);
s.set('action','doThing');

assert.equal(s.get('totalPages'),3);
s.set('targetObject', containingObject);
s.set('action', (arg) => containingObject.doThing(arg));
assert.equal(s.get('totalPages'), 3);
Ember.run(function() {
s.send('incrementPage',1);
s.send('incrementPage', 1);
});
assert.equal(s.get('currentPage'),2);
assert.equal(actionCounter,1);
assert.equal(clickedPage,2);
assert.equal(s.get('currentPage'), 2);
assert.equal(actionCounter, 1);
assert.equal(clickedPage, 2);
});

paramTest("invalid incrementPage does not send default event", {content: makePagedArray([1,2,3,4,5])}, function(s,assert) {
Expand All @@ -179,15 +172,12 @@ paramTest("invalid incrementPage does not send default event", {content: makePag
}
};

s.set('targetObject',containingObject);
s.set('action','doThing');

assert.equal(s.get('totalPages'),3);
s.set('action', () => containingObject.doThing());
Ember.run(function() {
s.send('incrementPage',-1);
});
assert.equal(s.get('currentPage'),1);
assert.equal(actionCounter,0);
assert.equal(actionCounter,0)
});

paramTest("invalid page send invalidPage component action", {content: makePagedArray([1,2,3,4,5])}, function(s,assert) {
Expand All @@ -200,15 +190,13 @@ paramTest("invalid page send invalidPage component action", {content: makePagedA
}
};

s.set('targetObject',containingObject);
s.set('invalidPageAction','doThing');

assert.equal(s.get('totalPages'),3);
s.set('invalidPageAction', (arg) => containingObject.doThing(arg));
Ember.run(function() {
s.get('content').set('page',99);
s.get('content').set('page', 99);
});
assert.equal(pageEvent.page,99);
assert.equal(actionCounter,1);
assert.equal(pageEvent.page, 99);
assert.equal(actionCounter, 1);
assert.equal(s.get('totalPages'), 3);
});
/*
*/

0 comments on commit aefb735

Please sign in to comment.