Skip to content

Commit

Permalink
Allow namespaced child components on ResourceIndexRoot (eg. posts.Rec…
Browse files Browse the repository at this point in the history
…ord)
  • Loading branch information
SeanRoberts committed Apr 8, 2016
1 parent 2e87872 commit 0e4ef08
Showing 1 changed file with 16 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,19 @@ import { connect } from 'react-redux';
import { bindActionCreators } from 'redux';
import actionCreators from '../actions/index';

const resolvePath = function(path, obj, safe) {
return path.split('.').reduce(function(prev, curr) {
let retVal;

if (!safe) {
retVal = prev[curr];
} else {
retVal = prev ? prev[curr] : undefined;
}
return retVal;
}, obj || self);
};

const DEFAULT_CHILD_COMPONENT_NAMES = {
AddButton: 'DefaultAddButton',
ActionButtons: 'DefaultActionButtons',
Expand Down Expand Up @@ -50,11 +63,11 @@ class Wrapper extends Component {
...DEFAULT_CHILD_COMPONENT_NAMES,
...this.props.childComponentNames
};
let name;
let component;

Object.keys(names).forEach((key) => {
name = names[key];
this.props.childComponents[key] = window.ResourceIndexComponents[name];
component = resolvePath(names[key], window.ResourceIndexComponents);
this.props.childComponents[key] = component;
});
}

Expand Down

0 comments on commit 0e4ef08

Please sign in to comment.