浏览代码

added instrument manager.

Tomislav Cvetic 7 年之前
父节点
当前提交
1038d16f3e
共有 2 个文件被更改,包括 57 次插入2 次删除
  1. 52 0
      instrument_manager.py
  2. 5 2
      project.py

+ 52 - 0
instrument_manager.py

@@ -0,0 +1,52 @@
+initial_state = dict(
+    instrument_list={},
+    connection_list={},
+)
+
+
+class ActionTypes(object):
+    UPDATE_LIST = 'instrument_manager/UPDATE_LIST'
+    CONNECT = 'instrument_manager/CONNECT'
+    DISCONNECT = 'instrument_manager/DISCONNECT'
+
+
+class ActionCreators(object):
+    @staticmethod
+    def update_list():
+        return dict(
+            type=ActionTypes.UPDATE_LIST
+        )
+
+    @staticmethod
+    def connect(id):
+        return dict(
+            type=ActionTypes.CONNECT,
+            id=id
+        )
+
+    @staticmethod
+    def disconnect(id):
+        return dict(
+            type=ActionTypes.DISCONNECT,
+            id=id
+        )
+
+
+def reducer(state=None, action=None):
+    if state is None:
+        state = initial_state
+    if not (isinstance(action, dict) and 'type' in action):
+        return state
+    # if action['type'] == ActionTypes.UPDATE_LIST:
+    #     state = action['value']
+    # elif action['type'] == ActionTypes.CONNECT:
+    #     state += 1
+    # elif action['type'] == ActionTypes.DISCONNECT:
+    #     state -= 1
+    return state
+
+
+if __name__ == '__main__':
+    import unittest
+
+    unittest.main()

+ 5 - 2
project.py

@@ -8,6 +8,7 @@ import pydux_sqlite
 # Import modules
 import counter
 import calculate
+import instrument_manager
 
 # Define the async loop
 loop = asyncio.get_event_loop()
@@ -25,13 +26,15 @@ middleware = pydux.apply_middleware(*middleware)
 # Combine the state
 initial_state = {
     'counter': counter.initial_state,
-    'calculate': calculate.initial_state
+    'calculate': calculate.initial_state,
+    'instrument_manager': instrument_manager.initial_state
 }
 
 # Combine the reducers
 root_reducer = pydux.combine_reducers({
     'counter': counter.reducer,
-    'calculate': calculate.reducer
+    'calculate': calculate.reducer,
+    'instrument_manager': instrument_manager.reducer
 })
 
 # Create the store