First of all many thanks for your work. This library looks promising (if I can make it work). I'm just trying to read a simple JSON stub and get it into the redux store. The first part (loading the data) works fine. I can see it with a console.log in the promise:
componentDidMount() {
this.props.dispatch(setEndpointHost(''));
this.props.dispatch(setEndpointPath(''));
this.props.dispatch(readEndpoint('data/navigation.json')).then(function(data) {
console.log(data);
});
}
What it doesn't work for me is having the data in the redux store. I just get an empty container for the navigation key.
import { createStore, applyMiddleware } from 'redux';
import { syncHistoryWithStore } from 'react-router-redux';
import { browserHistory } from 'react-router';
import thunk from 'redux-thunk';
import rootReducer from './reducers/index';
const store = createStore(rootReducer, applyMiddleware(thunk));
export const history = syncHistoryWithStore(browserHistory, store);
export default store;
import React, { Component, PropTypes } from 'react';
import Category from '../components/lib/category/category';
import sidebarStyles from '../styles/partials/sidebar.scss';
import { Link } from 'react-router';
import { connect } from 'react-redux';
import { readEndpoint, setEndpointHost, setEndpointPath } from 'redux-json-api';
const defaultProps = {
};
const propTypes = {
};
class Sidebar extends Component {
componentDidMount() {
this.props.dispatch(setEndpointHost(''));
this.props.dispatch(setEndpointPath(''));
this.props.dispatch(readEndpoint('data/navigation.json')).then(function(data) {
console.log(data);
});
}
render() {
return ()
}
}
const mapStateToProps = ({ api: { navigation = { data: [] } } }) => ({ navigation });
export default connect(mapStateToProps)(Sidebar);
import { combineReducers } from 'redux';
import { routerReducer } from 'react-router-redux';
import { reducer as api } from 'redux-json-api';
import mainReducer from './mainReducer';
const rootReducer = combineReducers({mainReducer: mainReducer, api: api, routing: routerReducer});
export default rootReducer;
{
"data": {
"type": "answers",
"id": "1",
"links": {
"self": "/answers/1"
},
"relationships": {
"jokes": {
"links": {
"self": "/answers/1/relationships/jokes",
"related": "/answers/1/jokes"
},
"data": [
{
"type": "jokes",
"id": "1"
}
]
},
"weather": {
"links": {
"self": "/answers/1/relationships/weather",
"related": "/answers/1/weather"
},
"data": [
{
"type": "weather",
"id": "1"
}
]
}
}
},
"included": [
{
"type": "jokes",
"id": "1",
"attributes": {
"joke": "Did you hear about the guy whose whole left side was cut off? He's all right now."
},
"links": {
"self": "/jokes/1"
},
"relationships": {
"actions": {
"links": {
"self": "/jokes/1/relationships/actions",
"related": "/jokes/1/actions"
},
"data": [
{
"type": "actions",
"id": "ask_me_another"
},
{
"type": "actions",
"id": "noop"
}
]
}
}
},
{
"type": "actions",
"id": "ask_me_another",
"attributes": {
"type": "jokes",
"label": "ask-me-another",
"verb": "get"
},
"links": {
"self": "/actions/ask_me_another"
}
},
{
"type": "actions",
"id": "noop",
"attributes": {
"type": "jokes",
"label": "not-funny",
"verb": "get"
},
"links": {
"self": "/actions/noop"
}
},
{
"type": "weather",
"id": "1",
"attributes": {
"city": "London",
"summary": "Partly Cloudy",
"temperature": 21.09
},
"links": {
"self": "/weather/1"
},
"relationships": {
"actions": {
"links": {
"self": "/weather/1/relationships/actions",
"related": "/weather/1/actions"
},
"data": []
}
}
}
]
}