123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241 |
- <!DOCTYPE html>
- <html lang="en">
- <head>
- <meta charset="utf-8">
- <title>JSDoc: Source: registermap/state.js</title>
- <script src="scripts/prettify/prettify.js"> </script>
- <script src="scripts/prettify/lang-css.js"> </script>
- <!--[if lt IE 9]>
- <script src="//html5shiv.googlecode.com/svn/trunk/html5.js"></script>
- <![endif]-->
- <link type="text/css" rel="stylesheet" href="styles/prettify-tomorrow.css">
- <link type="text/css" rel="stylesheet" href="styles/jsdoc-default.css">
- </head>
- <body>
- <div id="main">
- <h1 class="page-title">Source: registermap/state.js</h1>
-
-
- <section>
- <article>
- <pre class="prettyprint source linenums"><code>/** @module registermap */
- /**
- * state.js
- *
- * Collection of everything which has to do with state changes.
- * - actionTypes
- * - actions
- **/
- import { NAME } from './constants'
- import { registermapList, settingList } from './initialData'
- // import { call, put, takeEvery } from 'redux-saga/effects'
- /** actionTypes define what actions are handeled by the reducer. */
- export const actionTypes = {
- CREATE_SETTING: `${NAME}/CREATE_SETTING`,
- UPDATE_SETTING: `${NAME}/UPDATE_SETTING`,
- DELETE_SETTING: `${NAME}/DELETE_SETTING`,
- CREATE_REGISTERMAP: `${NAME}/CREATE_REGISTERMAP`,
- UPDATE_REGISTERMAP: `${NAME}/UPDATE_REGISTERMAP`,
- DELETE_REGISTERMAP: `${NAME}/DELETE_REGISTERMAP`,
- LOAD_SAMPLES: `${NAME}/LOAD_SAMPLES`
- }
- /** actions is an object with references to all action creators */
- function createSetting (setting) {
- return {
- type: actionTypes.CREATE_SETTING,
- setting
- }
- }
- function updateSetting (settingId, setting) {
- return {
- type: actionTypes.UPDATE_SETTING,
- settingId,
- setting
- }
- }
- function removeSetting (settingId) {
- return {
- type: actionTypes.DELETE_SETTING,
- settingId
- }
- }
- function createRegistermap (registermap) {
- return {
- type: actionTypes.CREATE_REGISTERMAP,
- registermap
- }
- }
- function updateRegistermap (registermapId, registermap) {
- return {
- type: actionTypes.UPDATE_REGISTERMAP,
- registermapId,
- registermap
- }
- }
- function removeRegistermap (registermapId) {
- return {
- type: actionTypes.DELETE_REGISTERMAP,
- registermapId
- }
- }
- function loadSamples () {
- return {
- type: actionTypes.LOAD_SAMPLES
- }
- }
- export const actions = { createSetting, updateSetting, removeSetting, createRegistermap, updateRegistermap, removeRegistermap, loadSamples }
- /** state definition */
- export const state = {
- registermap: [],
- settings: []
- }
- /** reducer is called by the redux dispatcher and handles all component actions */
- function registermapSettings (state = {}, action) {
- console.log(`Entering registermap setting reducer.`, state, action)
- switch (action.type) {
- case actionTypes.CREATE_SETTING:
- console.log(`Creating setting.`, state, action)
- return {
- ...state,
- [action.project.projectId]: action.project
- }
- case actionTypes.UPDATE_SETTING:
- console.log(`Update setting.`, state, action)
- return {
- ...state,
- [action.projectId]: action.project
- }
- case actionTypes.DELETE_SETTING:
- console.log(`Delete setting.`, state, action)
- return {
- ...state,
- [action.projectId]: null
- }
- default:
- return state
- }
- }
- function registermapAction (state = {}, action) {
- console.log(`Entering registermap reducer.`, state, action)
- switch (action.type) {
- case actionTypes.CREATE_REGISTERMAP:
- console.log(`Creating registermap.`, state, action)
- return {
- ...state,
- [action.project.projectId]: action.project
- }
- case actionTypes.UPDATE_REGISTERMAP:
- console.log(`Update registermap.`, state, action)
- const idx = state.findIndex(elem => { return (elem.id === action.registermapId) })
- console.log(`Update registermap.`, idx)
- const next = [
- ...state.slice(0, idx),
- action.registermap,
- ...state.slice(idx + 1)
- ]
- console.log(`Update registermap.`, next)
- return next
- case actionTypes.DELETE_REGISTERMAP:
- console.log(`Delete registermap.`, state, action)
- return {
- ...state,
- [action.projectId]: null
- }
- default:
- return state
- }
- }
- export function reducer (state = {}, action) {
- console.log(`Entering registermap root reducer.`, state, action)
- if (typeof action.settingId !== 'undefined') {
- return {
- ...state,
- registermap: registermapSettings(state.registermap, action)
- }
- }
- if (typeof action.registermapId !== 'undefined') {
- return {
- ...state,
- registermap: registermapAction(state.registermap, action)
- }
- }
- switch (action.type) {
- case actionTypes.LOAD_SAMPLES:
- console.log(`Loading samples.`, state, action, registermapList, settingList)
- console.log({...state, registermap: registermapList, settings: settingList})
- return {
- ...state,
- registermap: registermapList,
- settings: settingList
- }
- default:
- return state
- }
- }
- /** sagas are asynchronous workers (JS generators) to handle the state.
- // Worker
- export function * incrementAsync () {
- try {
- const data = yield call(Api.isIncrementOk)
- yield put({ type: 'INCREMENT_SUCCESS', data })
- } catch (error) {
- yield put({ type: 'INCREMENT_FAIL', error})
- }
- }
- // Watcher (intercepts INCREMENT_REQUEST, dispatches INCREMENT_SUCCESS or INCREMENT_FAIL in return.)
- export function * watchIncrementAsync () {
- yield takeEvery('INCREMENT_REQUEST', incrementAsync)
- }
- // export all sagas in parallel
- function * sagas () {
- yield takeEvery('INCREMENT_REQUEST')
- yield takeEvery('DECREMENT_REQUEST')
- } */
- export const sagas = null
- </code></pre>
- </article>
- </section>
- </div>
- <nav>
- <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>
- </nav>
- <br class="clear">
- <footer>
- 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)
- </footer>
- <script> prettyPrint(); </script>
- <script src="scripts/linenumber.js"> </script>
- </body>
- </html>
|