Closed vmenard closed 5 years ago
I try a second attempt to reproduce with the built version.
By now my first attempt is a failure reproducing your issue:
yarn add redux esm
node -r esm ./santeclair.js
import { combineReducers, createStore } from 'redux'
import { keyValue, simple } from './src'
import { mapPayload } from './src/helpers'
const path = 'data.analyse'
const mapCity = city => ({ text: city.label, ...city, }) const mapCities = cities => cities.map(mapCity)
const middlewares = { pre: [ mapPayload(/@@krf\/SET>DATA.ANALYSE>CITIES/)(mapCities), ], }
export const cities = keyValue(middlewares)({ path, key: 'value', name: 'cities', prefix: path, defaultData: [] }) export const establishments = keyValue({ path, key: 'id', name: 'establishments', prefix: path }) export const firstActs = keyValue({ path, key: 'value', name: 'firstActs', prefix: path }) export const hasConsented = simple.bool({ path, name: 'hasConsented', defaultData: false, prefix: path }) export const hasDevisChirurgie = simple.bool({ path, name: 'hasDevisChirurgie', defaultData: false, prefix: path }) export const modeConnecte = simple.bool({ path, name: 'modeConnecte', defaultData: false, prefix: path }) export const result = simple.object({ path, name: 'result', prefix: path }) export const secondActs = keyValue({ path, key: 'value', name: 'secondActs', prefix: path })
const analyse = combineReducers({ cities, establishments, firstActs, hasConsented, hasDevisChirurgie, modeConnecte, result, secondActs, })
const store = createStore(combineReducers({ data: combineReducers({ analyse, }), }))
store.dispatch({ type: 'test' }) console.log(store.getState()) console.log(cities.getAsArray(store.getState()))
- result is :
➜ k-redux-factory git:(master) ✗ node -r esm ./santeclair.js { data: { analyse: { cities: [Object], establishments: [Object], firstActs: [Object], hasConsented: false, hasDevisChirurgie: false, modeConnecte: false, result: {}, secondActs: [Object] } } } [] ➜ k-redux-factory git:(master) ✗
Second attempt, reproducing the error :
➜ k-redux-factory git:(master) ✗ node -r esm ./santeclair.js
file:///Volumes/sensitive/work/k-redux-factory/node_modules/redux/lib/redux
.js:1
Error: Reducer "cities" returned undefined during initialization. If the st
ate passed to the reducer is undefined, you must explicitly return the init
ial state. The initial state may not be undefined. If you don't want to set
a value for this reducer, you can use null instead of undefined.
at file:///Volumes/sensitive/work/k-redux-factory/node_modules/redux/li
b/redux.js:366:13
at Array.forEach (<anonymous>)
at assertReducerShape (file:///Volumes/sensitive/work/k-redux-factory/n
ode_modules/redux/lib/redux.js:359:25)
at combineReducers (file:///Volumes/sensitive/work/k-redux-factory/node
_modules/redux/lib/redux.js:422:5)
at Object.<anonymous> (file:///Volumes/sensitive/work/k-redux-factory/s
anteclair.js:28:17)
at Generator.next (<anonymous>)
➜ k-redux-factory git:(master) ✗
What I changed in code :
import { keyValue, simple } from './dist/index.es'
import { mapPayload } from './helpers/index.es'
It works with built version of helper It breaks with built version of k-redux-factory
import { keyValue, simple } from './src'
// import { mapPayload } from './src/helpers'
// import { keyValue, simple } from './dist/index.es'
import { mapPayload } from './helpers/index.es'
@vmenard I was a bug with microbundle, I upgraded it and it seems to work fine :)
https://github.com/alakarteio/k-redux-factory/pull/147
I am waiting for a review + I'll ping you when I will publish a new version.
Great thanks @fabienjuif ;)
You could maybeeee pay us a beer next time we see each other :)
@vmenard this is published (v6.0.1
)
No problem for beer :)
Hello, I would like to migrate from 5.0.2 to 6.0 but I have this error when I define a middleware with helper mapPayload. This middleware worked with v5.0.2. Please help me :) because I would like to migrate for reduce my bundle.
Thanks.
Error :
Uncaught Error: Reducer "cities" returned undefined during initialization. If the state passed to the reducer is undefined, you must explicitly return the initial state. The initial state may not be undefined. If you don't want to set a value for this reducer, you can use null instead of undefined
Example :