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

Address ember 3 deprecations #88

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
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
9 changes: 3 additions & 6 deletions addon/-private/parachute-event.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
import { A as emberArray } from '@ember/array';
import Ember from 'ember';
import QueryParams from '../query-params';

const { canInvoke } = Ember;
import { canInvoke } from '../utils/can-invoke';

const { keys } = Object;

Expand All @@ -25,7 +22,7 @@ export default class ParachuteEvent {
constructor(routeName, controller, changed = {}) {
let { queryParams, queryParamsArray } = QueryParams.metaFor(controller);
let state = QueryParams.stateFor(controller);
let changedKeys = emberArray(keys(changed));
let changedKeys = keys(changed);

/**
* The route the event was fired from
Expand Down Expand Up @@ -56,7 +53,7 @@ export default class ParachuteEvent {
/**
* Whether or not a model refresh should occur
*/
this.shouldRefresh = emberArray(keys(this.changed)).any(
this.shouldRefresh = keys(this.changed).some(
key => queryParams[key].refresh
);

Expand Down
9 changes: 3 additions & 6 deletions addon/-private/parachute-meta.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { A as emberArray } from '@ember/array';
import QueryParam from './query-param';
import { PARACHUTE_QPS } from './symbols';

Expand All @@ -23,11 +22,9 @@ export default class ParachuteMeta {
return qps;
}, {});

this.queryParamsArray = emberArray(
keys(this.queryParams).map(key => {
return this.queryParams[key];
})
);
this.queryParamsArray = keys(this.queryParams).map(key => {
return this.queryParams[key];
}) ;

this.qpMapForController = this.queryParamsArray.reduce(
(qps, { key, as, scope }) => {
Expand Down
3 changes: 1 addition & 2 deletions addon/-private/query-param.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import { get } from '@ember/object';
import { assert } from '@ember/debug';
import { isPresent } from '@ember/utils';
import Ember from 'ember';

const { canInvoke } = Ember;
import { canInvoke } from '../utils/can-invoke';

/**
* Normalized query param object.
Expand Down
7 changes: 4 additions & 3 deletions addon/decorators/query-param.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { A } from '@ember/array';
import { PARACHUTE_QPS } from 'ember-parachute/-private/symbols';
import {
addQueryParamFor,
Expand All @@ -18,8 +17,10 @@ function createDescriptor(desc, qpDefinition) {

// Remove duplicate queryParams created by the multiple mixins
if (Array.isArray(proto.queryParams)) {
const queryParams = A([...proto.queryParams]);
const parachuteQueryParams = queryParams.filterBy(PARACHUTE_QPS, true);
const queryParams = [...proto.queryParams];
const parachuteQueryParams = queryParams.filter(queryParam =>
queryParam[PARACHUTE_QPS] === true
);

// Keep the newest one
parachuteQueryParams.pop();
Expand Down
20 changes: 8 additions & 12 deletions addon/initializers/ember-parachute.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,13 @@
import Route from '@ember/routing/route';
import RSVP from 'rsvp';
import { run } from '@ember/runloop';
import { assign } from '@ember/polyfills';
import { tryInvoke } from '@ember/utils';
import { schedule } from '@ember/runloop';
import { sendEvent } from '@ember/object/events';
import Ember from 'ember';
import QueryParams from '../query-params';
import ParachuteEvent from '../-private/parachute-event';
import lookupController from '../utils/lookup-controller';
import { lookupController } from '../utils/lookup-controller';
import { canInvoke } from '../utils/can-invoke';
import { tryInvoke } from '../utils/try-invoke';

const { canInvoke } = Ember;

const { keys } = Object;
const { keys, assign } = Object;

export function initialize(/* application */) {
if (Route._didInitializeParachute) {
Expand Down Expand Up @@ -99,7 +95,7 @@ export function initialize(/* application */) {
// https://github.com/emberjs/ember.js/issues/15291
const _super = this._super.bind(this);

return RSVP.all(routeInfos.map(x => x.routePromise)).then(() =>
return Promise.all(routeInfos.map(x => x.routePromise)).then(() =>
_super(params, transition)
);
} else {
Expand All @@ -111,7 +107,7 @@ export function initialize(/* application */) {

const _super = this._super.bind(this);

return RSVP.all(handlerInfos.map(x => x.handlerPromise)).then(() =>
return Promise.all(handlerInfos.map(x => x.handlerPromise)).then(() =>
_super(params, transition)
);
}
Expand Down Expand Up @@ -173,7 +169,7 @@ export function initialize(/* application */) {
* @returns {void}
*/
_scheduleParachuteChangeEvent(routeName, controller, changed = {}) {
run.schedule('afterRender', this, () => {
schedule('afterRender', this, () => {
let event = new ParachuteEvent(routeName, controller, changed);

tryInvoke(controller, 'queryParamsDidChange', [event]);
Expand Down
5 changes: 2 additions & 3 deletions addon/query-params.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import Mixin from '@ember/object/mixin';
import { assign } from '@ember/polyfills';
import { assert } from '@ember/debug';
import { isPresent, isEmpty } from '@ember/utils';
import { setProperties, computed, set, get } from '@ember/object';
Expand All @@ -23,7 +22,7 @@ export default class QueryParams {
* @returns {QueryParams}
*/
constructor() {
let queryParams = assign({}, ...arguments);
let queryParams = Object.assign({}, ...arguments);

// Cleanup the queryParams object. Some keys can be passed
// as undefined via extend to nullify a QP
Expand Down Expand Up @@ -94,7 +93,7 @@ export default class QueryParams {
static lookupQueryParam(controller, urlKey) {
let { queryParamsArray } = this.metaFor(controller);

return queryParamsArray.findBy('as', urlKey);
return queryParamsArray.find(queryParam => queryParam.as === urlKey);
}

/**
Expand Down
3 changes: 3 additions & 0 deletions addon/utils/can-invoke.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export function canInvoke(obj, methodName) {
return obj != null && typeof obj[methodName] === 'function';
}
2 changes: 1 addition & 1 deletion addon/utils/lookup-controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { getOwner } from '@ember/application';
* @param {function(any): any} [ownerLookupFn=getOwner]
* @returns {Ember.Controller}
*/
export default function lookupController(route, ownerLookupFn = getOwner) {
export function lookupController(route, ownerLookupFn = getOwner) {
let controller = get(route, 'controller');

if (!controller) {
Expand Down
8 changes: 8 additions & 0 deletions addon/utils/try-invoke.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { canInvoke } from './can-invoke';

export function tryInvoke(obj, methodName, args) {
if (canInvoke(obj, methodName)) {
let method = obj[methodName];
return method.apply(obj, args);
}
}
4 changes: 2 additions & 2 deletions tests/unit/-private/meta-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,8 @@ module('Unit | Implementation | meta', function() {
];

let { queryParamsArray } = new ParachuteMeta(dummyQpMap);
assert.propEqual(queryParamsArray.objectAt(0), expectedResult[0]);
assert.propEqual(queryParamsArray.objectAt(1), expectedResult[1]);
assert.propEqual(queryParamsArray[0], expectedResult[0]);
assert.propEqual(queryParamsArray[1], expectedResult[1]);
});

test('#qpMapForController', function(assert) {
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/utils/lookup-controller-test.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import EmberController from '@ember/controller';
import lookupController from 'ember-parachute/utils/lookup-controller';
import { lookupController } from 'ember-parachute/utils/lookup-controller';
import { module, test } from 'qunit';

module('Unit | Utility | lookup controller', function() {
Expand Down
Loading