Skip to content

Commit

Permalink
Implement install() for Runtime dispatcher
Browse files Browse the repository at this point in the history
  • Loading branch information
mrousavy committed Jun 23, 2024
1 parent 0cc2321 commit 5a302b2
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,27 @@

#include "NativeNitroModules.hpp"
#include "TestHybridObject.hpp"
#include "Dispatcher.hpp"
#include "CallInvokerDispatcher.hpp"

namespace facebook::react {

NativeNitroModules::NativeNitroModules(std::shared_ptr<CallInvoker> jsInvoker) : NativeNitroCxxSpec(jsInvoker) { }
using namespace margelo;

NativeNitroModules::NativeNitroModules(std::shared_ptr<CallInvoker> jsInvoker) : NativeNitroCxxSpec(jsInvoker), _callInvoker(jsInvoker) {
}

NativeNitroModules::~NativeNitroModules() { }

void NativeNitroModules::install(jsi::Runtime& runtime) {
// Installs the global Dispatcher mechanism into this Runtime.
// This allows creating Promises and calling back to JS.
auto dispatcher = std::make_shared<CallInvokerDispatcher>(_callInvoker);
Dispatcher::installRuntimeGlobalDispatcher(runtime, dispatcher);
}

jsi::Object NativeNitroModules::createTestHybridObject(jsi::Runtime &runtime) {
auto hybrid = std::make_shared<margelo::TestHybridObject>();
auto hybrid = std::make_shared<TestHybridObject>();
return jsi::Object::createFromHostObject(runtime, hybrid);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,11 @@ class NativeNitroModules : public NativeNitroCxxSpec<NativeNitroModules> {
NativeNitroModules(std::shared_ptr<CallInvoker> jsInvoker);
~NativeNitroModules();

void install(jsi::Runtime& runtime);
jsi::Object createTestHybridObject(jsi::Runtime& runtime);

private:
std::shared_ptr<CallInvoker> _callInvoker;
};

} // namespace facebook::react
2 changes: 2 additions & 0 deletions packages/react-native-nitro-modules/src/NativeNitro.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@ import { TurboModuleRegistry } from 'react-native';
import type { UnsafeObject } from 'react-native/Libraries/Types/CodegenTypes';

export interface Spec extends TurboModule {
install(): void;
createTestHybridObject(): UnsafeObject;
}

export const NitroModules =
TurboModuleRegistry.getEnforcing<Spec>('NitroModulesCxx');
NitroModules.install();

0 comments on commit 5a302b2

Please sign in to comment.