Skip to content

Commit

Permalink
refactor(javascript): change default exports to named exports
Browse files Browse the repository at this point in the history
  • Loading branch information
nicolasguridi committed Dec 30, 2022
1 parent ab031b4 commit 7df7acc
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 40 deletions.
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
const api = jest.fn();

export default api;
export { api };
76 changes: 39 additions & 37 deletions lib/potassium/assets/app/javascript/api/index.ts
Original file line number Diff line number Diff line change
@@ -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: [
Expand All @@ -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<User>) {
const path = '/api/internal/users';
return api({
method: 'post',
url: path,
data: {
user: data,
},
});
},
update(data: Partial<User>) {
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<User>) {
const path = '/api/internal/users';
return api({
method: 'post',
url: path,
data: {
user: data,
},
});
}
function update(data: Partial<User>) {
const path = `/api/internal/users/${data.id}`;
return api({
method: 'put',
url: path,
data: {
user: data,
},
});
}
export { index, create, update };
*/
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,4 @@ function convertKeys(
return object;
}

export default convertKeys;
export { convertKeys };
2 changes: 1 addition & 1 deletion lib/potassium/assets/app/javascript/utils/csrf-token.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@ function csrfToken() {
return token ?? false;
}

export default csrfToken;
export { csrfToken };

0 comments on commit 7df7acc

Please sign in to comment.