kossnocorp / typesaurus-react

🦕 React/Preact Hooks for Typesaurus, type-safe Firestore ODM
90 stars 5 forks source link

Lazy Loading #12

Open seanaguinaga opened 3 years ago

seanaguinaga commented 3 years ago

Hey there,

Not an issue, per se, but maybe you'll find it interesting.

ReactFire has lazy-loading for all of the obvious reasons.

Is there a way to pass in an already loaded or lazy instance of firebase or firestore into typesaurus?

Thinking about this from a code-splitting, React.lazy(), Suspense, etc., perspective.

seanaguinaga commented 3 years ago

There are also some cool things you can do when you can pass in an instance of firestore or firebase:

Using firebase emulators, or setting certain firestore configurations.

 preloadFunctions({ firebaseApp }).then((functions) => {
      if (process.env.NODE_ENV !== "production") {
        return functions().useFunctionsEmulator("http://localhost:5001");
      } else return;
    }),
    preloadPerformance({ firebaseApp }),
    preloadFirestore({
      firebaseApp,
      setup(firestore) {
        if (process.env.NODE_ENV !== "production") {
          firestore().settings({
            host: "localhost:8080",
            ssl: false,
          });
        }
        return firestore().enablePersistence({
          synchronizeTabs: true,
        });
      },
    }),
seanaguinaga commented 3 years ago

Or is all of this null and void, because firebase or firestore is a UMD global or something like that? So typesaurus will just reference that already "instantiated" instance? And will then pick up all of these benefits, lazy-loading, configuration, for free?