instrument_manager.py 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. initial_state = dict(
  2. instrument_list={},
  3. connection_list={},
  4. )
  5. class ActionTypes(object):
  6. UPDATE_LIST = 'instrument_manager/UPDATE_LIST'
  7. CONNECT = 'instrument_manager/CONNECT'
  8. DISCONNECT = 'instrument_manager/DISCONNECT'
  9. class ActionCreators(object):
  10. @staticmethod
  11. def update_list():
  12. return dict(
  13. type=ActionTypes.UPDATE_LIST
  14. )
  15. @staticmethod
  16. def connect(id):
  17. return dict(
  18. type=ActionTypes.CONNECT,
  19. id=id
  20. )
  21. @staticmethod
  22. def disconnect(id):
  23. return dict(
  24. type=ActionTypes.DISCONNECT,
  25. id=id
  26. )
  27. def reducer(state=None, action=None):
  28. if state is None:
  29. state = initial_state
  30. if not (isinstance(action, dict) and 'type' in action):
  31. return state
  32. # if action['type'] == ActionTypes.UPDATE_LIST:
  33. # state = action['value']
  34. # elif action['type'] == ActionTypes.CONNECT:
  35. # state += 1
  36. # elif action['type'] == ActionTypes.DISCONNECT:
  37. # state -= 1
  38. return state
  39. if __name__ == '__main__':
  40. import unittest
  41. unittest.main()