Parcourir la source

included CRUD and basic generators in project.

Tomislav Cvetic il y a 8 ans
Parent
commit
9467a713a7
4 fichiers modifiés avec 48 ajouts et 13 suppressions
  1. 2 0
      src/index.js
  2. 10 0
      src/project/components/model.js
  3. 17 1
      src/project/index.js
  4. 19 12
      src/project/state.js

+ 2 - 0
src/index.js

@@ -66,7 +66,9 @@ function mapStateToProps (state) {
 
 function mapDispatchToProps (dispatch) {
   const boundActionCreators = {}
+  console.log('ActionCreators', actionCreators)
   Object.keys(actionCreators).forEach(key => {
+    console.log('ActionCreators', actionCreators[key])
     boundActionCreators[`${key}Actions`] = bindActionCreators(actionCreators[key], dispatch)
   })
   console.log('Mapping dispatch to props:', dispatch, boundActionCreators)

+ 10 - 0
src/project/components/model.js

@@ -0,0 +1,10 @@
+class Project {
+  constructor (args) {
+    this.name = name
+    this.tag = tag
+    this.description = description
+    this.meta = []
+  }
+}
+
+export default Project

+ 17 - 1
src/project/index.js

@@ -12,7 +12,6 @@ import * as constants from './constants'
 import { actions, reducer, state } from './state'
 import components from './components'
 // import { createSelector } from 'reselect'
-// import { NAME } from './constants'
 // import _ from 'lodash'
 
 const filters = {
@@ -24,6 +23,23 @@ const selectors = {
   getActive: () => []
 }
 
+const meta = {
+  type: String,
+  key: String,
+  value: String,
+  options: {}
+}
+const project = {
+  _id: String,
+  tag: String,
+  name: String,
+  description: String,
+  meta: [meta],
+  _dbRequest: false,
+  _dbModified: false,
+  _localstorageRequest: false,
+  _localstorageModified: false
+}
 /* export const getAll = state => state[NAME]
 export const getActive = _.compose(filterActive, getAll)
 export const getCounts = createSelector(

+ 19 - 12
src/project/state.js

@@ -11,31 +11,38 @@
 import combineReducers from 'redux'
 import reduxCrudGen from 'redux-gen/crud'
 import reduxGen from 'redux-gen/basic'
-import { NAME, DATA } from './constants'
-// import { call, put, takeEvery } from 'redux-saga/effects'
+import { NAME } from './constants'
 
+/**
+  *
+  */
+import http from 'crud-api/http'
+import localstorage from 'crud-api/localStorage'
 const basic = reduxGen(NAME)
-const crud = reduxCrudGen(NAME)
+const db = reduxCrudGen(NAME, 'db', http)
+const local = reduxCrudGen(NAME, 'local', localstorage)
+console.log('basic, crud', basic, db, local)
 
 /** actionTypes define what actions are handeled by the reducer. */
-const actions = { ...basic.actions, ...crud.actions }
+export const actions = { ...basic.actions, ...db.actions, ...local.actions }
 console.log('State actions', actions)
 
 /** state definition */
 /** It is generally easier to not have another object here. */
-export const state = [ ...basic.state, ...crud.state ]
+export const state = { ...basic.state, ...db.state, ...local.state }
 console.log('State state', state)
 
 /** reducer is called by the redux dispatcher and handles all component actions */
 export function reducer (state = [], action) {
-  let nextState
-  nextState = basic.reducer(state, action)
-  nextState = crud.reducer(nextState, action)
+  let nextState = state
+  nextState = basic.reducer(nextState, action)
+  nextState = db.reducer(nextState, action)
+  nextState = local.reducer(nextState, action)
   return nextState
 }
 
 /** sagas are asynchronous workers (JS generators) to handle the state. */
-export const workers = crud.workers
-
-// Watcher (intercepts INCREMENT_REQUEST, dispatches INCREMENT_SUCCESS or INCREMENT_FAIL in return.)
-export const watchers = crud.watchers
+export function * saga () {
+  yield db.saga()
+  yield local.saga()
+}