From cc6523f00c76bb680035de44a37f32885efb7fea Mon Sep 17 00:00:00 2001 From: arthurfiorette Date: Sun, 23 Jan 2022 16:44:00 -0300 Subject: [PATCH] docs: updated sidebar and added dev mode section --- docs/config/sidebar.md | 11 ++++---- docs/pages/development-mode.md | 48 ++++++++++++++++++++++++++++++++++ docs/pages/homepage.md | 13 +-------- docs/pages/request-id.md | 12 ++++----- 4 files changed, 61 insertions(+), 23 deletions(-) create mode 100644 docs/pages/development-mode.md diff --git a/docs/config/sidebar.md b/docs/config/sidebar.md index 83f4e92..c662d6e 100644 --- a/docs/config/sidebar.md +++ b/docs/config/sidebar.md @@ -1,26 +1,27 @@ - Getting Started - [Homepage](/ 'Homepage') - - [Try it out!](pages/try-it-out.md 'Try axios-cache-interceptor') + - [Try it out!](pages/try-it-out.md 'Try axios-cache-interceptor in your browser!') - [Installing](pages/installing.md 'Installing') - - [Usage & Examples](pages/usage-examples.md 'Interceptor') + - [Usage & examples](pages/usage-examples.md 'Usage and examples') - [Storages](pages/storages.md 'Custom storages') - Cache Interceptor API - - [Request ID](pages/request-id.md 'Request ID') + - [Request Id](pages/request-id.md 'Request Id') - [Global configuration](pages/global-configuration.md 'Global configuration') - [Per request configuration](pages/per-request-configuration.md 'Per request configuration') - [Response object](pages/response-object.md 'Response object') - Extras - - [Typescript Users](pages/typescript-users.md 'Typescript users') + - [Development mode](pages/development-mode.md 'Development mode') + - [Typescript users](pages/typescript-users.md 'Typescript users') - [Compiled code](pages/compiled-code.md 'Compiled code') - [Comparison](pages/comparison.md 'Comparison') - Other - [License](pages/license.md 'License') - - [Contact & Security](pages/contact.md 'Contact & Security') + - [Contact & security](pages/contact.md 'Contact & security') - [Changelog](pages/changelog.md 'Changelog') diff --git a/docs/pages/development-mode.md b/docs/pages/development-mode.md new file mode 100644 index 0000000..ac54ebd --- /dev/null +++ b/docs/pages/development-mode.md @@ -0,0 +1,48 @@ +# Development + +For development, debug and testing purposes, you can opt to use the **Development mode**. + +It brings some extra features to our built code, like the `debug` option, source maps, +fewer code and etc. + +You can enable it basically by using `/dev` at the end of the import path. + +```js +import { setupCache } from 'axios-cache-interceptor/esm/dev'; +const { setupCache } = require('axios-cache-interceptor/umd/dev'); + +// https://cdn.jsdelivr.net/npm/axios-cache-interceptor/umd/dev.js +const { setupCache } = window.AxiosCacheInterceptor; +``` + +## Debug option + +The debug option will print debug information in the console. It is good if you need to +trace any undesired behavior or issue. + +You can enable it by setting `debug` to a function that receives an string. + +```js +// Will print debug info in the console. +setupCache(axios, { + debug: console.log +}); + +// own logger or whatever. +setupCache(axios, { + debug: (message) => { + // Etc + myCustomLogger.emit({ + key: 'axios-cache-interceptor', + log: message + }); + } +}); + +// Disables debug. +setupCache(axios, { + debug: undefined +}); +// or +axiosCacheInstance.debug = undefined; +``` diff --git a/docs/pages/homepage.md b/docs/pages/homepage.md index db071d6..e9c5940 100644 --- a/docs/pages/homepage.md +++ b/docs/pages/homepage.md @@ -1,15 +1,4 @@ -[![Issues](https://img.shields.io/github/issues/arthurfiorette/axios-cache-interceptor?logo=github&label=Issues)](https://github.com/arthurfiorette/axios-cache-interceptor/issues) -[![Stars](https://img.shields.io/github/stars/arthurfiorette/axios-cache-interceptor?logo=github&label=Stars)](https://github.com/arthurfiorette/axios-cache-interceptor/stargazers) -[![License](https://img.shields.io/github/license/arthurfiorette/axios-cache-interceptor?logo=githu&label=License)](https://github.com/arthurfiorette/axios-cache-interceptor/blob/main/LICENSE) -[![Try on Runkit](https://img.shields.io/badge/try%20on-RunKit-brightgreen?logo=runkit&logoColor=e83e8c)](https://npm.runkit.com/axios-cache-interceptor) -[![Codecov](https://codecov.io/gh/arthurfiorette/axios-cache-interceptor/branch/main/graph/badge.svg?token=ML0KGCU0VM)](https://codecov.io/gh/arthurfiorette/axios-cache-interceptor) -[![Downloads](https://img.shields.io/npm/dw/axios-cache-interceptor?style=flat)](https://www.npmjs.com/package/axios-cache-interceptor) -[![Bundlephobia](https://img.shields.io/bundlephobia/minzip/axios-cache-interceptor/latest?style=flat)](https://bundlephobia.com/package/axios-cache-interceptor@latest) -[![Packagephobia](https://packagephobia.com/badge?p=axios-cache-interceptor@latest)](https://packagephobia.com/result?p=axios-cache-interceptor@latest) - -
- -## What is this library? +# Homepage This package is an interceptor for [axios](https://axios-http.com/) that adds caching capabilities to it. It is a simple, easy to use and powerful library. diff --git a/docs/pages/request-id.md b/docs/pages/request-id.md index dd658da..3956be8 100644 --- a/docs/pages/request-id.md +++ b/docs/pages/request-id.md @@ -11,26 +11,26 @@ to the same id with `{ url: 'https://a.com/b/' }`. Also, a custom id can be used to treat two requests as the same. ```js #runkit -const Axios = require('axios'); +const axios = require('axios'); const { setupCache } = require('axios-cache-interceptor'); // Global -setupCache(Axios); +setupCache(axios); -const { id } = await Axios.get('https://jsonplaceholder.typicode.com/posts/1', { +const { id } = await axios.get('https://jsonplaceholder.typicode.com/posts/1', { baseURL: 'baseURL', query: { name: 'value' } }); console.log('Id 1: ' + id); -console.log('Cache 1:', await Axios.storage.get(id)); +console.log('Cache 1:', await axios.storage.get(id)); -const { id: id2 } = await Axios.get('https://jsonplaceholder.typicode.com/posts/1', { +const { id: id2 } = await axios.get('https://jsonplaceholder.typicode.com/posts/1', { id: 'my-overridden-id' }); console.log('Id 2: ' + id2); -console.log('Cache 2:', await Axios.storage.get(id2)); +console.log('Cache 2:', await axios.storage.get(id2)); ``` The