Skip to content

Commit

Permalink
format
Browse files Browse the repository at this point in the history
  • Loading branch information
mrousavy committed Jan 16, 2025
1 parent d030add commit ccfc707
Showing 1 changed file with 27 additions and 26 deletions.
53 changes: 27 additions & 26 deletions packages/react-native-nitro-modules/cpp/views/CachedProp.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,32 +11,33 @@

namespace margelo::nitro {

using namespace facebook;

template <typename T>
struct CachedProp {
public:
T value;
OwningReference<jsi::Value> jsiValue;
bool isDirty;

public:
bool equals(jsi::Runtime& runtime, const jsi::Value& other) const {
if (!jsiValue) return false;
return jsi::Value::strictEquals(runtime, *jsiValue, other);
}

public:
static CachedProp<T> fromRawValue(jsi::Runtime& runtime, const jsi::Value& value, const CachedProp<T>& oldProp) {
if (oldProp.equals(runtime, value)) {
// jsi::Value hasn't changed - no need to convert it again!
return oldProp;
}
auto converted = JSIConverter<T>::fromJSI(runtime, value);
auto cache = JSICache::getOrCreateCache(runtime);
auto cached = cache.makeShared(jsi::Value(runtime, value));
return CachedProp<T>(std::move(converted), std::move(cached), /* isDirty */ true);
using namespace facebook;

template <typename T>
struct CachedProp {
public:
T value;
OwningReference<jsi::Value> jsiValue;
bool isDirty;

public:
bool equals(jsi::Runtime& runtime, const jsi::Value& other) const {
if (!jsiValue)
return false;
return jsi::Value::strictEquals(runtime, *jsiValue, other);
}

public:
static CachedProp<T> fromRawValue(jsi::Runtime& runtime, const jsi::Value& value, const CachedProp<T>& oldProp) {
if (oldProp.equals(runtime, value)) {
// jsi::Value hasn't changed - no need to convert it again!
return oldProp;
}
};
auto converted = JSIConverter<T>::fromJSI(runtime, value);
auto cache = JSICache::getOrCreateCache(runtime);
auto cached = cache.makeShared(jsi::Value(runtime, value));
return CachedProp<T>(std::move(converted), std::move(cached), /* isDirty */ true);
}
};

} // namespace margelo::nitro

0 comments on commit ccfc707

Please sign in to comment.