registermap_state.js.html 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="utf-8">
  5. <title>JSDoc: Source: registermap/state.js</title>
  6. <script src="scripts/prettify/prettify.js"> </script>
  7. <script src="scripts/prettify/lang-css.js"> </script>
  8. <!--[if lt IE 9]>
  9. <script src="//html5shiv.googlecode.com/svn/trunk/html5.js"></script>
  10. <![endif]-->
  11. <link type="text/css" rel="stylesheet" href="styles/prettify-tomorrow.css">
  12. <link type="text/css" rel="stylesheet" href="styles/jsdoc-default.css">
  13. </head>
  14. <body>
  15. <div id="main">
  16. <h1 class="page-title">Source: registermap/state.js</h1>
  17. <section>
  18. <article>
  19. <pre class="prettyprint source linenums"><code>/** @module registermap */
  20. /**
  21. * state.js
  22. *
  23. * Collection of everything which has to do with state changes.
  24. * - actionTypes
  25. * - actions
  26. **/
  27. import { NAME } from './constants'
  28. import { registermapList, settingList } from './initialData'
  29. // import { call, put, takeEvery } from 'redux-saga/effects'
  30. /** actionTypes define what actions are handeled by the reducer. */
  31. export const actionTypes = {
  32. CREATE_SETTING: `${NAME}/CREATE_SETTING`,
  33. UPDATE_SETTING: `${NAME}/UPDATE_SETTING`,
  34. DELETE_SETTING: `${NAME}/DELETE_SETTING`,
  35. CREATE_REGISTERMAP: `${NAME}/CREATE_REGISTERMAP`,
  36. UPDATE_REGISTERMAP: `${NAME}/UPDATE_REGISTERMAP`,
  37. DELETE_REGISTERMAP: `${NAME}/DELETE_REGISTERMAP`,
  38. LOAD_SAMPLES: `${NAME}/LOAD_SAMPLES`
  39. }
  40. /** actions is an object with references to all action creators */
  41. function createSetting (setting) {
  42. return {
  43. type: actionTypes.CREATE_SETTING,
  44. setting
  45. }
  46. }
  47. function updateSetting (settingId, setting) {
  48. return {
  49. type: actionTypes.UPDATE_SETTING,
  50. settingId,
  51. setting
  52. }
  53. }
  54. function removeSetting (settingId) {
  55. return {
  56. type: actionTypes.DELETE_SETTING,
  57. settingId
  58. }
  59. }
  60. function createRegistermap (registermap) {
  61. return {
  62. type: actionTypes.CREATE_REGISTERMAP,
  63. registermap
  64. }
  65. }
  66. function updateRegistermap (registermapId, registermap) {
  67. return {
  68. type: actionTypes.UPDATE_REGISTERMAP,
  69. registermapId,
  70. registermap
  71. }
  72. }
  73. function removeRegistermap (registermapId) {
  74. return {
  75. type: actionTypes.DELETE_REGISTERMAP,
  76. registermapId
  77. }
  78. }
  79. function loadSamples () {
  80. return {
  81. type: actionTypes.LOAD_SAMPLES
  82. }
  83. }
  84. export const actions = { createSetting, updateSetting, removeSetting, createRegistermap, updateRegistermap, removeRegistermap, loadSamples }
  85. /** state definition */
  86. export const state = {
  87. registermap: [],
  88. settings: []
  89. }
  90. /** reducer is called by the redux dispatcher and handles all component actions */
  91. function registermapSettings (state = {}, action) {
  92. console.log(`Entering registermap setting reducer.`, state, action)
  93. switch (action.type) {
  94. case actionTypes.CREATE_SETTING:
  95. console.log(`Creating setting.`, state, action)
  96. return {
  97. ...state,
  98. [action.project.projectId]: action.project
  99. }
  100. case actionTypes.UPDATE_SETTING:
  101. console.log(`Update setting.`, state, action)
  102. return {
  103. ...state,
  104. [action.projectId]: action.project
  105. }
  106. case actionTypes.DELETE_SETTING:
  107. console.log(`Delete setting.`, state, action)
  108. return {
  109. ...state,
  110. [action.projectId]: null
  111. }
  112. default:
  113. return state
  114. }
  115. }
  116. function registermapAction (state = {}, action) {
  117. console.log(`Entering registermap reducer.`, state, action)
  118. switch (action.type) {
  119. case actionTypes.CREATE_REGISTERMAP:
  120. console.log(`Creating registermap.`, state, action)
  121. return {
  122. ...state,
  123. [action.project.projectId]: action.project
  124. }
  125. case actionTypes.UPDATE_REGISTERMAP:
  126. console.log(`Update registermap.`, state, action)
  127. const idx = state.findIndex(elem => { return (elem.id === action.registermapId) })
  128. console.log(`Update registermap.`, idx)
  129. const next = [
  130. ...state.slice(0, idx),
  131. action.registermap,
  132. ...state.slice(idx + 1)
  133. ]
  134. console.log(`Update registermap.`, next)
  135. return next
  136. case actionTypes.DELETE_REGISTERMAP:
  137. console.log(`Delete registermap.`, state, action)
  138. return {
  139. ...state,
  140. [action.projectId]: null
  141. }
  142. default:
  143. return state
  144. }
  145. }
  146. export function reducer (state = {}, action) {
  147. console.log(`Entering registermap root reducer.`, state, action)
  148. if (typeof action.settingId !== 'undefined') {
  149. return {
  150. ...state,
  151. registermap: registermapSettings(state.registermap, action)
  152. }
  153. }
  154. if (typeof action.registermapId !== 'undefined') {
  155. return {
  156. ...state,
  157. registermap: registermapAction(state.registermap, action)
  158. }
  159. }
  160. switch (action.type) {
  161. case actionTypes.LOAD_SAMPLES:
  162. console.log(`Loading samples.`, state, action, registermapList, settingList)
  163. console.log({...state, registermap: registermapList, settings: settingList})
  164. return {
  165. ...state,
  166. registermap: registermapList,
  167. settings: settingList
  168. }
  169. default:
  170. return state
  171. }
  172. }
  173. /** sagas are asynchronous workers (JS generators) to handle the state.
  174. // Worker
  175. export function * incrementAsync () {
  176. try {
  177. const data = yield call(Api.isIncrementOk)
  178. yield put({ type: 'INCREMENT_SUCCESS', data })
  179. } catch (error) {
  180. yield put({ type: 'INCREMENT_FAIL', error})
  181. }
  182. }
  183. // Watcher (intercepts INCREMENT_REQUEST, dispatches INCREMENT_SUCCESS or INCREMENT_FAIL in return.)
  184. export function * watchIncrementAsync () {
  185. yield takeEvery('INCREMENT_REQUEST', incrementAsync)
  186. }
  187. // export all sagas in parallel
  188. function * sagas () {
  189. yield takeEvery('INCREMENT_REQUEST')
  190. yield takeEvery('DECREMENT_REQUEST')
  191. } */
  192. export const sagas = null
  193. </code></pre>
  194. </article>
  195. </section>
  196. </div>
  197. <nav>
  198. <h2><a href="index.html">Home</a></h2><h3>Modules</h3><ul><li><a href="module-AutoMate.html">AutoMate</a></li><li><a href="module-demo_module.html">demo_module</a></li><li><a href="module-demo_module_components_index.html">demo_module/components/index</a></li><li><a href="module-demo_module_constants.html">demo_module/constants</a></li><li><a href="module-demo_module_initialData.html">demo_module/initialData</a></li><li><a href="module-demo_module_state.html">demo_module/state</a></li><li><a href="module-project.html">project</a></li><li><a href="module-project_components.html">project/components</a></li><li><a href="module-project_state.html">project/state</a></li><li><a href="module-registermap.html">registermap</a></li></ul>
  199. </nav>
  200. <br class="clear">
  201. <footer>
  202. Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.4.3</a> on Tue Mar 14 2017 18:34:23 GMT+0100 (W. Europe Standard Time)
  203. </footer>
  204. <script> prettyPrint(); </script>
  205. <script src="scripts/linenumber.js"> </script>
  206. </body>
  207. </html>