Skip to content

Instantly share code, notes, and snippets.

@omarstreak
Created September 10, 2015 17:54
Show Gist options
  • Star 5 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save omarstreak/d0693876eedcbeef63f5 to your computer and use it in GitHub Desktop.
Save omarstreak/d0693876eedcbeef63f5 to your computer and use it in GitHub Desktop.
Thread Data Manager example
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;
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
};
}
})
);
});
});
import ThreadDataManager from './threadDataManager';
InboxSDK.load(...).then(sdk => {
sdk.registerToolbarButtonForList({
title: 'foo',
...
onClick: (event) => {
event.selectedThreadRowViews.forEach(threadRowView => {
threadDataManager.setThreadData(threadRowView.getThreadID(), /* whatever data you want */);
});
}
})
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment