Skip to content

Commit 4a84429

Browse files
authored
Merge pull request #333 from chantouchsek/refactor/332-remove-redundant-methods
Refactor/332 remove redundant methods
2 parents afd35c1 + e8f3cf4 commit 4a84429

File tree

8 files changed

+153
-248
lines changed

8 files changed

+153
-248
lines changed

README.md

Lines changed: 24 additions & 24 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

@@ -127,18 +127,18 @@ It will create `$errors` object inside components.
127127

128128
1.Create **proxies** folder or your prefer folder name for this
129129

130-
`~/proxies/NewsProxy.js`
130+
`~/proxies/NewsService.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 NewsService extends BaseService {
136136
constructor(parameters = {}) {
137137
super('news', parameters)
138138
}
139139
}
140140

141-
export default NewsProxy
141+
export default NewsService
142142
```
143143

144144
2.Store
@@ -157,19 +157,19 @@ actions.js
157157

158158
```js
159159
import { ALL } from './mutation-types'
160-
import { NewsProxy } from '~/proxies'
160+
import { NewsService } from '~/proxies'
161161
import { BaseTransformer, PaginationTransformer } from 'vue-axios-http'
162162
import { pagination, notify } from '~/utils'
163163

164-
const proxy = new NewsProxy()
164+
const service = new NewsService()
165165

166166
const all = async ({ commit, dispatch }, payload = {}) => {
167167
const { fn } = payload
168168
if (typeof fn === 'function') {
169-
await fn(proxy)
169+
await fn(service)
170170
}
171171
try {
172-
const { data, meta } = await proxy.all()
172+
const { data, meta } = await service.all()
173173
const all = {
174174
items: BaseTransformer.fetchCollection(data),
175175
pagination: PaginationTransformer.fetch(meta),
@@ -247,8 +247,8 @@ export default {
247247
async asyncData({ app, store }) {
248248
const { id = null } = app.$auth.user
249249
await store.dispatch('news/all', {
250-
fn: (proxy) => {
251-
proxy
250+
fn: (service) => {
251+
service
252252
.setParameters({
253253
userId: id,
254254
include: ['categories'],
@@ -267,8 +267,8 @@ export default {
267267
mounted() {
268268
const { id = null } = this.$auth.user
269269
this.$store.dispatch('news/all', {
270-
fn: (proxy) => {
271-
proxy
270+
fn: (service) => {
271+
service
272272
.setParameters({
273273
userId: id,
274274
include: ['categories'],
@@ -282,7 +282,7 @@ export default {
282282

283283
You can set or remove any parameters you like.
284284

285-
## Proxy's methods are available
285+
## Service's methods are available
286286

287287
| Method | Description |
288288
| ----------------------------------------------- | --------------------------- |
@@ -301,7 +301,7 @@ Set parameters with key/value.
301301
#### Example
302302

303303
```js
304-
const proxy = new ExampleProxy()
304+
const service = new ExampleService()
305305
const parameters = {
306306
search: {
307307
first_name: 'Sek',
@@ -317,7 +317,7 @@ const parameters = {
317317
},
318318
category_id: 6,
319319
}
320-
const { data } = proxy.setParameters(parameters).all()
320+
const { data } = service.setParameters(parameters).all()
321321
this.data = data
322322
```
323323

@@ -334,8 +334,8 @@ if setParameter that value is empty or null it will remove that param for query
334334
#### Example 1
335335

336336
```js
337-
const proxy = new ExampleProxy()
338-
const { data } = await proxy.setParameter('page', 1).all()
337+
const service = new ExampleService()
338+
const { data } = await service.setParameter('page', 1).all()
339339
this.data = data
340340
```
341341

@@ -350,9 +350,9 @@ Expected will be:
350350
#### Example 2
351351

352352
```js
353-
const proxy = new ExampleProxy()
353+
const service = new ExampleService()
354354
const queryString = 'limit=10&page=1&search[name]=hello'
355-
const { data } = await proxy.setParameter(queryString).all()
355+
const { data } = await service.setParameter(queryString).all()
356356
this.data = data
357357
```
358358

@@ -370,20 +370,20 @@ Expected will be:
370370

371371
Be sure to use only once in `mounted()` or `asyncData()` and `asyncData()` is only available in `NuxtJs`
372372

373-
## Use proxy in components
373+
## Use service in components
374374

375375
- news/\_id.vue pages
376376

377377
```js
378-
import { NewsProxy } from '~/proxies'
378+
import { NewsService } from '~/proxies'
379379

380-
const proxy = new NewsProxy()
380+
const service = new NewsService()
381381

382382
export default {
383383
methods: {
384384
async fetchNews(id) {
385385
try {
386-
const { data } = await proxy.find(id)
386+
const { data } = await service.find(id)
387387
this.detail = data
388388
} catch (e) {
389389
console.log(e)

jest.config.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,8 @@ const config: InitialOptionsTsJest = {
55
collectCoverageFrom: ['src/**/*.ts', 'src/**/*.js'],
66
coverageThreshold: {
77
global: {
8-
lines: 100,
9-
functions: 100,
10-
branches: 92.72,
11-
statements: 99.33,
8+
branches: 93,
9+
statements: 99,
1210
},
1311
},
1412
testEnvironment: 'node',

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
}

0 commit comments

Comments
 (0)