gfredericks / vcr-clj

Generic IO playback for clojure
117 stars 20 forks source link

CLJS version? #30

Open mauricioszabo opened 3 years ago

mauricioszabo commented 3 years ago

Let me say: thanks a lot for this project, it's surely the best "VCR" library that I used in all of my projects!

Now, to the point: I want to port your code to CLJS. I'm thinking about a way to manually inform VCR when cassettes were changed on your local machine, so it can re-cache them again (that's needed because ClojureScript may not have synchronous file reading, for example in the browser, so it'll not be able to "record" calls that are sync).

Probably the API can be a little clumsy to use (because, again, it'll only work seamlessly on Node.JS, not on Browser targets, so a quite hard limitation) but even them, I think it'll be really useful.

Now, the question: do you want me to make this code, and then open a PR for you? Or do you prefer that I keep a fork (let's say, vcr-cljs or something) so that the code don't mix? Also, if you have any questions on how I intend to do this API, feel free to ask here.

Thanks again for this project!

gfredericks commented 3 years ago

Hello!

I can't tell from your description whether you have a use case in mind involving browsers or not.

If you're just targeting node, then I'm unopposed, but if there's some way you imagine browsers being involved then it might help to give a detailed example.

W.r.t. forking, I imagine a lot of code could be shared between the two via cljc, so keeping them together seems worth it. You'll have to put up with my slow pace for reviewing/responding though, so obviously you could make a temporary fork in the meantime if you'd like.

mauricioszabo commented 3 years ago

Right, I'm talking about both to be honest :smile:

I'll try to cut something, but the idea is that most ClojureScript development environments today (Figwheel and Shadow) have a way to start a "backend handler" like Shadow-CLJS' :dev-http -> :handler for example.

So the idea I had (I still need to check if it'll work) is that if I could, in some way, create a macro that would call this handler to get the cassetes, then pre-define them. This means that, for browser targets, VCR will need to have some way to "refresh" cassetes otherwise deleting them on the filesystem will not work at all (because the value from them will be cached).

I'll try to hack something and show you. In Node.JS file, it's indeed easier because we can always use fs.readFileSync and everything kinda works like we expect. Let me see if my idea survives some battle-test and them we can discuss further :)

gfredericks commented 3 years ago

Sounds good, I'm looking forward to seeing it.