Created
May 10, 2016 20:34
-
-
Save kenwheeler/fee35124fab4f383f1edeeaebfee0f50 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
// 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