Skip to content

Commit c171eb3

Browse files
committed
Auto merge of #4380 - Turbo87:with-meta, r=Turbo87
mirage: Replace `withMeta()` utility function with object spread operator This seems a bit more straight forward compared to the `withMeta()` function hiding what's being returned.
2 parents c5ce00c + 7e1ba0c commit c171eb3

File tree

5 files changed

+8
-14
lines changed

5 files changed

+8
-14
lines changed

mirage/route-handlers/-utils.js

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,6 @@ export function pageParams(request) {
2222
return { page, perPage, start, end };
2323
}
2424

25-
export function withMeta(response, meta) {
26-
response.meta = meta;
27-
return response;
28-
}
29-
3025
export function compareStrings(a, b) {
3126
return a < b ? -1 : a > b ? 1 : 0;
3227
}

mirage/route-handlers/categories.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { compareStrings, notFound, pageParams, withMeta } from './-utils';
1+
import { compareStrings, notFound, pageParams } from './-utils';
22

33
export function register(server) {
44
server.get('/api/v1/categories', function (schema, request) {
@@ -8,7 +8,7 @@ export function register(server) {
88
let categories = allCategories.slice(start, end);
99
let total = allCategories.length;
1010

11-
return withMeta(this.serialize(categories), { total });
11+
return { ...this.serialize(categories), meta: { total } };
1212
});
1313

1414
server.get('/api/v1/categories/:category_id', function (schema, request) {

mirage/route-handlers/crates.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { Response } from 'ember-cli-mirage';
22

33
import { getSession } from '../utils/session';
4-
import { compareIsoDates, compareStrings, notFound, pageParams, withMeta } from './-utils';
4+
import { compareIsoDates, compareStrings, notFound, pageParams } from './-utils';
55

66
export function list(schema, request) {
77
const { start, end } = pageParams(request);
@@ -46,7 +46,7 @@ export function list(schema, request) {
4646
crates = crates.sort((a, b) => compareStrings(a.id.toLowerCase(), b.id.toLowerCase()));
4747
}
4848

49-
return withMeta(this.serialize(crates.slice(start, end)), { total: crates.length });
49+
return { ...this.serialize(crates.slice(start, end)), meta: { total: crates.length } };
5050
}
5151

5252
export function register(server) {
@@ -221,7 +221,7 @@ export function register(server) {
221221

222222
let versionDownloads = schema.versionDownloads.all().filter(it => it.version.crateId === crate.id);
223223

224-
return withMeta(this.serialize(versionDownloads), { extra_downloads: crate._extra_downloads });
224+
return { ...this.serialize(versionDownloads), meta: { extra_downloads: crate._extra_downloads } };
225225
});
226226

227227
server.put('/api/v1/crates/:name/owners', (schema, request) => {

mirage/route-handlers/keywords.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { notFound, pageParams, withMeta } from './-utils';
1+
import { notFound, pageParams } from './-utils';
22

33
export function register(server) {
44
server.get('/api/v1/keywords', function (schema, request) {
@@ -8,7 +8,7 @@ export function register(server) {
88
let keywords = allKeywords.slice(start, end);
99
let total = allKeywords.length;
1010

11-
return withMeta(this.serialize(keywords), { total });
11+
return { ...this.serialize(keywords), meta: { total } };
1212
});
1313

1414
server.get('/api/v1/keywords/:keyword_id', (schema, request) => {

mirage/route-handlers/me.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import { Response } from 'ember-cli-mirage';
22

33
import { getSession } from '../utils/session';
4-
import { withMeta } from './-utils';
54

65
export function register(server) {
76
server.get('/api/v1/me', function (schema) {
@@ -83,7 +82,7 @@ export function register(server) {
8382
let totalPages = Math.ceil(totalCount / perPage);
8483
let more = page < totalPages;
8584

86-
return withMeta(this.serialize(versions), { more });
85+
return { ...this.serialize(versions), meta: { more } };
8786
});
8887

8988
server.put('/api/v1/confirm/:token', (schema, request) => {

0 commit comments

Comments
 (0)