From 7c2b3b0f149459a675c2377bac0ebcb7cd7cc4ac Mon Sep 17 00:00:00 2001 From: Kouts Date: Wed, 12 May 2021 01:01:38 +0300 Subject: [PATCH] feat: added delete methods --- src/pathStore.js | 6 +++++- src/vuexPathStore.js | 10 +++++++++- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/src/pathStore.js b/src/pathStore.js index b343223..ffaa9a6 100644 --- a/src/pathStore.js +++ b/src/pathStore.js @@ -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) => { @@ -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() diff --git a/src/vuexPathStore.js b/src/vuexPathStore.js index da9980c..b057883 100644 --- a/src/vuexPathStore.js +++ b/src/vuexPathStore.js @@ -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' @@ -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) } } @@ -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()