Jared Anderson
Mike Jasper
ICS Stack Team
2 "page"
Lorem Ipsum?
Mollit nulla deserunt?
Laborum in reprehenderit?
Lorem Ipsum?
Minim Lorem culpa?
Home - Question List
"page" 1
Answer 1
Answer 2
Answer 3
5
3
2
Lorem Ipsum?
Answer 1
Answer 2
Answer 3
Question
"page" 2
App
API
rest & socket.io
render in browser
render on server
App
API
rest endpoints
db
local app state
UI components
socket endpoints
service clients
JSON
between app and api
[
{
"id": "5694c574-0348-45dd-bde0-2e05563712fe",
"question": "What's your favorite America?"
},
{
"id": "5e0ca5e0-d31c-418f-a4eb-79747d03d6fd",
"question": "Where should we go to lunch?"
},
{
"id": "6fed2bae-4325-4e2b-8c93-0662d8dcd682",
"question": "Would you like fries with that?"
},
{
"id": "2c703db8-3912-4690-a553-5dfb59269a6d",
"question": "Who would win in a fight?"
}
]
GET /v1/questions/list
{
"id": "5e0ca5e0-d31c-418f-a4eb-79747d03d6fd",
"options": [
{
"id": 0,
"responses": 0,
"text": "Cubbies"
},
{
"id": 1,
"responses": 0,
"text": "Lonestar"
},
{
"id": 2,
"responses": 0,
"text": "J & C"
},
{
"id": 3,
"responses": 0,
"text": "SmashBurger"
},
{
"id": 4,
"responses": 1,
"text": "The Pie"
}
],
"question": "Where should we go to lunch?"
}
GET /v1/questions/:id
[
{
"option": 1,
"question": "6fed2bae-4325-4e2b-8c93-0662d8dcd682",
"user": "14289a42-13fc-452c-9c72-328b75c6b1b3"
}
]
GET /v1/answers/user/:id
{
"user": "bcdf879d-6fc1-4186-8062-85ca42c8cc93",
"option": 0
}
POST /v1/questions/:id/answers
{
"type": "delete",
"data": {
"id": "74d6f9c2-44d9-4146-aa40-000d08e06a82",
"option": 4,
"question": "5e0ca5e0-d31c-418f-a4eb-79747d03d6fd",
"user": "c23c8b9e-fd52-490b-a940-4c7bef2e7ac8"
}
}
ws /
event name: "answers.change"
{
"type": "create",
"data": {
"id": "49100db7-d5f6-4568-8e71-756494338459",
"option": 3,
"question": "5e0ca5e0-d31c-418f-a4eb-79747d03d6fd",
"user": "c23c8b9e-fd52-490b-a940-4c7bef2e7ac8"
}
}
App
API
rest endpoints
db
local app state
UI components
socket endpoints
service clients
JSON
You Are Here
UI components
=
let's build this
Answer 1
Answer 2
Answer 3
5
3
2
Lorem Ipsum?
Answer 1
Answer 2
Answer 3
Question
"page" 2
Answer 1
Answer 2
Answer 3
5
3
2
the <BarChart/> component
the other components
<HomeLayout
questions={[
{
text: "Quis ut amet excepteur exercitation incididunt ?",
href: "#123",
size: 1
},
{
text: "Aute aliquip proident sunt ipsum reprehenderit elit?",
href: "#123",
size: 3
},
{
text: "Nisi consectetur ex magna id?",
href: "#123",
size: 2
}
]}
/>
<QuestionLayout
id={1234}
text="Pick a number between 1 and 4?"
name="test"
options={[
{ id: 1, value: 1, label: "One", qty: 7 },
{ id: 2, value: 2, label: "Two", qty: 5 },
{ id: 3, value: 3, label: "Three", qty: 2 },
{ id: 4, value: 4, label: "Four", qty: 6 }
]}
onVote={action("Changed")}
/>
App
API
rest endpoints
db
local app state
UI components
socket endpoints
service clients
JSON
You Are Here
Data Explorer
Show Tables
CRUD example
Show `.update()` functionality
show our data models
API: /src/libs/models/db.js
src/routes/questions.js
GET /v1/questions/list
api
src/routes/questions.js
GET /v1/questions/:id
api
src/routes/questions.js
POST /v1/questions/:id
api
API: /src/routes/answers.js
API: /src/server.js
data retrieval
App
API
rest endpoints
db
local app state
UI components
socket endpoints
service clients
JSON
You Are Here
src/app/services/
jump to 06-services
templates/
a predictable state container for JavaScript apps
App
API
rest endpoints
db
local app state
UI components
socket endpoints
service clients
JSON
You Are Here
single source of truth
state is read-only
derived new state
const {questions} = store.getState()
(state=0, {type}) => {
switch (type) {
case INCREMENT:
return state+1;
default:
return state
}
change requests dispatched
store.dispatch({type: INCREMENT})
subscribe to changes
store.subscribe( () =>
store.getState()
)
questions.addAnswer(1);
Redux offers a tradeoff. It asks you to:
In return:
potentially more boilerplate & indirection, but generally worth it :)
RECEIVE_MY_ANSWERS RECEIVE_ANSWER_TALLY RECEIVE_ANSWER_INCREMENT RECEIVE_ANSWER_DECREMENT
RECEIVE_QUESTION_SUMMARY RECEIVE_FULL_QUESTION
RECEIVE_USER_PROFILE
(events) that change our app state
src/app/store/constants.js
jump to 07-store-constants
src/app/store/reducers/questions.js
src/app/store/index.js
demo
{
type: 'RECEIVE_QUESTION_SUMMARY',
payload: {
id: 1234,
question: "Where should we go to lunch?"
}
}
src/app/store/actions/questions.js (part 1)
src/app/store/reducers/user-profile.js
src/app/store/reducers/answers.js
src/app/store/index.js
11-actions-almost-finish
src/app/store/actions/user-profile.js
src/app/store/actions/answers.js
src/app/containers/app.js
src/app/containers/home.js
13-home-container
src/app/store/actions/questions.js*
src/app/containers/app.js*
src/app/containers/question.js
src/app/routes.js*
http://10.228.251.173:8888
if things went badly...