Skip to content

Commit 1e486c3

Browse files
committed
refactor!: 🔥 rename BaseProxy class to BaseService class
1 parent 47f65cb commit 1e486c3

File tree

7 files changed

+35
-35
lines changed

7 files changed

+35
-35
lines changed

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ This package helps you quickly to build requests for REST API. Move your logic a
1010
classes. Keep your code clean and elegant.
1111

1212
Wouldn't it be great if you could just use your back end to validate forms on the front end? This package provides a
13-
`BaseProxy` class that does exactly that. It can post itself to a configured endpoint and manage errors. The class is
13+
`BaseService` class that does exactly that. It can post itself to a configured endpoint and manage errors. The class is
1414
meant to be used with a Laravel back end, and it doesn't limit that you need only to work with laravel, Ruby on Rail,
1515
NodeJs, ExpressJs, or any other languages.
1616

@@ -130,9 +130,9 @@ It will create `$errors` object inside components.
130130
`~/proxies/NewsProxy.js`
131131

132132
```js
133-
import { BaseProxy } from 'vue-axios-http'
133+
import { BaseService } from 'vue-axios-http'
134134

135-
class NewsProxy extends BaseProxy {
135+
class NewsProxy extends BaseService {
136136
constructor(parameters = {}) {
137137
super('news', parameters)
138138
}

nuxt/templates/plugin.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
import Vue from 'vue'
2-
import AxiosHttp, { BaseProxy, Validator } from 'vue-axios-http'
2+
import AxiosHttp, { BaseService, Validator } from 'vue-axios-http'
33

44
const errorProperty = '<%= options.errorProperty %>'
55
const parsedQs = '<%= options.parsedQs %>'
66

77
Vue.use(AxiosHttp, { errorProperty: errorProperty, parsedQs })
88

99
export default function ({ $axios }, inject) {
10-
BaseProxy.$http = $axios
10+
BaseService.$http = $axios
1111
inject('errors', Validator)
1212
}

src/__tests__/base-proxy.test.ts renamed to src/__tests__/base-service.test.ts

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,28 @@
11
import Axios from 'axios'
2-
import BaseProxy from '../core/BaseProxy'
2+
import BaseService from '../core/BaseService'
33
import MockAdapter from 'axios-mock-adapter'
4-
import PostProxy from '../util/PostPorxy'
4+
import PostService from '../util/PostService'
55
import type { ValidatorType } from '../core/Validator'
66
import Validator from '../core/Validator'
77
import { merge } from '../util'
88

9-
let proxy: PostProxy
9+
let proxy: PostService
1010
let mockAdapter: MockAdapter
1111
let validator: ValidatorType
1212

13-
describe('BaseProxy', () => {
13+
describe('BaseService', () => {
1414
beforeEach(() => {
1515
validator = Validator
1616
const axios = Axios.create({ baseURL: 'https://mock-api.test' })
17-
BaseProxy.$http = axios
18-
BaseProxy.$errorProperty = 'message'
19-
proxy = new PostProxy()
17+
BaseService.$http = axios
18+
BaseService.$errorProperty = 'message'
19+
proxy = new PostService()
2020
mockAdapter = new MockAdapter(axios)
2121
mockAdapter.reset()
2222
})
2323

2424
it('check if http was installed', async () => {
25-
BaseProxy.$http = undefined as any
25+
BaseService.$http = undefined as any
2626
try {
2727
await proxy.all()
2828
} catch (e) {
@@ -346,10 +346,10 @@ describe('BaseProxy', () => {
346346
})
347347

348348
it('can accept a custom http instance in options', () => {
349-
BaseProxy.$http = Axios.create({ baseURL: 'https://another-example.com' })
349+
BaseService.$http = Axios.create({ baseURL: 'https://another-example.com' })
350350
expect(proxy.$http.defaults.baseURL).toBe('https://another-example.com')
351351

352-
BaseProxy.$http = Axios.create()
352+
BaseService.$http = Axios.create()
353353
expect(proxy.$http.defaults.baseURL).toBe(undefined)
354354
})
355355
})

src/__tests__/post-proxy.spec.ts renamed to src/__tests__/post-service.spec.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
import Axios from 'axios'
2-
import BaseProxy from '../core/BaseProxy'
3-
import PostProxy from '../util/PostPorxy'
2+
import BaseService from '../core/BaseService'
3+
import PostService from '../util/PostService'
44
import MockAdapter from 'axios-mock-adapter'
55

6-
let proxy: PostProxy
6+
let proxy: PostService
77
let mockAdapter: MockAdapter
88

9-
describe('PostProxy', () => {
9+
describe('PostService', () => {
1010
beforeEach(() => {
1111
const axios = Axios.create({ baseURL: 'https://mock-api.test' })
12-
BaseProxy.$http = axios
13-
proxy = new PostProxy()
12+
BaseService.$http = axios
13+
proxy = new PostService()
1414
mockAdapter = new MockAdapter(axios)
1515
mockAdapter.reset()
1616
})

src/core/BaseProxy.ts renamed to src/core/BaseService.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import qs, { IParseOptions } from 'qs'
1818
const validator = Validator
1919
const UNPROCESSABLE_ENTITY = 422
2020

21-
class BaseProxy {
21+
class BaseService {
2222
errors: Errors
2323
parameters: Record<string, any>
2424
endpoint: string
@@ -37,15 +37,15 @@ class BaseProxy {
3737
}
3838

3939
get $http() {
40-
return BaseProxy.$http
40+
return BaseService.$http
4141
}
4242

4343
get $errorProperty() {
44-
return BaseProxy.$errorProperty
44+
return BaseService.$errorProperty
4545
}
4646

4747
get $parsedQs() {
48-
return BaseProxy.$parsedQs
48+
return BaseService.$parsedQs
4949
}
5050

5151
all<T>() {
@@ -129,7 +129,7 @@ class BaseProxy {
129129
form?: T,
130130
config?: AxiosRequestConfig,
131131
): Promise<T> {
132-
const method = BaseProxy.__validateRequestType(requestType)
132+
const method = BaseService.__validateRequestType(requestType)
133133
this.beforeSubmit()
134134
return new Promise((resolve, reject) => {
135135
const data = hasFiles(form) ? objectToFormData(form) : form
@@ -255,4 +255,4 @@ class BaseProxy {
255255
}
256256
}
257257

258-
export default BaseProxy
258+
export default BaseService

src/index.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import type { ValidatorType } from './core/Validator'
2-
import BaseProxy from './core/BaseProxy'
2+
import BaseService from './core/BaseService'
33
import Validator from './core/Validator'
44
import { merge } from './util'
55
import _Vue from 'vue'
@@ -28,9 +28,9 @@ class AxiosHttp {
2828
options,
2929
)
3030
const { $axios, errorProperty, parsedQs } = defaultOption
31-
BaseProxy.$http = $axios
32-
BaseProxy.$errorProperty = errorProperty || 'errors'
33-
BaseProxy.$parsedQs = parsedQs || this.parsedQs
31+
BaseService.$http = $axios
32+
BaseService.$errorProperty = errorProperty || 'errors'
33+
BaseService.$parsedQs = parsedQs || this.parsedQs
3434
Vue.mixin({
3535
beforeCreate() {
3636
this.$options.$errors = {} as any
@@ -49,6 +49,6 @@ class AxiosHttp {
4949
})
5050
}
5151
}
52-
export { Validator, BaseProxy, BaseProxy as BaseService }
52+
export { Validator, BaseService }
5353
export * from './util'
5454
export default new AxiosHttp()

src/util/PostPorxy.ts renamed to src/util/PostService.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
import BaseProxy from '../core/BaseProxy'
1+
import BaseService from '../core/BaseService'
22

3-
class PostProxy extends BaseProxy {
3+
class PostService extends BaseService {
44
constructor(parameters = {}) {
55
super('posts', parameters)
66
}
@@ -14,4 +14,4 @@ class PostProxy extends BaseProxy {
1414
}
1515
}
1616

17-
export default PostProxy
17+
export default PostService

0 commit comments

Comments
 (0)