Skip to content
This repository has been archived by the owner on Mar 29, 2022. It is now read-only.

drop mockfirebase for offline firebase-copy #13

Merged
merged 4 commits into from
Oct 23, 2015

Conversation

jamestalmage
Copy link
Contributor

This drops mockfirebase in favor of using an offline firebase client.

It uses firebase-copy which is simply a hack that gives you a fresh require("firebase") with all new global state. See the docs.

It immediately takes it's unique "copy" of the Firebase code and calls Firebase.goOffline(), so it never actually tries to communicate with a server. The goOffline part is really what necessitates a new copy of the code (otherwise you would have to launch firebase-server in a separate process to prevent it from taking Firebase offline globally).

There are a few downsides to this approach:

  1. There is no synchronous getData() in the standard firebase client, so I had to introduce asynchronous getSnap(), getValue(), and getExport() functions. This complicates the code base a little, as well as writing tests against it. We could probably work around this by setting the latest snap every we receive a valid write.
  2. To minimize the diff and ease the pain of the extra async calls, I elected to use generators, yield statements and the co library. This means firebase-server is broken on Node <= 4.0.0. This is solvable, either via a build step using babel, or just manually rewriting using callbacks.
  3. Since the copy is offline and will never communicate with the server, some callbacks you are accustomed to using on the client will never be fired (ref.set(data, cb) for example). There really is no reason you need that anyways, I substituted locations where that was used with setTimeout, but even that may have been unnecessary (you could probably just have synchronous statements one after the other).

In all, some further experimentation should be done. That said, this swaps out a fairly complex project that is all but abandoned for 20 lines of code. It should make staying up-to-date with new Firebase features easier (as long as those features are available on the client in "offline mode").

@urish
Copy link
Owner

urish commented Oct 22, 2015

Very clever, thanks!

I don't want to drop node 0.10 and 0.12 support, perhaps some transpilation build step could be useful. Also, we need to figure out a way to fix the test coverage code (which is currently broken). Any chance you could look into that?

Many thanks!

switches to istanbul
@jamestalmage
Copy link
Contributor Author

I fixed coverage and I reimplemented my changes to the server code in ES5 (tests are still ES6).

I elected that route over a babel build to keep the package dependency list small.

Users of Node 0.10 will also have to install bluebird (they will get a friendly error telling them so).

urish added a commit that referenced this pull request Oct 23, 2015
drop mockfirebase for offline firebase-copy
@urish urish merged commit 5b63e34 into urish:master Oct 23, 2015
@urish
Copy link
Owner

urish commented Oct 23, 2015

Amazing, thanks!

This was referenced Oct 23, 2015
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants