| 39 | } |
| 40 | |
| 41 | class SkillShareApp { |
| 42 | constructor(state, dispatch) { |
| 43 | this.dispatch = dispatch; |
| 44 | this.talkDOM = elt("div", {className: "talks"}); |
| 45 | this.talkMap = Object.create(null); |
| 46 | this.dom = elt("div", null, |
| 47 | renderUserField(state.user, dispatch), |
| 48 | this.talkDOM, |
| 49 | renderTalkForm(dispatch)); |
| 50 | this.syncState(state); |
| 51 | } |
| 52 | |
| 53 | syncState(state) { |
| 54 | if (state.talks == this.talks) return; |
| 55 | this.talks = state.talks; |
| 56 | |
| 57 | for (let talk of state.talks) { |
| 58 | let found = this.talkMap[talk.title]; |
| 59 | if (found && found.talk.presenter == talk.presenter && |
| 60 | found.talk.summary == talk.summary) { |
| 61 | found.syncState(talk); |
| 62 | } else { |
| 63 | if (found) found.dom.remove(); |
| 64 | found = new Talk(talk, this.dispatch); |
| 65 | this.talkMap[talk.title] = found; |
| 66 | this.talkDOM.appendChild(found.dom); |
| 67 | } |
| 68 | } |
| 69 | for (let title of Object.keys(this.talkMap)) { |
| 70 | if (!state.talks.some(talk => talk.title == title)) { |
| 71 | this.talkMap[title].dom.remove(); |
| 72 | delete this.talkMap[title]; |
| 73 | } |
| 74 | } |
| 75 | } |
| 76 | } |
nothing calls this directly
no outgoing calls
no test coverage detected