All Projects → whtsky → vuex-queries

whtsky / vuex-queries

Licence: BSD-3-Clause license
Vuex-Queries helps you write query functions in Vuex

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to vuex-queries

Vuex Flash
VueJs Flash Message Component within Vuex
Stars: ✭ 54 (+350%)
Mutual labels:  vuex2
Record
Vue + Nodejs + Mongodb构建的校园打卡系统,支持csv文件上传名单🚀
Stars: ✭ 94 (+683.33%)
Mutual labels:  vuex2
Bilibili Vue
前端vue+后端koa,全栈式开发bilibili首页
Stars: ✭ 2,590 (+21483.33%)
Mutual labels:  vuex2
Simple Todo Tutorial
Simple todo app built with Vue 2.0 and Vuex 2.0
Stars: ✭ 62 (+416.67%)
Mutual labels:  vuex2
Vue Admin Element
(Vue2 演示项目)物业后台管理系统 - ElementUI ( 基本结构已完成, 剩下的就是具体业务开发; 如有疑问请留言 )
Stars: ✭ 73 (+508.33%)
Mutual labels:  vuex2
Vue2admin
基于vue2 + vue-router + vuex + fetch + PostCSS + element-ui +webpack2 实现的一个后台管理系统基础框架。
Stars: ✭ 126 (+950%)
Mutual labels:  vuex2
Manhuaren
vue2.0全家桶,仿漫画人官网(移动端)
Stars: ✭ 18 (+50%)
Mutual labels:  vuex2
Shangchao-Website
(官网案例) - 上朝科技 - Vue 2.0 - SPA项目
Stars: ✭ 22 (+83.33%)
Mutual labels:  vuex2
Vue2 Qq
一个基于兴趣,为了学习,提高能力的项目
Stars: ✭ 90 (+650%)
Mutual labels:  vuex2
Paascloud Login Web
模拟商城,完整的购物流程、后端运营平台,使用 spring cloud + vue 全家桶实现快速搭建企业级微服务项目
Stars: ✭ 207 (+1625%)
Mutual labels:  vuex2
Vue Cnode
基于vue2 + vue-router + vuet + ES6 + less + flex.css重写vue版cnode社区,使用webpack2打包
Stars: ✭ 1,134 (+9350%)
Mutual labels:  vuex2
Vbox
vue实现的音乐Web App
Stars: ✭ 73 (+508.33%)
Mutual labels:  vuex2
Vue Admin Manager
整合 vue,element,echarts,video,bootstrap(AdminLTE),admin等,搭建的后台管理系统
Stars: ✭ 153 (+1175%)
Mutual labels:  vuex2
Vue Shopping Clean Architecture
Shopping cart app demonstrate clean architecture
Stars: ✭ 60 (+400%)
Mutual labels:  vuex2
Toucan
Boilerplate template using Vue.js, TypeScript and .NET Core 2.1, based on SOLID design principles
Stars: ✭ 215 (+1691.67%)
Mutual labels:  vuex2
Vue Entity Adapter
Package to maintain entities in Vuex.
Stars: ✭ 20 (+66.67%)
Mutual labels:  vuex2
Vue2 Element
基于vue2 + vue-router2 + element-ui + vuex2 + fetch + webpack2 企业级后台管理系统最佳实践
Stars: ✭ 112 (+833.33%)
Mutual labels:  vuex2
vue2-element
基于vue2 + vue-router2 + element-ui + vuex2 + fetch + webpack2 企业级后台管理系统最佳实践
Stars: ✭ 115 (+858.33%)
Mutual labels:  vuex2
Vue Cnode
🔥Vue.js打造一个开源的CNode社区。CNode by Vue.js
Stars: ✭ 249 (+1975%)
Mutual labels:  vuex2
Spring Boot Vue Bank
我,请始皇[打钱]是一个前后端分离的工具人系统,项目采用 SpringBoot+Go+Vue 开发,项目加入常见的企业级应用所涉及到的技术点,例如 Redis、RabbitMQ 等(主要是多用用工具多踩踩坑)。
Stars: ✭ 157 (+1208.33%)
Mutual labels:  vuex2

Vuex-Queries

Build Status JavaScript Style Guide codecov NPM version FOSSA Status

Vuex-Queries helps you write query functions in Vuex

Usage

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>
    )
  }
}

Changelog

v1.1.1

  • update peerDependencies to allow work with Vuex 3.x

v1.1.0

  • Add support for rootState & rootGetters

License

FOSSA Status

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].