Skip to content

Commit

Permalink
Optimise serialization code (#137)
Browse files Browse the repository at this point in the history
  • Loading branch information
davestewart authored Aug 4, 2021
1 parent 858a385 commit 9a35375
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 8 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
7 changes: 5 additions & 2 deletions src/classes/Payload.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { isObject, setValue } from '../utils/object'
import { isPlainObject, setValue } from '../utils/object'
import options from '../plugin/options'

/**
Expand Down Expand Up @@ -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
}
11 changes: 6 additions & 5 deletions src/helpers/store.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
}, {})
Expand Down

0 comments on commit 9a35375

Please sign in to comment.