-
Notifications
You must be signed in to change notification settings - Fork 39
Sample State
johnschoeman edited this page Sep 19, 2017
·
4 revisions
// entities
// -products
// -by_id
// -all_ids
// -comments
// -by_id
// -all_ids
// -reviews
// -by_id
// -all_ids
// -topics
// -by_id
// -all_ids
// -collections
// -by_id
// -all_ids
// -user details
//
// ui
// -current product: 17
// -current user: 5
// -current topic: 19
//
// session
// -user
//
// errors
// -session
// -comment form
// -new product form
// -edit product form
let state = {
entities: {
products: {
by_id: {
1: {
id: 1,
name: "Product 1 name",
headline: "Product 1 headline",
image_url: "image_url",
author_id: 11,
topics: [topic1Id, topic2Id, ...],
upvote_count: 42,
comment_count: 12,
current_user_upvoted: false,
website_url: "www.example.com",
created_at: 'date-time'
},
2: {
id: 2,
name: "Product 2 name",
headline: "Product 2 headline",
image_url: "image_url",
author_id: 17,
topics: [topic1Id, topic2Id, ...],
upvote_count: 1729,
comment_count: 1618,
current_user_upvoted: false,
website_url: "www.example.com",
created_at: 'date-time'
},
173: { //Currently viewed product
id: 173,
name: "Product 173 name",
headline: "Product 173 headline",
image_url: "image_url",
author_id: 11,
maker: { userobj },
hunter: { userobj },
topic: 'some topic',
subtopics: [1,2,3],
upvotes: 42,
current_user_upvoted: false,
product_of_the_day: 2,
website_url: "www.example.com",
related_products: [...products], //ordered at model level
featured: 'date-time',
media_urls: [url1Id, url2Id, ...], //ordered at model level
reviews: [review1Id, review2Id, ...], //ordered at model level
discussion: [comment1Id, comment2Id,...] //ordered at model level
}
},
all_ids: [1,2,173,...]
},
topics: {
by_id: {
1: {
id: 1,
title: "tech"
},
2: {
id: 2,
title: "drones"
}
},
all_ids: [1,2,...]
}
comments: {
by_id: {
1: {
id: 1,
body: "Comment 1 body",
comment_parent: { commentobj },
productId: productId
user: { userobj },
likes: 165,
link_url: "link_url",
author_is_maker: true/false
}
2: {
id: 2,
body: "comment 2 body"
...
}
},
all_ids: [1,2,...]
},
user: {
id: 17,
username: 'username',
headline: 'three word phrase',
upvotes: [post1Id, post2Id, ...],
submitted: [post17Id, post19Id, ...],
made_products: [products173Id, ...],
topics: [...topicIds],
collections_made: [...collectionIds],
followed_collections: [...collectionIds]
}
reviews: {
by_id: {
1: {
id: 1
body: "Review one",
...
}
},
all_ids: [1,2,...]
},
search: {
search_term: "mac apps",
user_results: [...userIds],
product_results: [...productIds],
collection_results: [...collectionIds]
}
},
ui: {
loading: true/false,
current_product: 173,
current_topic: 3,
current_user: 17
},
session: {
user: {
name: "current user name",
image_url: "image_url"
}
},
errors: {
session: ['must be logged in to see form'],
new_product_form: ['post name can\'t be blank'],
new_comment_form: ['comment can\'t be blank']
}
};