Skip to content

Commit

Permalink
feat: Assert "Cannot pass QPs object in @models and @query at same time
Browse files Browse the repository at this point in the history
  • Loading branch information
Alonski committed Oct 4, 2019
1 parent 4dc4c53 commit fc7cb2d
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 7 deletions.
20 changes: 14 additions & 6 deletions packages/@ember/-internals/glimmer/lib/components/link-to.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
*/

import { alias, computed } from '@ember/-internals/metal';
import { isQueryParams } from '@ember/-internals/routing/lib/system/query_params';
import { isSimpleClick } from '@ember/-internals/views';
import { assert, warn } from '@ember/debug';
import { flaggedInstrument } from '@ember/instrumentation';
Expand Down Expand Up @@ -838,14 +839,21 @@ const LinkComponent = EmberComponent.extend({
)
);

let { _models: models } = this;
if (models.length > 0) {
let lastModel = models[models.length - 1];
if (this.query === UNDEFINED) {
let { _models: models } = this;
if (models.length > 0) {
let lastModel = models[models.length - 1];

if (typeof lastModel === 'object' && lastModel !== null && lastModel.isQueryParams) {
this.query = lastModel.values;
models.pop();
if (typeof lastModel === 'object' && lastModel !== null && lastModel.isQueryParams) {
this.query = lastModel.values;
models.pop();
}
}
} else {
assert(
'Cannot pass a QueryParams object in @models and @query at the same time',
!(this.models.length === 0 || isQueryParams(this.models[this.models.length - 1]))
);
}

return;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
import { Option } from '@glimmer/interfaces';

export default class QueryParams {
values: null | object;
isQueryParams = true;
constructor(values = null) {
constructor(values: Option<object> = null) {
this.values = values;
}
}

export function isQueryParams(obj: unknown): obj is QueryParams {
return typeof obj === 'object' && obj !== null && obj['isQueryParams'] === true;
}

0 comments on commit fc7cb2d

Please sign in to comment.