From 9a3537540914cc6114b894c1fb359b41263167ee Mon Sep 17 00:00:00 2001 From: Dave Stewart Date: Wed, 4 Aug 2021 13:35:40 +0100 Subject: [PATCH] Optimise serialization code (#137) --- CHANGELOG.md | 4 ++++ package.json | 2 +- src/classes/Payload.js | 7 +++++-- src/helpers/store.js | 11 ++++++----- 4 files changed, 16 insertions(+), 8 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 47a2bd4..56875b9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,10 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html). +## [1.5.1] - 2021-08-04 +### Fixed +- Optimise serialization code + ## [1.5.0] - 2021-08-03 ### Added - Support for serialized payloads - #125 / @Heziode diff --git a/package.json b/package.json index 7fae0fa..8e51aee 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "vuex-pathify", - "version": "1.5.0", + "version": "1.5.1", "description": "Ridiculously simple Vuex setup + wiring", "main": "dist/vuex-pathify.js", "module": "dist/vuex-pathify.esm.js", diff --git a/src/classes/Payload.js b/src/classes/Payload.js index f841ae3..2a7e205 100644 --- a/src/classes/Payload.js +++ b/src/classes/Payload.js @@ -1,4 +1,4 @@ -import { isObject, setValue } from '../utils/object' +import { isPlainObject, setValue } from '../utils/object' import options from '../plugin/options' /** @@ -44,5 +44,8 @@ export default class Payload { * @see https://github.com/davestewart/vuex-pathify/pull/125 */ Payload.isSerialized = function (value) { - return isObject(value) && 'expr' in value && 'path' in value && 'value' in value + return isPlainObject(value) + && 'expr' in value + && 'path' in value + && 'value' in value } diff --git a/src/helpers/store.js b/src/helpers/store.js index 6e19bfc..b5f9fbd 100644 --- a/src/helpers/store.js +++ b/src/helpers/store.js @@ -40,12 +40,13 @@ export function makeMutations (state) { .reduce(function (obj, key) { const mutation = resolveName('mutations', key) obj[mutation] = function (state, value) { - if (Payload.isSerialized(value)) { - value = new Payload(value.expr, value.path, value.value) + if (value instanceof Payload) { + value = value.update(state[key]) } - state[key] = value instanceof Payload - ? value.update(state[key]) - : value + else if (Payload.isSerialized(value)) { + value = Payload.prototype.update.call(value, state[key]) + } + state[key] = value } return obj }, {})