moving lexdata to redux store - wip

master
Malar Kannan 2017-07-13 19:06:47 +05:30
parent 2aa2cf1c83
commit c32fea2881
7 changed files with 29 additions and 9 deletions

View File

@ -8,7 +8,7 @@ import { walleStore } from './WallEStore';
import { Header, Icon, Segment } from 'semantic-ui-react';
function mapStateToProps(state: any) {
return {...state};
return state;
}
function mapDispachToProps(dispatch: any) {

View File

@ -16,14 +16,14 @@ export class LexEditor extends React.Component<any, any> {
.filter((q: any) => _.get<any>(q, searchLens, '') === searchText)
.take(10)
.value();
let { fieldMetaMap: fieldMetaMap, save: save } = this.props;
return (
<div>
<LexSearch
{...this.props}
{...{ fieldMetaMap: this.props.fieldMetaMap }}
/>
<LexMatches
{...{ fieldMetaMap: this.props.fieldMetaMap }}
{...{ fieldMetaMap, save }}
matchedEntries={matchedEntries}
selectionMeta={this.props.selectFields}
searchText={searchText}
@ -82,7 +82,7 @@ function LexMatches(params: any) {
let uniqueKey = mObj.guid[0] + '#' + mObj.$.id;
return (
<LexEdit
{...{ fieldMetaMap: props.fieldMetaMap }}
{...props}
key={uniqueKey}
lexItem={mObj}
selectionMeta={props.selectionMeta}
@ -93,7 +93,7 @@ function LexMatches(params: any) {
_.set(addProps, props.searchLens, props.searchText);
let addEntry = (
<LexEdit
{...{ fieldMetaMap: props.fieldMetaMap }}
{...props}
key={props.searchText}
lexItem={addProps}
selectionMeta={props.selectionMeta}

View File

@ -103,11 +103,11 @@ export class LexEdit extends React.Component<any, any> {
let lens = this.props.fieldMetaMap[type].lens;
let { lexItem: lexItem } = this.state;
_.set(lexItem, lens, value);
console.log('setting event :', lexItem);
this.setState(lexItem);
}
private handleOnSave(event: any) {
this.props.save(this.state.lexItem);
console.log('saving object :', this.state.lexItem);
}
}

View File

@ -59,8 +59,9 @@ export class LexSetup extends React.Component<any, any> {
}));
return [lang, langOpts];
}));
this.props.addXmlData(lexData);
this.setState({
lexData, allEntries, selectFields, fieldMetaMap
allEntries, selectFields, fieldMetaMap
});
});
})

View File

@ -2,7 +2,8 @@ import { createStore } from 'redux';
import rootReducer from './reducers';
const defaultState = {
searchState: { searchValue: 'just', searchType: 'label' }
searchState: { searchValue: 'just', searchType: 'label' },
xmlData: []
};
const devToolsKey = '__REDUX_DEVTOOLS_EXTENSION__';

View File

@ -13,6 +13,13 @@ export function searchForValue(searchValue: any) {
};
}
export function addXmlData(xmlData: any) {
return {
type: 'ACTION_XML_DATA',
xmlData
};
}
export function save(lexItem: any) {
return {
type: 'ACTION_SAVE_LEXITEM',

View File

@ -24,7 +24,18 @@ function save(state: any = {}, action: any) {
return state;
}
function addXmlData(state: any = {}, action: any) {
if (action.type === 'ACTION_XML_DATA') {
return action.xmlData;
}
return state;
}
const searchReducer = combineReducers({ searchValue, searchType });
const rootReducer = combineReducers({ searchState: searchReducer, save });
const rootReducer = combineReducers({
searchState: searchReducer,
save,
xmlData: addXmlData
});
export default rootReducer;