Security News
Research
Supply Chain Attack on Rspack npm Packages Injects Cryptojacking Malware
A supply chain attack on Rspack's npm packages injected cryptomining malware, potentially impacting thousands of developers.
firex-store
Advanced tools
If you use this npm, you can reference firestore data, easily
It is inspired by vuexfire
node v8.9.4 ~
npm install --save firex-store
others comming soon
Return values or state values bounded to Firestore has docId
(documentId in Firestore) property.
A store module cannot subscribe to more than one 'collection' and 'document'
If you want to subscribe again after unsubscribing 'collection', set the property of the store you want to subscribe to []
and then subscribe.
.....
firebase.initializeApp({
apiKey: [your firebase api key],
projectId: [your project id],
.....
})
export const firestore = firebase.firestore()
firestoreMutations
Ex. Subscribe collection
export default {
namespaced: true,
state: {
comments: [],
comment: null
},
mutations: {
...firestoreMutations({ statePropName: 'comments', type: 'collection' })
},
.....
}
method: firestoreSubscribeActions
argments:
Ex. Subscribe collection
// modules: comment
export default {
namespaced: true,
state: {
comments: [],
comment: null
},
mutations: {
...firestoreMutations({ statePropName: 'comments', type: 'collection' })
},
actions: {
...firestoreSubscribeActions({ ref: firestore.collection('/comments') })
}
.....
}
Ex. Subscribe collection
<script>
import { actionTypes } from 'firex-store'
export default {
name: 'Comments',
created() {
this.$store.dispatch(`comment/${actionTypes.collection.SUBSCRIBE}`)
}
}
</script>
firestoreMutations
Ex. Subscribe collection
export default {
namespaced: true,
state: {
comments: [],
comment: null
},
mutations: {
...firestoreMutations({ statePropName: 'comments', type: 'collection' })
},
.....
}
subscribeFirestore
in custom-actionssubscribeFirestore
export default {
namespaced: true,
state: {
comments: [],
comment: null
},
mutations: {
...firestoreMutations({ statePropName: 'comments', type: 'collection' })
},
actions: {
subscribe: ({ state, commit }) => {
subscribeFirestore({
state,
commit,
ref: firestore.collection('/comments'),
options
})
}
}
.....
}
Ex. Unsubscribe collection
firestoreUnsubscribeActions
in actionsmethod: firestoreUnsubscribeActions
argments:
export default {
namespaced: true,
state: {
comments: [],
comment: null
},
mutations: {
...firestoreMutations({ statePropName: 'comments', type: 'collection' })
},
actions: {
...firestoreSubscribeActions({ ref: firestore.collection('/comments') }),
...firestoreUnsubscribeActions({ type: 'collection' })
}
.....
}
<script>
import { actionTypes } from 'firex-store'
export default {
name: 'Comments',
created() {
this.$store.dispatch(`comment/${actionTypes.collection.UNSUBSCRIBE}`)
}
}
</script>
method: unsubscribeFirestore
argments:
export default {
namespaced: true,
state: {
comments: [],
comment: null
},
mutations: {
...firestoreMutations({ statePropName: 'comments', type: 'collection' })
},
actions: {
subscribe: ({ state, commit }) => {
subscribeFirestore({
state,
commit,
ref: firestore.collection('/comments'),
options
})
},
unsubscribe: ({ state }) => {
unsubscribeFirestore({
state,
type: 'collection'
})
}
}
.....
}
method: findFirestore
argments:
Return null
if data not found
EX. Call in Store Action, to fetch collection
export default {
namespaced: true,
state: {},
getters: {},
mutations: {},
actions: {
fetchComments: async ({ commit }) => {
const ref = firestore.collection('/comments')
const result = await findFirestore({ ref })
commit(***, result)
}
}
}
Options
mapper:
errorHandler
console.error(error)
onCompleted
afterMutationCalled
subscribeFirestore
and subscribeFirestoreActions
only.Ex.
const mapUser = (data) => ({
id: data.id
name: data.name
.....
})
const errorHandler = (error) => {
console.error(`[App Name]: ${error}`)
}
const onCompleted = () => {
console.log('completed!')
}
const afterMutationCalled = (payload) => {
/**
* payload = {
* data: { docId: string | null, [key: string]: any },
* isLast: boolean,
* [key: string]: any
* }
* */
console.log(payload)
}
export default {
namespaced: true,
state: {
comments: [],
comment: null
},
mutations: {
...firestoreMutations({ statePropName: 'users', type: 'document' })
},
actions: {
subscribe: ({ state, commit }) => {
subscribeFirestore({
state,
commit,
ref: firestore.collection('/users').doc('userId'),
options: {
mapper: mapUser,
errorHandler,
onCompleted,
afterMutationCalled
}
})
}
}
.....
}
FAQs
Subscribe and write firestore data, easily
The npm package firex-store receives a total of 1 weekly downloads. As such, firex-store popularity was classified as not popular.
We found that firex-store demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Research
A supply chain attack on Rspack's npm packages injected cryptomining malware, potentially impacting thousands of developers.
Research
Security News
Socket researchers discovered a malware campaign on npm delivering the Skuld infostealer via typosquatted packages, exposing sensitive data.
Security News
Sonar’s acquisition of Tidelift highlights a growing industry shift toward sustainable open source funding, addressing maintainer burnout and critical software dependencies.