0

I am building an app with React + Redux + Immutable JS and am running into some architectural problems. To illustrate I will use my user record as an example. The user object is an Immutable Record, defined in the user reducer. Now I would like to define some methods for this user (for example, isCurrentUser(userId), which would return a boolean and can be called on any user instance). From what I gather, the state should simply be plain objects though (reference: How to put methods onto the objects in Redux state?)

However, since this method wouldn't change the state of the application it doesn't make sense to use the typical Redux flow either. Is it acceptable for me to define methods within my Immutable Records, or should I be defining some helper methods in a separate JS file. Or maybe there's something else I haven't thought of?

Community
  • 1
  • 1
Nicholas Haley
  • 3,558
  • 3
  • 29
  • 50

1 Answers1

1

You can create a new layer called 'services' and put this methods inside it. So, you can have a services/UserSession that is used like.:

{ isCurrentUser } from './services/UserSession'

isCurrentUser(user)

Does it help you?

Bruno Quaresma
  • 9,457
  • 7
  • 32
  • 50