-
Notifications
You must be signed in to change notification settings - Fork 102
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Wugaoliang
committed
Dec 9, 2020
1 parent
aedf062
commit 345a814
Showing
6 changed files
with
139 additions
and
59 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,34 +1,51 @@ | ||
import _ from 'lodash' | ||
|
||
/* eslint-disable no-case-declarations */ | ||
export const FILEDS_INIT = 'FILEDS_INIT' | ||
export const FILEDS_UPDATE = 'FILEDS_UPDATE' | ||
export const FILEDS_UPDATE_VALUE = 'FILEDS_UPDATE_VALUE' | ||
export const FILEDS_REMOVE = 'FILEDS_REMOVE' | ||
export const FILEDS_INIT_LIST = 'FILEDS_INIT_LIST' | ||
export const FILEDS_UPDATE_LIST = 'FILEDS_UPDATE_LIST' | ||
const FormReducer = (state, action) => { | ||
switch (action.type) { | ||
case FILEDS_INIT: | ||
const { fields } = state | ||
const initfields = [...fields].filter((item) => { | ||
return action.payload.field !== item.field | ||
}) | ||
return Object.assign({}, { ...state }, { fields: initfields.concat(action.payload) }) | ||
case FILEDS_UPDATE: | ||
return Object.assign({}, { ...state }, { fields: [...action.payload] }) | ||
case FILEDS_REMOVE: | ||
const _fields = state.fields.filter((item) => { | ||
return action.payload !== item.field && action.payload !== item.propsField | ||
}) | ||
return Object.assign({}, { ...state }, { fields: _fields }) | ||
class Immutable { | ||
constructor() { | ||
this.state = {} | ||
} | ||
|
||
FormReducer = (state, action) => { | ||
switch (action.type) { | ||
case FILEDS_INIT: | ||
const { fields } = state | ||
const initfields = [...fields].filter((item) => { | ||
return action.payload.field !== item.field | ||
}) | ||
this.state = Object.assign({}, { ...state }, { fields: initfields.concat(action.payload) }) | ||
return this.state | ||
case FILEDS_UPDATE: | ||
return Object.assign({}, { ...state }, { fields: [...action.payload] }) | ||
case FILEDS_REMOVE: | ||
const _fields = state.fields.filter((item) => { | ||
return action.payload !== item.field && action.payload !== item.propsField | ||
}) | ||
this.state = Object.assign({}, { ...state }, { fields: _fields }) | ||
return this.state | ||
case FILEDS_INIT_LIST: | ||
const { listNames } = state | ||
!listNames.includes(action.payload) && listNames.push(action.payload) | ||
this.state = Object.assign({}, { ...state }, { listNames: listNames }) | ||
|
||
return this.state | ||
case FILEDS_UPDATE_LIST: | ||
this.state = Object.assign({}, { ...state }, { listValues: action.payload }) | ||
return this.state | ||
default: | ||
this.state = state | ||
return state | ||
} | ||
} | ||
|
||
case FILEDS_INIT_LIST: | ||
const { listNames } = state | ||
!listNames.includes(action.payload) && listNames.push(action.payload) | ||
return Object.assign({}, { ...state }, { listNames: listNames }) | ||
case FILEDS_UPDATE_LIST: | ||
return Object.assign({}, { ...state }, { listValues: action.payload }) | ||
default: | ||
return state | ||
currentStateFields() { | ||
return _.cloneDeep(this.state.fields) | ||
} | ||
} | ||
export default FormReducer | ||
export default new Immutable() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters