From 7df7acc00991b16a051af9d4ab8d74baadc617d9 Mon Sep 17 00:00:00 2001 From: nicolasguridi Date: Fri, 30 Dec 2022 14:47:33 -0300 Subject: [PATCH] refactor(javascript): change default exports to named exports --- .../javascript/api/__mocks__/index.mock.ts | 2 +- .../assets/app/javascript/api/index.ts | 76 ++++++++++--------- .../app/javascript/utils/case-converter.ts | 2 +- .../assets/app/javascript/utils/csrf-token.ts | 2 +- 4 files changed, 42 insertions(+), 40 deletions(-) diff --git a/lib/potassium/assets/app/javascript/api/__mocks__/index.mock.ts b/lib/potassium/assets/app/javascript/api/__mocks__/index.mock.ts index ea669d37..d11273c4 100644 --- a/lib/potassium/assets/app/javascript/api/__mocks__/index.mock.ts +++ b/lib/potassium/assets/app/javascript/api/__mocks__/index.mock.ts @@ -1,3 +1,3 @@ const api = jest.fn(); -export default api; +export { api }; diff --git a/lib/potassium/assets/app/javascript/api/index.ts b/lib/potassium/assets/app/javascript/api/index.ts index b4c1032a..452b0b38 100644 --- a/lib/potassium/assets/app/javascript/api/index.ts +++ b/lib/potassium/assets/app/javascript/api/index.ts @@ -1,6 +1,6 @@ import axios, { type AxiosRequestTransformer, type AxiosResponseTransformer } from 'axios'; -import convertKeys, { type objectToConvert } from '../utils/case-converter'; -import csrfToken from '../utils/csrf-token'; +import { convertKeys, type objectToConvert } from '../utils/case-converter'; +import { csrfToken } from '../utils/csrf-token'; const api = axios.create({ transformRequest: [ @@ -18,44 +18,46 @@ const api = axios.create({ }, }); -export default api; +export { api }; /* // Example to use the api object in the path ´app/javascript/api/users.ts´ -import api from './index'; - -export default { - index() { - const path = '/api/internal/users'; - - return api({ - method: 'get', - url: path, - }); - }, - create(data: Partial) { - const path = '/api/internal/users'; - - return api({ - method: 'post', - url: path, - data: { - user: data, - }, - }); - }, - update(data: Partial) { - const path = `/api/internal/users/${data.id}`; - - return api({ - method: 'put', - url: path, - data: { - user: data, - }, - }); - }, -}; +import { api } from './index'; + +function index() { + const path = '/api/internal/users'; + + return api({ + method: 'get', + url: path, + }); +} + +function create(data: Partial) { + const path = '/api/internal/users'; + + return api({ + method: 'post', + url: path, + data: { + user: data, + }, + }); +} + +function update(data: Partial) { + const path = `/api/internal/users/${data.id}`; + + return api({ + method: 'put', + url: path, + data: { + user: data, + }, + }); +} + +export { index, create, update }; */ diff --git a/lib/potassium/assets/app/javascript/utils/case-converter.ts b/lib/potassium/assets/app/javascript/utils/case-converter.ts index 145f5ecb..19acc281 100644 --- a/lib/potassium/assets/app/javascript/utils/case-converter.ts +++ b/lib/potassium/assets/app/javascript/utils/case-converter.ts @@ -36,4 +36,4 @@ function convertKeys( return object; } -export default convertKeys; +export { convertKeys }; diff --git a/lib/potassium/assets/app/javascript/utils/csrf-token.ts b/lib/potassium/assets/app/javascript/utils/csrf-token.ts index b9490341..27f95630 100644 --- a/lib/potassium/assets/app/javascript/utils/csrf-token.ts +++ b/lib/potassium/assets/app/javascript/utils/csrf-token.ts @@ -6,4 +6,4 @@ function csrfToken() { return token ?? false; } -export default csrfToken; +export { csrfToken };