Permalink
Browse files

Fix issue with post details navigation and refactor

  • Loading branch information...
MrLeebo committed Oct 13, 2017
1 parent 08ee928 commit f7ef0ced8aa022bfa32e8fce38ea235cdce110ab
@@ -2,7 +2,6 @@ import React, { Component } from 'react'
import { connect } from 'react-redux'
import { Link } from 'react-router-dom'
import resources from '../lib/resources'
const { posts } = resources
const source = 'https://github.com/MrLeebo/redux-supermodel/blob/master/example/src/components/PostDetailPage.js'
const documentation = 'https://github.com/MrLeebo/redux-supermodel/blob/master/docs/api.md#resources'
@@ -73,14 +72,14 @@ export class PostDetailPage extends Component {
}
export function mapProps (state) {
const { ready, error, payload } = posts(state)
const { ready, error, payload } = resources.post(state)
const { data: { id, title, body } = {} } = payload
return { ready, error, id, title, body }
}
const actions = {
fetch: id => posts.fetch({id}),
reset: posts.reset,
fetch: id => resources.post.fetch({id}),
reset: resources.post.reset,
}
export default connect(mapProps, actions)(PostDetailPage)
@@ -2,7 +2,6 @@ import React, { Component } from 'react'
import { connect } from 'react-redux'
import { Link } from 'react-router-dom'
import resources from '../lib/resources'
const { posts } = resources
const source = 'https://github.com/MrLeebo/redux-supermodel/blob/master/example/src/components/PostListPage.js'
const documentation = 'https://github.com/MrLeebo/redux-supermodel/blob/master/docs/api.md#resources'
@@ -59,13 +58,13 @@ export class PostListPage extends Component {
}
export function mapProps (state) {
const { ready, error, payload: { data } } = posts(state)
const { ready, error, payload: { data } } = resources.posts(state)
return { ready, error, data: data || [] }
}
const actions = {
fetch: posts.fetch,
reset: posts.reset,
fetch: resources.posts.fetch,
reset: resources.posts.reset,
}
export default connect(mapProps, actions)(PostListPage)
@@ -3,7 +3,6 @@ import { connect } from 'react-redux'
import './TodoList.css'
import TodoListTableRow from './TodoListTableRow'
import resources from '../lib/resources'
const { todos } = resources
const source = 'https://github.com/MrLeebo/redux-supermodel/blob/master/example/src/components/TodoListPage.js'
const documentation = 'https://github.com/MrLeebo/redux-supermodel/blob/master/docs/api.md'
@@ -112,16 +111,16 @@ export class TodoListPage extends Component {
}
export function mapProps (state) {
const { busy, error, payload: { data = [] } } = todos(state)
const { busy, error, payload: { data = [] } } = resources.todos(state)
return { busy, error, data }
}
const actions = {
fetch: todos.fetch,
update: todos.update,
toggle: todo => todos.update({ ...todo, completed: !todo.completed }),
destroy: todos.destroy,
reset: todos.reset,
fetch: resources.todos.fetch,
update: resources.todos.update,
toggle: todo => resources.todos.update({ ...todo, completed: !todo.completed }),
destroy: resources.todos.destroy,
reset: resources.todos.reset,
}
export default connect(mapProps, actions)(TodoListPage)
@@ -3,7 +3,8 @@ import { createClient, collectionTransform } from 'redux-supermodel'
const client = createClient('https://jsonplaceholder.typicode.com')
export default client({
posts: { urlRoot: 'posts' },
post: { urlRoot: 'posts' },
posts: { url: 'posts' },
todos: { urlRoot: 'todos', transform: collectionTransform },
users: true,
})
View

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.

0 comments on commit f7ef0ce

Please sign in to comment.