Created
September 10, 2015 17:54
-
-
Save omarstreak/d0693876eedcbeef63f5 to your computer and use it in GitHub Desktop.
Thread Data Manager example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Kefir from 'kefir'; | |
class ThreadDataManager { | |
constructor(){ | |
Kefir.stream(emitter => {this._emitter = emitter; return () => null}); | |
this._threadData = {}; //map from threadID to thread data | |
} | |
setThreadData(threadID, data){ | |
this._threadData[threadID] = data; | |
this._emitter.emit({threadID, data}); | |
} | |
getThreadData(threadID){ | |
return this._threadData[threadID]; | |
} | |
getThreadStream(threadID){ | |
return this._emitter.filter(event => event.threadID === threadID); | |
} | |
} | |
var threadDataManager = new ThreadDataManager(); | |
export default threadDataManager; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import ThreadDataManager from './threadDataManager'; | |
InboxSDK.load(...).then(sdk => { | |
sdk.registerThreadRowViewHandler(threadRowView => { | |
var threadID = threadRowView.getThreadID(); | |
threadRowView.addButton( | |
ThreadDataManager.getThreadStream(threadID) | |
.toProperty(() => ThreadDataManager.getThreadData(threadID)) /* start the stream off with data */ | |
.map(threadData => { | |
if(!threadData){ | |
return null; /* clears out the button from the threadRowView */ | |
} | |
else{ | |
return { | |
iconUrl: '', | |
iconClass: '', | |
onClick: () => console.log('hi'), | |
hasDropdown: false | |
}; | |
} | |
}) | |
); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment