# getDefaultManagers()

`getDefaultManagers` returns an Array of [Managers](https://dataclient.io/vue/api/Manager.md) to be sent to [DataClientPlugin](https://dataclient.io/vue/api/DataClientPlugin.md).

This makes it simple to configure and add custom [Managers](https://dataclient.io/vue/api/Manager.md), while remaining robust against
any potential changes to the default managers.

Currently returns \[[DevToolsManager](https://dataclient.io/vue/api/DevToolsManager.md)\*, [NetworkManager](https://dataclient.io/vue/api/NetworkManager.md), [SubscriptionManager](https://dataclient.io/vue/api/SubscriptionManager.md)].

\*(`DevToolsManager` is excluded in production builds.)

## Usage

```ts title="main.ts"
import { createApp } from 'vue';
import { DataClientPlugin, getDefaultManagers } from '@data-client/vue';
import App from './App.vue';

const managers = getDefaultManagers({
  // set fallback expiry time to an hour
  networkManager: { dataExpiryLength: 1000 * 60 * 60 },
});

const app = createApp(App);
app.use(DataClientPlugin, { managers });
app.mount('#app');
```

When `managers` is omitted, `DataClientPlugin` uses `getDefaultManagers()` with no arguments.
See [DataClientPlugin](https://dataclient.io/vue/api/DataClientPlugin.md#options) for the
other options.

## Arguments

Each argument represents a configuration of the manager. It can be of three possible types:

- Any plain object is used as options to be sent to the manager's constructor.
- An instance of the manager to be used directly.
- `null`. When sent will exclude the manager.

```ts
getDefaultManagers({
  devToolsManager: { trace: true },
  networkManager: new NetworkManager({ errorExpiryLength: 1 }),
  subscriptionManager: null,
});
```

### networkManager

> **Note**
>
> `null` is not allowed here since NetworkManager is required

`dataExpiryLength` is used as a fallback when an Endpoint does not have [dataExpiryLength](https://dataclient.io/docs/concepts/expiry-policy#endpointdataexpirylength) defined.

`errorExpiryLength` is used as a fallback when an Endpoint does not have [errorExpiryLength](https://dataclient.io/docs/concepts/expiry-policy#endpointerrorexpirylength) defined.

### devToolsManager

[Arguments](https://github.com/reduxjs/redux-devtools/blob/main/extension/docs/API/Arguments.md)
to send to redux devtools.

### subscriptionManager

A class that implements `SubscriptionConstructable` like [PollingSubscription](https://dataclient.io/vue/api/PollingSubscription.md)

## Examples

### Tracing actions

For example, we can enable the [trace](https://github.com/reduxjs/redux-devtools/blob/main/extension/docs/API/Arguments.md#trace) option to help track down where actions are dispatched from. This has a large performance impact, so it is normally disabled.

```ts
const managers = getDefaultManagers({
  devToolsManager: { trace: true },
});
```

### Manager inheritance

Sending manager instances allows us to customize managers using inheritance.

```ts
import {
  NetworkManager,
  getDefaultManagers,
  type FetchAction,
} from '@data-client/vue';

class LoggingNetworkManager extends NetworkManager {
  protected handleFetch(action: FetchAction) {
    console.log('fetching', action.key);
    return super.handleFetch(action);
  }
}

const managers = getDefaultManagers({
  networkManager: new LoggingNetworkManager(),
});
```

### Disabling

Using `null` will remove managers completely. [NetworkManager](https://dataclient.io/vue/api/NetworkManager.md) cannot be removed this way.

```ts
const managers = getDefaultManagers({
  devToolsManager: null,
  subscriptionManager: null,
});
```

Here we disable every manager except [NetworkManager](https://dataclient.io/vue/api/NetworkManager.md).
