Skip to content

Commit

Permalink
fix: Fix objects inside a SharedValue not being re-assignable (#183)
Browse files Browse the repository at this point in the history
  • Loading branch information
caheinz2 authored May 3, 2024
1 parent 477040c commit a8ae78f
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 8 deletions.
10 changes: 3 additions & 7 deletions cpp/wrappers/WKTJsiObjectWrapper.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ class JsiObjectWrapper : public JsiHostObject,
updateNativeState(runtime, object);
#endif
}

#if JS_RUNTIME_HERMES
void updateNativeState(jsi::Runtime &runtime, jsi::Object &obj) {
if (obj.hasNativeState(runtime)) {
Expand Down Expand Up @@ -128,11 +128,7 @@ class JsiObjectWrapper : public JsiHostObject,
std::unique_lock lock(_readWriteMutex);

auto nameStr = name.utf8(runtime);
// Just emplace so that we can box property values, ie. a slot can
// hold both an object and an int if that's what we need.
_properties.emplace(
nameStr,
JsiWrapper::wrap(runtime, value, this, getUseProxiesForUnwrapping()));
_properties[nameStr] = JsiWrapper::wrap(runtime, value, this, getUseProxiesForUnwrapping());
}

/**
Expand Down Expand Up @@ -161,7 +157,7 @@ class JsiObjectWrapper : public JsiHostObject,
std::vector<jsi::PropNameID>
getPropertyNames(jsi::Runtime &runtime) override {
std::unique_lock lock(_readWriteMutex);

std::vector<jsi::PropNameID> retVal;
retVal.reserve(_properties.size());
for (auto it = _properties.begin(); it != _properties.end(); it++) {
Expand Down
2 changes: 1 addition & 1 deletion example/Tests/sharedvalue-tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,6 @@ export const sharedvalue_tests = {
const sharedValue = Worklets.createSharedValue({ a: { b: 200 } });
// @ts-ignore
sharedValue.value.a = undefined;
return Promise.resolve();
return ExpectValue(sharedValue.value, { a: undefined });
},
};

0 comments on commit a8ae78f

Please sign in to comment.