firex-store
Advanced tools
Comparing version 0.2.0 to 0.3.1
@@ -1,8 +0,8 @@ | ||
import { CriteriaOptions } from './criteria-options.interface'; | ||
import { FindCriteriaOptions } from './options'; | ||
import { FirestoreRef } from './types'; | ||
interface Criteria<T, U> { | ||
ref: T; | ||
options?: CriteriaOptions<U>; | ||
options?: FindCriteriaOptions<U>; | ||
} | ||
export declare const findFirestore: <T = any>({ ref, options }: Criteria<FirestoreRef, T>) => Promise<T>; | ||
export {}; |
export * from './store'; | ||
export { findFirestore } from './find'; | ||
export { ErrorHandler, OnCompleted, Mapper } from './types'; | ||
export { ErrorHandler, OnCompleted, Mapper, AfterMutationCalled } from './types'; | ||
export { Payload } from './models'; |
export * from './criteria-options.interface'; | ||
export * from './find-criteria-options.interface'; | ||
export * from './subscribe-criteria-options.interface'; |
import { FireMutation } from '../types'; | ||
import { Unsubscribe } from 'firebase'; | ||
import { CriteriaOptions } from '../options'; | ||
interface SubscribeCriteria<T, U> extends CriteriaOptions<T> { | ||
import { SubscribeCriteriaOptions, FindCriteriaOptions } from '../options'; | ||
interface SubscribeCriteria<T, U> extends SubscribeCriteriaOptions<T> { | ||
ref: U; | ||
fireMutation: FireMutation; | ||
} | ||
interface FindCriteria<T, U> extends CriteriaOptions<T> { | ||
interface FindCriteria<T, U> extends FindCriteriaOptions<T> { | ||
ref: U; | ||
} | ||
export declare class FirestoreService { | ||
static subscribe<T = any>({ ref, fireMutation, mapper, errorHandler, onCompleted }: SubscribeCriteria<T, firebase.firestore.DocumentReference>): Unsubscribe; | ||
static subscribeAll<T = any>({ ref, fireMutation, mapper, errorHandler, onCompleted }: SubscribeCriteria<T, firebase.firestore.CollectionReference | firebase.firestore.Query>): Unsubscribe; | ||
static subscribe<T = any>({ ref, fireMutation, mapper, errorHandler, onCompleted, afterMutationCalled }: SubscribeCriteria<T, firebase.firestore.DocumentReference>): Unsubscribe; | ||
static subscribeAll<T = any>({ ref, fireMutation, mapper, errorHandler, onCompleted, afterMutationCalled }: SubscribeCriteria<T, firebase.firestore.CollectionReference | firebase.firestore.Query>): Unsubscribe; | ||
static find<T = any>({ ref, mapper, errorHandler, onCompleted }: FindCriteria<T, firebase.firestore.DocumentReference>): Promise<T | any>; | ||
@@ -15,0 +15,0 @@ static findAll<T = any>({ ref, mapper, errorHandler, onCompleted }: FindCriteria<T, firebase.firestore.CollectionReference | firebase.firestore.Query>): Promise<T[] | any | any[]>; |
@@ -5,3 +5,3 @@ "use strict"; | ||
class FirestoreService { | ||
static subscribe({ ref, fireMutation, mapper, errorHandler, onCompleted }) { | ||
static subscribe({ ref, fireMutation, mapper, errorHandler, onCompleted, afterMutationCalled }) { | ||
return ref.onSnapshot((doc) => { | ||
@@ -14,2 +14,5 @@ if (!doc.exists) { | ||
fireMutation('added', payload); | ||
if (afterMutationCalled) { | ||
afterMutationCalled(payload); | ||
} | ||
}, (error) => errorHandler ? errorHandler(error) : console.error(error), () => { | ||
@@ -22,3 +25,3 @@ if (!onCompleted) { | ||
} | ||
static subscribeAll({ ref, fireMutation, mapper, errorHandler, onCompleted }) { | ||
static subscribeAll({ ref, fireMutation, mapper, errorHandler, onCompleted, afterMutationCalled }) { | ||
return ref.onSnapshot((snapshot) => { | ||
@@ -32,2 +35,5 @@ snapshot.docChanges().forEach((change) => { | ||
fireMutation(change.type, payload); | ||
if (afterMutationCalled) { | ||
afterMutationCalled(payload); | ||
} | ||
}); | ||
@@ -34,0 +40,0 @@ }, (error) => errorHandler ? errorHandler(error) : console.error(error), () => { |
import { ActionTree } from 'vuex'; | ||
import { CriteriaOptions } from '../../options'; | ||
import { SubscribeCriteriaOptions } from '../../options'; | ||
import { FirestoreRef } from '../../types'; | ||
@@ -7,5 +7,5 @@ interface Criteria<T = any> { | ||
actionName?: string; | ||
options?: CriteriaOptions<T>; | ||
options?: SubscribeCriteriaOptions<T>; | ||
} | ||
export declare const firestoreSubscribeActions: <T = any>({ ref, actionName, options }: Criteria<T>) => ActionTree<any, any>; | ||
export {}; |
import { Commit } from 'vuex'; | ||
import { FirestoreRef } from '../../types'; | ||
import { CriteriaOptions } from '../../options'; | ||
import { SubscribeCriteriaOptions } from '../../options'; | ||
interface Criteria<T, U> { | ||
@@ -8,5 +8,5 @@ state: any; | ||
ref: T; | ||
options?: CriteriaOptions<U>; | ||
options?: SubscribeCriteriaOptions<U>; | ||
} | ||
export declare const subscribeFirestore: <T = any>({ state, commit, ref, options }: Criteria<FirestoreRef, T>) => void; | ||
export {}; |
@@ -7,1 +7,2 @@ export * from './error-handler.type'; | ||
export * from './firestore-ref.type'; | ||
export * from './subscribe-hooks.type'; |
{ | ||
"name": "firex-store", | ||
"version": "0.2.0", | ||
"version": "0.3.1", | ||
"description": "subscribe firebase data to vuex", | ||
@@ -5,0 +5,0 @@ "main": "./lib/index.js", |
@@ -7,3 +7,3 @@ # firex-store | ||
- If you use this npm, you can reference firestore data, easily | ||
- It is influenced by [vuexfire](https://github.com/vuejs/vuefire) | ||
- It is inspired by [vuexfire](https://github.com/vuejs/vuefire) | ||
@@ -91,3 +91,3 @@ - node v8.9.4 ~ | ||
- actionName?: action property you want to define. | ||
- options?: see [Options](#Options) | ||
- options?: see [Options](#options) | ||
@@ -167,3 +167,3 @@ Ex. subscribe collection | ||
- ref: firebase.firestore.DocumentReference | firebase.firestore.CollectionReference | firebase.firestore.Query | ||
- options?: see [Options](#Options) | ||
- options?: see [Options](#options) | ||
@@ -284,3 +284,3 @@ ```javascript | ||
- ref: firebase.firestore.DocumentReference | firebase.firestore.CollectionReference | firebase.firestore.Query | ||
- options?: see [Options](#Options) | ||
- options?: see [Options](#options) | ||
@@ -321,2 +321,7 @@ EX. call in Store Action, to fetch collection | ||
- afterMutationCalled | ||
- `subscribeFirestore` and `subscribeFirestoreActions` only. | ||
- this method called after mutation called | ||
Ex. | ||
@@ -345,2 +350,11 @@ | ||
```javascript | ||
const afterMutationCalled = (payload: Payload) => { | ||
/** | ||
* payload = { data: any, [key: string]: any } | ||
* */ | ||
console.log(payload) | ||
} | ||
``` | ||
```javascript | ||
export default { | ||
@@ -364,3 +378,4 @@ namespaced: true, | ||
errorHandler, | ||
onCompleted | ||
onCompleted, | ||
afterMutationCalled | ||
} | ||
@@ -367,0 +382,0 @@ }) |
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
32210
71
573
382