realm / realm-js

Realm is a mobile database: an alternative to SQLite & key-value stores
https://realm.io
Apache License 2.0
5.72k stars 564 forks source link

Create Polyfill Convenience Modules #5410

Open takameyer opened 1 year ago

takameyer commented 1 year ago

Problem

In order for React Native developers to use the MongoDB watch method, they are required to perform the following setup to their project:

// Install the following dependencies
npm install react-native-polyfill-globals text-encoding;

// Add the following lines to index.js
import { polyfill as polyfillReadableStream } from "react-native-polyfill-globals/src/readable-stream";
polyfillReadableStream();

import { polyfill as polyfillEncoding } from "react-native-polyfill-globals/src/encoding";
polyfillEncoding();

import { polyfill as polyfillFetch } from "react-native-polyfill-globals/src/fetch";
polyfillFetch();

Solution

Add react-native-polyfill-globals and text-encoding as optional dependencies to Realm. Throw a warning when they are not present when trying to use the mongodb watch method. Give instructions on how to setup. Make the setup as easy as:

import "realm/polyfills/react-native/watch";

Alternatives

Just document this better and have the developer do the heavy lifting.

How important is this improvement for you?

Would be a major improvement

Feature would mainly be used with

Atlas App Services: Auth or Functions etc

NoatToan commented 8 months ago

Thanks @takameyer