Research
Security News
Malicious npm Packages Inject SSH Backdoors via Typosquatted Libraries
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
vuex-queries
Advanced tools
Vuex-Queries helps you write query functions in Vuex
Write your queries in Vuex options:
const options = {
state: {
events: [{id: 1, author: ['a', 'b']}, {id: 2, author: ['b', 'c']}, {id: 3, author: ['c', 'a']}],
},
queries: {
getEventByAuthors (context, authors) {
return context.state.events.filter(e => authors.every(author => e.author.includes(author)))
}
}
}
Query functions receive a context object which contains store's state and getters. You can access them by context.state
or context.getters
, or using Object Destructuring feature in ES2015:
const options = {
state: {
events: [{id: 1, author: ['a', 'b']}, {id: 2, author: ['b', 'c']}, {id: 3, author: ['c', 'a']}],
},
queries: {
getEventByAuthors ({state, getters}, authors) {
return state.events.filter(e => authors.every(author => e.author.includes(author)))
}
}
}
Inside module queries, context will also contain rootState
and rootGetters
.
const options = {
state: {
events: [{id: 1, author: ['a', 'b']}, {id: 2, author: ['b', 'c']}, {id: 3, author: ['c', 'a']}],
},
computed: {
currentAuthor (state) {
return state.author[0]
}
},
modules: {
foo: {
namespaced: true,
queries: {
getEvents ({rootState, rootGetters}, authors) {
return rootState.events.filter(e => authors.concat(rootGetters.currentAuthor).every(author => e.author.includes(author)))
}
}
}
}
}
Before creating Vuex store, transform the options with supportQuery(options)
method:
import Vuex from 'vuex'
import { supportQuery } from 'vuex-queries'
const store = new Vuex.Store(supportQuery(options))
Use mapQueries(namespace, map)
method (which has the same parameters as other component binding helpers) to map component methods to query functions:
import { mapQueries } from 'vuex-queries'
export default {
methods: {
...mapQueries(['getEventByAuthors'])
},
render () {
return (
<div>
{this.getEventByAuthors(['a', 'c']).map(e => (
<p>Event: {e.id}</p>
))}
</div>
)
}
}
rootState
& rootGetters
FAQs
Vuex-Queries helps you write query functions in Vuex
We found that vuex-queries 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.
Research
Security News
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
Security News
MITRE's 2024 CWE Top 25 highlights critical software vulnerabilities like XSS, SQL Injection, and CSRF, reflecting shifts due to a refined ranking methodology.
Security News
In this segment of the Risky Business podcast, Feross Aboukhadijeh and Patrick Gray discuss the challenges of tracking malware discovered in open source softare.