Skip to content

Instantly share code, notes, and snippets.

@kenwheeler
Created May 10, 2016 20:34
Show Gist options
  • Save kenwheeler/fee35124fab4f383f1edeeaebfee0f50 to your computer and use it in GitHub Desktop.
Save kenwheeler/fee35124fab4f383f1edeeaebfee0f50 to your computer and use it in GitHub Desktop.
// thunk
export function save(filename, notebook) {
return (subject) => {
// If there isn't a filename, save-as it instead
if (!filename) {
throw new Error('save needs a filename');
}
subject.next({
type: constants.START_SAVING,
});
writeFile(filename, JSON.stringify(commutable.toJS(notebook), null, 2), (err) => {
if (err) {
console.error(err);
throw err;
}
subject.next({
type: constants.DONE_SAVING,
});
});
};
}
//test
it('emits a done action', (done) => {
let subject = new Rx.Subject();
let thunk = actions.save('test.js');
subject
.skip(1)
.subscribe((action) => {
expect(action).to.deep.equal({
type: constants.DONE_SAVING
});
done();
});
thunk(subject);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment