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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This drops
mockfirebase
in favor of using an offline firebase client.It uses
firebase-copy
which is simply a hack that gives you a freshrequire("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. ThegoOffline
part is really what necessitates a new copy of the code (otherwise you would have to launchfirebase-server
in a separate process to prevent it from taking Firebase offline globally).There are a few downsides to this approach:
getData()
in the standard firebase client, so I had to introduce asynchronousgetSnap()
,getValue()
, andgetExport()
functions. This complicates the code base a little, as well as writing tests against it. We could probably work around this by setting thelatest snap
every we receive a validwrite
.yield
statements and theco
library. This meansfirebase-server
is broken onNode <= 4.0.0
. This is solvable, either via a build step usingbabel
, or just manually rewriting using callbacks.ref.set(data, cb)
for example). There really is no reason you need that anyways, I substituted locations where that was used withsetTimeout
, 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").