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

fix: use legacy syntax for decorators #82

Open
wants to merge 2 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
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
- '6'
- '8'

sudo: false
dist: trusty
Expand Down
62 changes: 21 additions & 41 deletions addon/decorators/query-param.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,54 +4,34 @@ import {
addQueryParamFor,
getQueryParamsFor
} from './-private/query-params-for';
import { decoratorWithParams } from '@ember-decorators/utils/decorator';

function createDescriptor(desc, qpDefinition) {
qpDefinition = qpDefinition || {};
export const queryParam = decoratorWithParams((target, key, desc, params) => {
const qpDefinition = params ? params[0] : {};

const descriptor = {
...desc,
finisher(klass) {
addQueryParamFor(klass, desc.key, qpDefinition);
klass.reopen(getQueryParamsFor(klass).Mixin);

const proto = klass.proto();

// 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);

// Keep the newest one
parachuteQueryParams.pop();
// Remove the old ones
queryParams.removeObjects(parachuteQueryParams);

proto.queryParams = queryParams.toArray();
}
if (typeof desc.initializer === 'function') {
qpDefinition.defaultValue = desc.initializer();
}

return klass;
}
desc.initializer = function initializer() {
return qpDefinition.defaultValue;
};

if (desc.kind === 'field') {
if (typeof desc.initializer === 'function') {
qpDefinition.defaultValue = desc.initializer();
}
addQueryParamFor(target, key, qpDefinition);
target.reopen(getQueryParamsFor(target).Mixin);

descriptor.initializer = function initializer() {
return qpDefinition.defaultValue;
};
}
// Remove duplicate queryParams created by the multiple mixins
if (Array.isArray(target.queryParams)) {
const queryParams = A([...target.queryParams]);
const parachuteQueryParams = queryParams.filterBy(PARACHUTE_QPS, true);

return descriptor;
}
// Keep the newest one
parachuteQueryParams.pop();
// Remove the old ones
queryParams.removeObjects(parachuteQueryParams);

export default function queryParam(qpDefinition) {
// Handle `@queryParam` usage
if (`${qpDefinition}` === '[object Descriptor]') {
return createDescriptor(qpDefinition);
target.queryParams = queryParams.toArray();
}
});

// Handle `@queryParam()` usage
return desc => createDescriptor(desc, qpDefinition);
}
export default queryParam;
16 changes: 7 additions & 9 deletions addon/decorators/with-parachute.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
import QueryParams from '../query-params';
import { decoratorWithParams } from '@ember-decorators/utils/decorator';

export default function withParachute(desc) {
return {
...desc,
finisher(klass) {
klass.reopen(new QueryParams().Mixin);
export const withParachute = decoratorWithParams(target => {
target.reopen(new QueryParams().Mixin);

return klass;
}
};
}
return target;
});

export default withParachute;
8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,10 @@
"test:all": "ember try:each"
},
"dependencies": {
"ember-cli-babel": "^7.1.2"
"@ember-decorators/utils": "^6.1.1",
"ember-cli-babel": "^7.12.0"
},
"devDependencies": {
"@ember-decorators/babel-transforms": "^4.0.0",
"@ember/jquery": "^0.5.2",
"@ember/optional-features": "^0.6.3",
"babel-eslint": "^10.0.1",
Expand All @@ -55,7 +55,7 @@
"ember-composable-helpers": "^2.1.0",
"ember-concurrency": "^0.8.26",
"ember-concurrency-decorators": "^0.5.0",
"ember-decorators": "^4.0.0",
"ember-decorators": "^6.1.1",
"ember-disable-prototype-extensions": "^1.1.3",
"ember-export-application-global": "^2.0.0",
"ember-load-initializers": "^2.0.0",
Expand All @@ -75,7 +75,7 @@
"sass": "^1.15.3"
},
"engines": {
"node": "6.* || 8.* || >= 10.*"
"node": "8.* || >= 10.*"
},
"ember-addon": {
"configPath": "tests/dummy/config",
Expand Down
Loading