Skip to content

Instantly share code, notes, and snippets.

@ccapndave
Last active October 29, 2015 09:49
Show Gist options
  • Save ccapndave/35881a8ca14e7188181f to your computer and use it in GitHub Desktop.
Save ccapndave/35881a8ca14e7188181f to your computer and use it in GitHub Desktop.
Rx.Observable.prototype.sendToTimeline = function(name) {
const addToTimeline = (group, data, className) => {
items.add({
start: new Date(),
content: stringify(data),
group: group.id,
className
});
if (shouldFit) timeline.fit();
};
const setGroupClass = (group, className) => groups.update(Object.assign({}, group, { className }));
const source = this, key = this;
// Get the group (creating it if necessary)
let group;
if (!streams.has(key)) {
group = { id: cuid(), content: name };
groups.add(group);
streams.set(key, groups);
} else {
group = streams.get(key);
}
return Rx.Observable.create(o => {
return source.subscribe(
data => {
addToTimeline(group, data);
o.onNext(data);
},
err => {
addToTimeline(group, err.message, 'error');
setGroupClass(group, 'error');
o.onError(err);
},
() => {
setGroupClass(group, 'completed');
o.onCompleted();
}
);
});
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment