Skip to content

Commit 338d9b5

Browse files
committed
feat: move installed to separate class
1 parent 9c03346 commit 338d9b5

3 files changed

Lines changed: 45 additions & 22 deletions

File tree

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
#include "BrownieInstaller.h"
2+
#include "BrownieHostObject.h"
3+
#include "BrownieStoreManager.h"
4+
5+
namespace brownie {
6+
7+
void BrownieInstaller::install(facebook::jsi::Runtime &runtime) {
8+
auto getStore = facebook::jsi::Function::createFromHostFunction(
9+
runtime, facebook::jsi::PropNameID::forAscii(runtime, "__getStore"), 1,
10+
[](facebook::jsi::Runtime &rt, const facebook::jsi::Value &,
11+
const facebook::jsi::Value *args, size_t count) -> facebook::jsi::Value {
12+
if (count < 1 || !args[0].isString()) {
13+
throw facebook::jsi::JSError(rt,
14+
"getStore requires a string key argument");
15+
}
16+
17+
std::string key = args[0].asString(rt).utf8(rt);
18+
auto store = BrownieStoreManager::shared().getStore(key);
19+
20+
if (!store) {
21+
return facebook::jsi::Value::undefined();
22+
}
23+
24+
auto hostObject = std::make_shared<BrownieHostObject>(store);
25+
return facebook::jsi::Object::createFromHostObject(rt, hostObject);
26+
});
27+
28+
runtime.global().setProperty(runtime, "__getStore", getStore);
29+
}
30+
31+
} // namespace brownie
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#pragma once
2+
3+
#include <jsi/jsi.h>
4+
5+
namespace brownie {
6+
7+
class BrownieInstaller {
8+
public:
9+
static void install(facebook::jsi::Runtime &runtime);
10+
};
11+
12+
} // namespace brownie

packages/brownie/ios/BrownieModule.mm

Lines changed: 2 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,7 @@
77
#import "Brownie-Swift.h"
88
#endif
99

10-
#import "BrownieHostObject.h"
11-
#import "BrownieStoreManager.h"
10+
#import "BrownieInstaller.h"
1211
#import "RCTTurboModule.h"
1312

1413
using namespace facebook;
@@ -46,26 +45,7 @@ - (void)handleNotification:(NSNotification *)notification {
4645

4746
- (void)installJSIBindingsWithRuntime:(facebook::jsi::Runtime &)runtime
4847
callInvoker:(const std::shared_ptr<facebook::react::CallInvoker> &)callinvoker {
49-
auto getStore = jsi::Function::createFromHostFunction(
50-
runtime, jsi::PropNameID::forAscii(runtime, "__getStore"), 1,
51-
[](jsi::Runtime &rt, const jsi::Value &, const jsi::Value *args,
52-
size_t count) -> jsi::Value {
53-
if (count < 1 || !args[0].isString()) {
54-
throw jsi::JSError(rt, "getStore requires a string key argument");
55-
}
56-
57-
std::string key = args[0].asString(rt).utf8(rt);
58-
auto store = brownie::BrownieStoreManager::shared().getStore(key);
59-
60-
if (!store) {
61-
return jsi::Value::undefined();
62-
}
63-
64-
auto hostObject = std::make_shared<brownie::BrownieHostObject>(store);
65-
return jsi::Object::createFromHostObject(rt, hostObject);
66-
});
67-
68-
runtime.global().setProperty(runtime, "__getStore", getStore);
48+
brownie::BrownieInstaller::install(runtime);
6949
}
7050

7151
- (std::shared_ptr<facebook::react::TurboModule>)getTurboModule:

0 commit comments

Comments
 (0)