# pinia-plugin-firestore-sync

> Sync your pinia state and firestore document at ease!

Latest version **1.3.0** (published 2023-09-29) · MIT license · 0 weekly downloads

## Install

```sh
npm install pinia-plugin-firestore-sync
pnpm add pinia-plugin-firestore-sync
yarn add pinia-plugin-firestore-sync
bun add pinia-plugin-firestore-sync
```

## Health

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

Positive: has types; no vulnerabilities.

Warnings: low downloads; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.3.0 |
| Published | 2023-09-29 |
| First published | 2022-01-16 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 10.2 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | kazuwombat |
| Maintainers | kazuwombat |
| Keywords | pinia, plugin, firestore, starter |

## Links

- npm: https://www.npmjs.com/package/pinia-plugin-firestore-sync
- npm.io page: https://npm.io/package/pinia-plugin-firestore-sync

## Alternatives

- [lodash.startswith](https://npm.io/package/lodash.startswith.md) — 769.7K weekly downloads
- [@tarojs/service](https://npm.io/package/@tarojs/service.md) — 33.9K weekly downloads
- [io.extendreality.tilia.indicators.spatialtargets.unity](https://npm.io/package/io.extendreality.tilia.indicators.spatialtargets.unity.md) — 131 weekly downloads
- [@rtarojs/taro](https://npm.io/package/@rtarojs/taro.md) — 90 weekly downloads
- [node-branch-io](https://npm.io/package/node-branch-io.md) — 50 weekly downloads

## Recent versions

- 1.3.0 (latest) — 2023-09-29
- 1.2.0 — 2022-09-01
- 1.1.0 — 2022-04-16
- 1.0.2 — 2022-01-16
- 1.0.1 — 2022-01-16
- 1.0.0 — 2022-01-16

## README

<h1>
  <img height="64" src="https://user-images.githubusercontent.com/6919381/149651295-0bf814f5-ad07-4d40-9af2-78dd99d8e1e7.png" alt="logo">
  Pinia Firestore Sync
</h1>

Sync your pinia 🍍 store with Firestore at ease!

## Installation

```sh
npm install pinia-plugin-firestore-sync
```

## Usage

### Preparation

At first, you need to add plugin by use

```ts
import { PiniaFirestoreSync } from 'pinia-plugin-firestore-sync'

const pinia = createPinia().use(firestoreSyncPlugin)
app.use(pinia).mount('#app') 
```

### Sync with Document

```ts
 type ExampleDoc = {
   name: string,
   age: number
 }
 
 export type State = {
   docData: ExampleDoc | null,
 }
 
 export const useExampleStore = defineStore('expamle', {
   state: (): State => {
     return {
       docData: null,
     }
   },
   actions: {
     async setup() {
       // Get Document reference
       const store = getFirestore()
       const docRef = doc(store, 'Examples/id')
 
       // Do the magic
       this.sync('docData', docRef)
     }
   }
 })
```

### Sync with Collection

```ts
type ExampleDoc = {
  name: string,
  age: number
}

export type State = {
  collectionData: ExampleDoc[] | null,
}
export const useExampleStore = defineStore('expamle', {
  state: (): State => {
    return {
      collectionData: null,
    }
  },
  actions: {
    async setup() {
      // Get Collection reference
      const store = getFirestore()
      const collectionRef = collection(store, 'Examples')

      // Do the magic
      this.sync('collectionData', collectionRef)
    }
  }
})
```

### Sync with Query

```ts
type ExampleDoc = {
  name: string,
  age: number
}
export type State = {
  queryData: ExampleDoc[] | null,
} 
export const useExampleStore = defineStore('expamle', {
  state: (): State => {
    return {
      queryData: null,
    }
  },
  actions: {
    async setup() {
      // Build query
      const store = getFirestore()
      const collectionRef = collection(store, 'Examples')
      const q = query(collectionRef, where('name', '==', 'wombat'))

      // Do the magic
      this.sync('queryData', q)
    }
  }
})
```

## License

[MIT](http://opensource.org/licenses/MIT)

---
_Source: https://npm.io/package/pinia-plugin-firestore-sync · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
