Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.