Skip to content

Commit

Permalink
move computed values to server
Browse files Browse the repository at this point in the history
  • Loading branch information
markbrown4 committed May 24, 2015
1 parent f61fba1 commit d32411e
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 15 deletions.
2 changes: 2 additions & 0 deletions app/coffee/components/shared/drop_down.cjsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ App.Components.DropDown = React.createClass
open: false

toggle: (event)->
event.stopPropagation()

@setState open: !@state.open

render: ->
Expand Down
16 changes: 1 addition & 15 deletions app/coffee/stores/thread_store.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -10,23 +10,9 @@ App.Stores.ThreadStore = ThreadStore = App.createStore
allSelected: allSelected()
someSelected: someSelected()

updateComputedProperties = (data)->
for thread in data
thread.unread = _.some thread.messages, (m)-> m.unread

participants = []
for message in thread.messages
participants.push message.from
for person in message.to
participants.push person

thread.participants = _.uniq participants, (p)-> p.id

data

loadThreadsSuccess = (data)->
activeThread = null
threads = updateComputedProperties(data)
threads = data
paging =
from: 1
to: data.length
Expand Down
44 changes: 44 additions & 0 deletions db.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,23 @@
"threads": [
{
"id": 1,
"unread": false,
"participants": [
{
"id": 2,
"firstName": "Beatrix",
"lastName": "Kiddo",
"email": "[email protected]",
"avatarUrl": "/images/avatars/uma.jpg"
},
{
"id": 1,
"firstName": "Mark",
"lastName": "Brown",
"email": "[email protected]",
"avatarUrl": "/images/avatars/me.jpg"
}
],
"messages": [
{
"id": 1,
Expand Down Expand Up @@ -92,6 +109,23 @@
},
{
"id": 2,
"unread": true,
"participants": [
{
"id": 3,
"firstName": "Budd",
"lastName": "",
"email": "[email protected]",
"avatarUrl": "/images/avatars/budd.jpg"
},
{
"id": 1,
"firstName": "Mark",
"lastName": "Brown",
"email": "[email protected]",
"avatarUrl": "/images/avatars/me.jpg"
}
],
"messages": [
{
"id": 3,
Expand Down Expand Up @@ -166,6 +200,16 @@
},
{
"id": 3,
"unread": true,
"participants": [
{
"id": 2,
"firstName": "Beatrix",
"lastName": "Kiddo",
"email": "[email protected]",
"avatarUrl": "/images/avatars/uma.jpg"
}
],
"messages": [
{
"id": 6,
Expand Down

0 comments on commit d32411e

Please sign in to comment.