Skip to content

Commit

Permalink
Hermes: Adding an index.native.js (#4461)
Browse files Browse the repository at this point in the history
* Ading an index.native.js to help bundlers

* Adding a note to the changelog
  • Loading branch information
kraenhansen committed Apr 11, 2022
1 parent ecc3892 commit ad3488e
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 8 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ x.x.x Release notes (yyyy-MM-dd)
### Fixed
* Logging out too fast can cause an error if the timeout behavior is set to `openLocalRealm` ([4453](https://github.com/realm/realm-js/issues/4453))
* Released `realm-network-transport` to adopt the changes published to fix `globalThis` undefined issue for older devices. ([#4350](https://github.com/realm/realm-js/4350))
* Changed "react-native" main field to point to a `lib/index.native.js` file to help bundlers pick the right file when loading our library on React Native. ([#4459](https://github.com/realm/realm-js/issues/4459))

### Compatibility
* MongoDB Realm Cloud.
Expand Down Expand Up @@ -4409,4 +4410,4 @@ Old files can still be opened and files open in read-only mode will not be modif
0.10.0 Release notes (2016-2-22)
=============================================================
### Enhancements
* Initial Release
* Initial Release
20 changes: 20 additions & 0 deletions lib/index.native.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
////////////////////////////////////////////////////////////////////////////
//
// Copyright 2022 Realm Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
////////////////////////////////////////////////////////////////////////////

const { Realm } = require("./react-native");
module.exports = Realm;
10 changes: 5 additions & 5 deletions lib/react-native/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@

import { Platform, NativeModules } from "react-native";

import utils from "../utils";
import extend from "../extensions";

//switch how babel transpiled code creates children objects.
//Inheriting from Realm.Object with class syntax does not support using Reflect.construct the way babel transpiles it.
//Defining Reflect.construct.sham makes the transpiled code use different standard mechanism for inheriting. (Function.apply with setPrototypeOf)
Expand All @@ -39,7 +42,7 @@ if (Platform.OS === "android") {

// TODO: Remove the need to store Realm as a global
// @see https://github.com/realm/realm-js/issues/2126
const Realm = globalThis.Realm;
export const Realm = globalThis.Realm;

// Otherwise, we must be in a "normal" react native situation.
// In that case, the Realm type should have been injected by the native code.
Expand All @@ -50,10 +53,7 @@ if (typeof Realm === "undefined") {
);
}

require("../extensions")(Realm);
extend(Realm);

const utils = require("../utils");
const versions = utils.getVersions();
Realm.App._setVersions(versions);

module.exports = Realm;
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
},
"types": "types/index.d.ts",
"main": "lib/index.js",
"react-native": "lib/react-native/index.js",
"react-native": "lib/index.native.js",
"files": [
"cmake",
"lib",
Expand Down Expand Up @@ -162,4 +162,4 @@
4
]
}
}
}

0 comments on commit ad3488e

Please sign in to comment.