Skip to content

Commit

Permalink
feat: added delete methods
Browse files Browse the repository at this point in the history
  • Loading branch information
kouts committed May 11, 2021
1 parent d3aba7b commit 7c2b3b0
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
6 changes: 5 additions & 1 deletion src/pathStore.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import Vue from 'vue'
import { getByPath, isArray } from 'vue-set-path/dist/es/utils'
import { setOne, setMany } from 'vue-set-path'
import { setOne, setMany, deleteMany } from 'vue-set-path'
import { ARRAY_METHODS } from './constants.js'

const createPathStore = (state) => {
Expand All @@ -18,6 +18,10 @@ const createPathStore = (state) => {
return path ? getByPath(store, path) : store
}

store.delete = (path) => {
deleteMany(store, path)
}

ARRAY_METHODS.forEach((method) => {
store[method] = (...args) => {
const path = args.shift()
Expand Down
10 changes: 9 additions & 1 deletion src/vuexPathStore.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import Vuex from 'vuex'
import { setOne, setMany } from 'vue-set-path'
import { setOne, setMany, deleteMany } from 'vue-set-path'
import { getByPath, isArray } from 'vue-set-path/dist/es/utils'
import { ARRAY_METHODS } from './constants.js'

Expand All @@ -12,6 +12,10 @@ const createVuexPathStore = (options) => {
toggle(state, info) {
const { path } = info
setOne(state, path, !getByPath(state, path))
},
delete(state, info) {
const { path } = info
deleteMany(state, path)
}
}

Expand All @@ -38,6 +42,10 @@ const createVuexPathStore = (options) => {
store.commit('toggle', { path })
}

store.delete = (path) => {
store.commit('delete', { path })
}

ARRAY_METHODS.forEach((method) => {
store[method] = (...args) => {
const path = args.shift()
Expand Down

0 comments on commit 7c2b3b0

Please sign in to comment.