nuxt-resource-module
Advanced tools
Comparing version 0.4.0 to 0.4.1
@@ -5,2 +5,12 @@ # Change Log | ||
<a name="0.4.1"></a> | ||
## [0.4.1](https://github.com/mya-ake/nuxt-resource-module/compare/v0.4.0...v0.4.1) (2018-11-09) | ||
### Bug Fixes | ||
* type ([9786d83](https://github.com/mya-ake/nuxt-resource-module/commit/9786d83)) | ||
<a name="0.4.0"></a> | ||
@@ -7,0 +17,0 @@ # [0.4.0](https://github.com/mya-ake/nuxt-resource-module/compare/v0.3.1...v0.4.0) (2018-11-07) |
@@ -23,3 +23,3 @@ import { RequestMethod, ResourceConstructor, ResourceRequestMethods, ResourceDelayProperty, ResourceMayBeCancelProperty } from '@/interfaces'; | ||
private buildMayBeCancelMethods; | ||
private createMayBeCancelMthod; | ||
private createMayBeCancelMethod; | ||
private processResponse; | ||
@@ -26,0 +26,0 @@ private addDelayRequestConifg; |
@@ -163,3 +163,3 @@ var __assign = (this && this.__assign) || function () { | ||
get: function () { | ||
return _this.createMayBeCancelMthod(methodName); | ||
return _this.createMayBeCancelMethod(methodName); | ||
}, | ||
@@ -170,3 +170,3 @@ }); | ||
}; | ||
Resource.prototype.createMayBeCancelMthod = function (methodName) { | ||
Resource.prototype.createMayBeCancelMethod = function (methodName) { | ||
var _this_1 = this; | ||
@@ -173,0 +173,0 @@ var method = this[methodName]; |
@@ -23,4 +23,4 @@ import { AxiosInstance, AxiosRequestConfig, AxiosResponse } from 'axios'; | ||
url: string; | ||
dataMapper?: (response: AxiosResponse) => any; | ||
processor?: (response: AxiosResponse) => any; | ||
dataMapper?: (response: ResourceResponse) => any; | ||
processor?: (response: ResourceResponse) => any; | ||
} | ||
@@ -27,0 +27,0 @@ export interface ResourceDelayRequestConfig { |
{ | ||
"name": "nuxt-resource-module", | ||
"version": "0.4.0", | ||
"version": "0.4.1", | ||
"description": "@nuxtjs/axios based API request wrapper for Nuxt.js", | ||
@@ -5,0 +5,0 @@ "main": "dist/module.js", |
147
README.md
@@ -14,3 +14,3 @@ # Nuxt.js Resource Module | ||
- リンクをクリックしてすぐに遷移します | ||
- 遷移後リクエストを行い、response.dataをそのままdataプロパティにマッピングします | ||
- 遷移後リクエストを行い、response.data をそのまま data プロパティにマッピングします | ||
- SSR 時は遅延させずにそのままリクエストします | ||
@@ -20,3 +20,16 @@ - キャンセル可能なリクエストを簡単に作れます | ||
- リクエスト時にレスポンスを加工する処理を追加できます | ||
- 内部でエラーハンドリングしているので使うときにエラーが投げられることはありません | ||
--- | ||
- HTTP request module wrapping [@nuxtjs/axios](https://github.com/nuxt-community/axios-module) | ||
- AsyncData and fetch requested requests can be delayed until after transition | ||
- Immediate transition | ||
- Make a request after the transition and map response.data to the data property | ||
- When requesting SSR, do not delay but request as is | ||
- Easily create cancelable requests | ||
- When making a transition, cancel request in request automatically | ||
- You can add a process to modify the response on request | ||
- Since error handling is done internally, no error is thrown when using | ||
## Install | ||
@@ -66,3 +79,3 @@ | ||
// response | ||
// response | ||
processor(response: ResourceResponse) { | ||
@@ -80,5 +93,5 @@ if (response.status !== 200) { | ||
// cancel | ||
async requestSuggestion() { | ||
this.$_resource.cancel('/users'); | ||
const response = await this.$_resource.mayBeCancel.get({ url: '/users' }); | ||
async searchUser() { | ||
this.$_resource.cancel('/users/search'); | ||
const response = await this.$_resource.mayBeCancel.get({ url: '/users/search' }); | ||
if (response.canceled === true) { | ||
@@ -93,5 +106,5 @@ // when cancel | ||
export const actions = { | ||
async request() { | ||
this.$_resource.cancel('/users'); | ||
const response = await this.$_resource.mayBeCancel.get({ url: '/users' }); | ||
async searchUser() { | ||
this.$_resource.cancel('/users/search'); | ||
const response = await this.$_resource.mayBeCancel.get({ url: '/users/search' }); | ||
if (response.canceled === true) { | ||
@@ -104,5 +117,114 @@ // when cancel | ||
## API | ||
### Methods | ||
#### Request methods | ||
##### Default request methods | ||
- $\_resource.get(config: ResourceRequestConfig) | ||
- $\_resource.delete(config: ResourceRequestConfig) | ||
- $\_resource.head(config: ResourceRequestConfig) | ||
- $\_resource.post(config: ResourceRequestConfig) | ||
- $\_resource.put(config: ResourceRequestConfig) | ||
- $\_resource.patch(config: ResourceRequestConfig) | ||
##### Delay request methods | ||
クライアントとサーバーで動作が変わります。 | ||
There are client and server behavior changes. | ||
client: asyncData または fetch で利用した場合は、遷移が確定してからリクエストが呼ばれます。 | ||
server: デフォルトメソッドを使ったときと同じです。使ったときにそのままリクエストを送ります。 | ||
client: When used with asyncData or fetch, it is called after the transition is confirmed. | ||
server: Same as default method. Send a request when called. | ||
- $\_resource.delay.get(config: ResourceRequestConfig) | ||
- $\_resource.delay.delete(config: ResourceRequestConfig) | ||
- $\_resource.delay.head(config: ResourceRequestConfig) | ||
- $\_resource.delay.post(config: ResourceRequestConfig) | ||
- $\_resource.delay.put(config: ResourceRequestConfig) | ||
- $\_resource.delay.patch(config: ResourceRequestConfig) | ||
##### May be cancel request methods | ||
キャンセル可能なリクエストになります。`$_resource.cancel()`と一緒に使います。 | ||
It will be a request that can be canceled. Use with `$_resource.cancel()`. | ||
- $\_resource.mayBeCancel.get(config: ResourceRequestConfig) | ||
- $\_resource.mayBeCancel.delete(config: ResourceRequestConfig) | ||
- $\_resource.mayBeCancel.head(config: ResourceRequestConfig) | ||
- $\_resource.mayBeCancel.post(config: ResourceRequestConfig) | ||
- $\_resource.mayBeCancel.put(config: ResourceRequestConfig) | ||
- $\_resource.mayBeCancel.patch(config: ResourceRequestConfig) | ||
#### Cancel methods | ||
- $\_resource.cancel(url: ResourceRequestConfig.url) | ||
- $\_resource.cancelAll() | ||
- Automatically call with beforeEach | ||
#### Delay methods | ||
- $\_resource.requestDelayedRequest() | ||
- Request all delayed requests | ||
- Automatically call within the `next` function of beforeRouteEnter. | ||
- $\_resource.clearDelayedRequest() | ||
- Clear all delayed requests | ||
- Automatically call with beforeEach | ||
#### Extending methods | ||
- $\_resource.setEachProcessor(fn: Function) | ||
### Types | ||
#### ResourceRequestConfig | ||
Extends [AxiosRequestConfig](https://github.com/axios/axios#request-config) | ||
```TypeScript | ||
export interface ResourceRequestConfig extends AxiosRequestConfig { | ||
url: string; | ||
dataMapper?: (response: ResourceResponse) => any; | ||
processor?: (response: ResourceResponse) => any; | ||
} | ||
``` | ||
e.g. | ||
```JavaScript | ||
{ | ||
url: '/users/search', // require | ||
params: { // Can also use axios config | ||
query: 'Alice', | ||
}, | ||
dataMapper(response) { // option | ||
const { delayed, data } = response; | ||
return delayed ? { users: [] } : { users: data.users }; | ||
}, | ||
processor(response) { // option | ||
if (response.status !== 200) { | ||
error({ statusCode: response.status, message: 'Request error' }) | ||
} | ||
return response; | ||
}, | ||
} | ||
``` | ||
#### ResourceResponse | ||
Extends [AxiosResponse](https://github.com/axios/axios#response-schema) | ||
```TypeScript | ||
export interface ResourceResponse extends AxiosResponse { | ||
canceled: boolean; | ||
delayed: boolean; | ||
} | ||
``` | ||
## Extending | ||
### Each processor | ||
@@ -127,2 +249,3 @@ | ||
#### nuxt.config.js | ||
```JavaScript | ||
@@ -144,2 +267,3 @@ module.exports = { | ||
#### application code | ||
```JavaScript | ||
@@ -156,4 +280,2 @@ export default { | ||
## Options | ||
@@ -167,3 +289,2 @@ | ||
e.g. | ||
@@ -198,2 +319,2 @@ | ||
}, | ||
``` | ||
``` |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
33344
310