firex-store
Advanced tools
Comparing version 0.1.2 to 0.2.0
export * from './store'; | ||
export { findFirestore } from './find'; | ||
export { ErrorHandler, OnCompleted, Mapper } from './types'; |
import { FireMutation } from '../types'; | ||
import { Unsubscribe } from 'firebase'; | ||
import { CriteriaOptions } from '../criteria-options.interface'; | ||
import { CriteriaOptions } from '../options'; | ||
interface SubscribeCriteria<T, U> extends CriteriaOptions<T> { | ||
@@ -15,4 +15,4 @@ ref: U; | ||
static find<T = any>({ ref, mapper, errorHandler, onCompleted }: FindCriteria<T, firebase.firestore.DocumentReference>): Promise<T | any>; | ||
static findAll<T = any>({ ref, mapper, errorHandler, onCompleted }: FindCriteria<T, firebase.firestore.CollectionReference | firebase.firestore.Query>): Promise<T | any>; | ||
static findAll<T = any>({ ref, mapper, errorHandler, onCompleted }: FindCriteria<T, firebase.firestore.CollectionReference | firebase.firestore.Query>): Promise<T[] | any | any[]>; | ||
} | ||
export {}; |
@@ -10,3 +10,4 @@ "use strict"; | ||
} | ||
const payload = utils_1.mapToIfDefined(doc, mapper); | ||
const data = utils_1.mapToIfDefined(doc, mapper); | ||
const payload = { data }; | ||
fireMutation('added', payload); | ||
@@ -26,3 +27,4 @@ }, (error) => errorHandler ? errorHandler(error) : console.error(error), () => { | ||
} | ||
const payload = utils_1.mapToIfDefined(change.doc, mapper); | ||
const data = utils_1.mapToIfDefined(change.doc, mapper); | ||
const payload = { data }; | ||
fireMutation(change.type, payload); | ||
@@ -37,4 +39,4 @@ }); | ||
} | ||
static find({ ref, mapper, errorHandler, onCompleted }) { | ||
return ref | ||
static async find({ ref, mapper, errorHandler, onCompleted }) { | ||
const result = await ref | ||
.get() | ||
@@ -48,12 +50,10 @@ .then((doc) => { | ||
}) | ||
.catch((error) => errorHandler ? errorHandler(error) : console.error(error)) | ||
.finally(() => { | ||
if (!onCompleted) { | ||
return; | ||
} | ||
.catch((error) => errorHandler ? errorHandler(error) : console.error(error)); | ||
if (onCompleted) { | ||
onCompleted(); | ||
}); | ||
} | ||
return result; | ||
} | ||
static findAll({ ref, mapper, errorHandler, onCompleted }) { | ||
return ref | ||
static async findAll({ ref, mapper, errorHandler, onCompleted }) { | ||
const result = await ref | ||
.get() | ||
@@ -67,11 +67,9 @@ .then((snapshot) => snapshot.docs.map((doc) => { | ||
})) | ||
.catch((error) => errorHandler ? errorHandler(error) : console.error(error)) | ||
.finally(() => { | ||
if (!onCompleted) { | ||
return; | ||
} | ||
.catch((error) => errorHandler ? errorHandler(error) : console.error(error)); | ||
if (onCompleted) { | ||
onCompleted(); | ||
}); | ||
} | ||
return result; | ||
} | ||
} | ||
exports.FirestoreService = FirestoreService; |
import { Mapper } from '../../types'; | ||
export declare const mapToIfDefined: <T = any>(documentSnapshot: import("firebase").firestore.DocumentSnapshot | import("firebase").firestore.QueryDocumentSnapshot, mapper?: Mapper<T> | undefined) => any; | ||
import { DocumentResult } from '../../models'; | ||
export declare const mapToIfDefined: <T = any>(documentSnapshot: import("firebase").firestore.DocumentSnapshot | import("firebase").firestore.QueryDocumentSnapshot, mapper?: Mapper<T> | undefined) => DocumentResult; |
import { ActionTree } from 'vuex'; | ||
import { CriteriaOptions } from '../../criteria-options.interface'; | ||
import { CriteriaOptions } from '../../options'; | ||
import { FirestoreRef } from '../../types'; | ||
@@ -4,0 +4,0 @@ interface Criteria<T = any> { |
@@ -7,4 +7,4 @@ "use strict"; | ||
const defaultActionName = helpers_1.isDocumentRef(ref) | ||
? action_1.actionTypes.DOCUMENT_SUBSCRIBE | ||
: action_1.actionTypes.COLLECTION_SUBSCRIBE; | ||
? action_1.actionTypes.document.SUBSCRIBE | ||
: action_1.actionTypes.collection.SUBSCRIBE; | ||
const action = actionName ? actionName : defaultActionName; | ||
@@ -11,0 +11,0 @@ const tree = { |
@@ -7,4 +7,4 @@ "use strict"; | ||
const defaultActionName = type === 'document' | ||
? action_1.actionTypes.DOCUMENT_UNSUBSCRIBE | ||
: action_1.actionTypes.COLLECTION_UNSUBSCRIBE; | ||
? action_1.actionTypes.document.UNSUBSCRIBE | ||
: action_1.actionTypes.collection.UNSUBSCRIBE; | ||
const action = actionName ? actionName : defaultActionName; | ||
@@ -11,0 +11,0 @@ const tree = { |
import { Commit } from 'vuex'; | ||
import { MutationType } from '../../types'; | ||
import { Payload } from '../../models'; | ||
interface Criteria { | ||
@@ -7,5 +8,5 @@ mutationType: MutationType; | ||
commit: Commit; | ||
payload: any; | ||
payload: Payload; | ||
} | ||
export declare const fireMutation: ({ mutationType, changeType, commit, payload }: Criteria) => void; | ||
export {}; |
@@ -10,11 +10,11 @@ "use strict"; | ||
case 'added': | ||
commit(types.ADD, payload); | ||
commit(types.ADD, payload.data); | ||
break; | ||
case 'modified': | ||
commit(types.MODIFY, payload); | ||
commit(types.MODIFY, payload.data); | ||
break; | ||
default: | ||
commit(types.REMOVE, payload); | ||
commit(types.REMOVE, payload.data); | ||
break; | ||
} | ||
}; |
import { Commit } from 'vuex'; | ||
import { FirestoreRef } from '../../types'; | ||
import { CriteriaOptions } from '../../criteria-options.interface'; | ||
import { CriteriaOptions } from '../../options'; | ||
interface Criteria<T, U> { | ||
@@ -5,0 +5,0 @@ state: any; |
export declare const actionTypes: { | ||
collection: { | ||
SUBSCRIBE: string; | ||
UNSUBSCRIBE: string; | ||
}; | ||
document: { | ||
SUBSCRIBE: string; | ||
UNSUBSCRIBE: string; | ||
}; | ||
/** | ||
* @deprecated it will be removed ^2.0.0, so use `document.SUBSCRIBE` , please | ||
*/ | ||
DOCUMENT_SUBSCRIBE: string; | ||
/** | ||
* @deprecated it will be removed ^2.0.0, so use `collection.SUBSCRIBE` , please | ||
*/ | ||
COLLECTION_SUBSCRIBE: string; | ||
/** | ||
* @deprecated it will be removed ^2.0.0, so use `document.UNSUBSCRIBE` , please | ||
*/ | ||
DOCUMENT_UNSUBSCRIBE: string; | ||
/** | ||
* @deprecated it will be removed ^2.0.0, so use `collection.UNSUBSCRIBE` , please | ||
*/ | ||
COLLECTION_UNSUBSCRIBE: string; | ||
}; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.actionTypes = { | ||
collection: { | ||
SUBSCRIBE: '[firex-store] Collection Subscribe', | ||
UNSUBSCRIBE: '[firex-store] Collection Unsubscribe' | ||
}, | ||
document: { | ||
SUBSCRIBE: '[firex-store] Document Subscribe', | ||
UNSUBSCRIBE: '[firex-store] Document Unsubscribe' | ||
}, | ||
// --- deprecated, follow variables will be removed ^2.0.0 --- | ||
/** | ||
* @deprecated it will be removed ^2.0.0, so use `document.SUBSCRIBE` , please | ||
*/ | ||
DOCUMENT_SUBSCRIBE: '[firex-store] Document Subscribe', | ||
/** | ||
* @deprecated it will be removed ^2.0.0, so use `collection.SUBSCRIBE` , please | ||
*/ | ||
COLLECTION_SUBSCRIBE: '[firex-store] Collection Subscribe', | ||
/** | ||
* @deprecated it will be removed ^2.0.0, so use `document.UNSUBSCRIBE` , please | ||
*/ | ||
DOCUMENT_UNSUBSCRIBE: '[firex-store] Document Unsubscribe', | ||
/** | ||
* @deprecated it will be removed ^2.0.0, so use `collection.UNSUBSCRIBE` , please | ||
*/ | ||
COLLECTION_UNSUBSCRIBE: '[firex-store] Collection Unsubscribe' | ||
}; |
@@ -1,1 +0,1 @@ | ||
export declare type ErrorHandler = (error?: any) => void; | ||
export declare type ErrorHandler = (error?: any) => any; |
{ | ||
"name": "firex-store", | ||
"version": "0.1.2", | ||
"version": "0.2.0", | ||
"description": "subscribe firebase data to vuex", | ||
@@ -14,8 +14,6 @@ "main": "./lib/index.js", | ||
"lint": "eslint --fix \"./src/**/*.ts\"", | ||
"test": "jest --config jestconfig.json", | ||
"test": "jest", | ||
"prepare": "npm run build", | ||
"prepublishOnly": "npm test && npm run lint", | ||
"preversion": "npm run lint", | ||
"version": "npm run format && git add -A src", | ||
"postversion": "git push && git push --tags" | ||
"preversion": "npm run lint" | ||
}, | ||
@@ -40,2 +38,5 @@ "repository": { | ||
"devDependencies": { | ||
"@babel/plugin-syntax-object-rest-spread": "^7.2.0", | ||
"@babel/plugin-transform-modules-commonjs": "^7.6.0", | ||
"@babel/preset-typescript": "^7.6.0", | ||
"@types/jest": "^24.0.18", | ||
@@ -45,2 +46,4 @@ "@typescript-eslint/eslint-plugin": "^2.2.0", | ||
"@vue/test-utils": "^1.0.0-beta.29", | ||
"babel-plugin-transform-object-rest-spread": "^6.26.0", | ||
"babel-preset-env": "^1.7.0", | ||
"eslint": "^6.3.0", | ||
@@ -47,0 +50,0 @@ "eslint-config-prettier": "^6.3.0", |
@@ -8,4 +8,5 @@ # firex-store | ||
- It is influenced by [vuexfire](https://github.com/vuejs/vuefire) | ||
- node v10 ~ | ||
- node v8.9.4 ~ | ||
## Installation | ||
@@ -27,4 +28,2 @@ | ||
- This npm library methods use only one 'document' and 'collection' type in one store module | ||
- A store module cannot subscribe to more than one 'collection' and 'document' | ||
@@ -41,3 +40,3 @@ | ||
- [Fetch at Once](#5-fetch-at-once) | ||
- [Options](#Options) | ||
- [Options](#options) | ||
@@ -128,3 +127,3 @@ ### Before Start... | ||
created() { | ||
this.$store.dispatch(`comment/${actionTypes.COLLECTION_SUBSCRIBE}`) | ||
this.$store.dispatch(`comment/${actionTypes.collection.SUBSCRIBE}`) | ||
} | ||
@@ -235,3 +234,3 @@ } | ||
created() { | ||
this.$store.dispatch(`comment/${actionTypes.COLLECTION_UNSUBSCRIBE}`) | ||
this.$store.dispatch(`comment/${actionTypes.collection.UNSUBSCRIBE}`) | ||
} | ||
@@ -353,3 +352,3 @@ } | ||
mutations: { | ||
...firestoreMutations({ statePropName: 'comments', type: 'collection' }) | ||
...firestoreMutations({ statePropName: 'users', type: 'document' }) | ||
}, | ||
@@ -356,0 +355,0 @@ actions: { |
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
30600
65
547
20
367