Skip to content

Commit 9a35375

Browse files
authored
Optimise serialization code (#137)
1 parent 858a385 commit 9a35375

File tree

4 files changed

+16
-8
lines changed

4 files changed

+16
-8
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@ All notable changes to this project will be documented in this file.
55
The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
66
and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).
77

8+
## [1.5.1] - 2021-08-04
9+
### Fixed
10+
- Optimise serialization code
11+
812
## [1.5.0] - 2021-08-03
913
### Added
1014
- Support for serialized payloads - #125 / @Heziode

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "vuex-pathify",
3-
"version": "1.5.0",
3+
"version": "1.5.1",
44
"description": "Ridiculously simple Vuex setup + wiring",
55
"main": "dist/vuex-pathify.js",
66
"module": "dist/vuex-pathify.esm.js",

src/classes/Payload.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { isObject, setValue } from '../utils/object'
1+
import { isPlainObject, setValue } from '../utils/object'
22
import options from '../plugin/options'
33

44
/**
@@ -44,5 +44,8 @@ export default class Payload {
4444
* @see https://github.com/davestewart/vuex-pathify/pull/125
4545
*/
4646
Payload.isSerialized = function (value) {
47-
return isObject(value) && 'expr' in value && 'path' in value && 'value' in value
47+
return isPlainObject(value)
48+
&& 'expr' in value
49+
&& 'path' in value
50+
&& 'value' in value
4851
}

src/helpers/store.js

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -40,12 +40,13 @@ export function makeMutations (state) {
4040
.reduce(function (obj, key) {
4141
const mutation = resolveName('mutations', key)
4242
obj[mutation] = function (state, value) {
43-
if (Payload.isSerialized(value)) {
44-
value = new Payload(value.expr, value.path, value.value)
43+
if (value instanceof Payload) {
44+
value = value.update(state[key])
4545
}
46-
state[key] = value instanceof Payload
47-
? value.update(state[key])
48-
: value
46+
else if (Payload.isSerialized(value)) {
47+
value = Payload.prototype.update.call(value, state[key])
48+
}
49+
state[key] = value
4950
}
5051
return obj
5152
}, {})

0 commit comments

Comments
 (0)