# vuex-map-computed

> Adds ...mapComputed to Vuex

Latest version **1.0.4** (published 2020-01-26) · MIT license · 0 weekly downloads

## Install

```sh
npm install vuex-map-computed
pnpm add vuex-map-computed
yarn add vuex-map-computed
bun add vuex-map-computed
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.4 |
| Published | 2020-01-26 |
| First published | 2020-01-26 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 4.3 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | Jiří Procházka |
| Maintainers | ji.prochazka |
| Keywords | vue, vuex |

## Links

- npm: https://www.npmjs.com/package/vuex-map-computed
- Repository: https://github.com/JiProchazka/mapComputed
- Homepage: https://github.com/JiProchazka/mapComputed#readme
- Issues: https://github.com/JiProchazka/mapComputed/issues
- npm.io page: https://npm.io/package/vuex-map-computed

## Recent versions

- 1.0.4 (latest) — 2020-01-26

## README

![npm](https://img.shields.io/npm/v/vuex-map-computed)

# Vuex ...mapComputed

When you are binding directly a Vuex state property to the form via `v-model` you need to create [Two-way Computed Property](https://vuex.vuejs.org/guide/forms.html#two-way-computed-property).

This simple method takes an inspiration from `mapGetters`, `mapMutations` and `mapActions` methods and helps to create such property the same way: `mapComputed`.

## Installation

`npm i vuex-map-computed`
or
`yarn add vuex-map-computed`

## Usage

First import the method:

```javascript
import { mapComputed } from "vuex-map-computed";
```

Consider we want to bind to a Vuex property called `message`:

```html
// MyComponent.vue <input v-model="email" />
```

### Rely on Convention

In case you have a Vuex state field named `message` it is expected you having a getter with the same name `message` and a setter named `setMessage` (with prefix `set*`). In such case you can simply map the computed property as this:

```javascript
// MyComponent.vue
computed: {
    ...
    ...mapComputed("moduleName", ["message"])
    ...
}
```

### Using Configuration

If you want to define getters and setters yourself, it is also possible:

```javascript
// MyComponent.vue
computed: {
    ...
    ...mapComputed("moduleName", [
      { name: "message", getter: "getMessage", setter: "setMessage" }
    ])
    ...
}
```

You can skip the `name`, in such case a value of `getter` is used as the name.

**Only modules are supported. That means you can't use this method with root store!**

## License

This code is published under the MIT license, you can do whatever you want with it, but it is provided with absolutely no warranty.

---
_Source: https://npm.io/package/vuex-map-computed · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
