简体   繁体   中英

function inside immutable js and redux store

I am developing an app using react, redux + immutable js.

All of my app state is in a redux store that only has immutable members. I wonder if it is allowed to have functions stored inside them. The use case I have is that I have descriptions of form elements in my state and I render them using react. Some form elements require validation so the easiest way is to just store the function inside the state. This works but I have a feeling this is some kind of bad practice. I can't seem to find anything online.

Any help is appreciated!

something like this:

Map({
  a: stuff
  b: List.of(
    ...
    // some UI form element that requires a function to validate
    Map({
      // other informations....   
      validate: value => 'success',
      ...
    })
    ...
  ),
  c: moreStuff
})

Yeah, that's generally discouraged, as it breaks abilities like time travel debugging. The Redux FAQ covers this topic:

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM