@logux/vuex
Advanced tools
Comparing version 0.4.0 to 0.5.0-beta.1
# Change Log | ||
This project adheres to [Semantic Versioning](http://semver.org/). | ||
## 0.5.0-beta.1 | ||
* Fix incorrect behavior with modules ([#26](https://github.com/logux/vuex/issues/26)) | ||
## 0.4.0 | ||
@@ -5,0 +8,0 @@ * Add `loguxComponent`, component with scoped slots ([#18](https://github.com/logux/vuex/pull/18), [#25](https://github.com/logux/vuex/pull/25)) (by Stanislav Lashmanov) |
@@ -6,3 +6,3 @@ let { createNanoEvents } = require('nanoevents') | ||
let { deepCopy } = require('../utils/deepCopy') | ||
let { deepCopy, getNestedObject } = require('../utils') | ||
@@ -130,9 +130,26 @@ function createLogux (config = { }) { | ||
function replaceState (state, actions, pushHistory) { | ||
let last = actions.length ? actions[actions.length - 1][1] : '' | ||
let newState = actions.reduceRight((prev, [action, id]) => { | ||
let changed = deepCopy(prev) | ||
let last = actions[actions.length - 1][1] | ||
if (vuexConfig.mutations[action.type]) { | ||
vuexConfig.mutations[action.type](changed, action) | ||
if (action.type in store._mutations) { | ||
let moduleName = action.type.split('/')[0] | ||
let module = getNestedObject(vuexConfig, ['modules', moduleName]) | ||
let actionTypeNamespaced = action.type.split(`${ moduleName }/`)[1] | ||
if ( | ||
module && | ||
module.namespaced && | ||
getNestedObject(module, ['mutations', actionTypeNamespaced]) | ||
) { | ||
module.mutations[actionTypeNamespaced](changed[moduleName], action) | ||
} else if ( | ||
module && | ||
getNestedObject(module, ['mutations', action.type]) | ||
) { | ||
module.mutations[action.type](changed[moduleName], action) | ||
} else { | ||
vuexConfig.mutations[action.type](changed, action) | ||
} | ||
} | ||
if (pushHistory && id === last) { | ||
@@ -203,3 +220,14 @@ stateHistory[pushHistory] = changed | ||
if (!replayed) { | ||
replaceState(deepCopy(vuexConfig.state), actions) | ||
let storeConfig = deepCopy(vuexConfig) | ||
let state = storeConfig.state || {} | ||
if (storeConfig.modules) { | ||
Object.entries(storeConfig.modules).forEach( | ||
([moduleName, module]) => { | ||
state = { ...state, [moduleName]: module.state } | ||
} | ||
) | ||
} | ||
replaceState(state, actions) | ||
} | ||
@@ -206,0 +234,0 @@ } |
{ | ||
"name": "@logux/vuex", | ||
"version": "0.4.0", | ||
"version": "0.5.0-beta.1", | ||
"description": "Vuex compatible API for Logux", | ||
@@ -5,0 +5,0 @@ "keywords": [ |
33112
18
831