Skip to content

Commit

Permalink
fix: Added support for changing type when setting prop
Browse files Browse the repository at this point in the history
Setting a property with different types used to fail:

```js
const sharedValue = Worklets.createSharedValue({ a: { b: 200 } });
sharedValue.value.a = undefined; // <- This failed
```

This fixes this issue.
  • Loading branch information
chrfalch committed Apr 25, 2024
1 parent 06cc66e commit 11e674c
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 7 deletions.
12 changes: 5 additions & 7 deletions cpp/wrappers/WKTJsiObjectWrapper.h
Expand Up @@ -121,13 +121,11 @@ class JsiObjectWrapper : public JsiHostObject,
std::unique_lock lock(_readWriteMutex);

auto nameStr = name.utf8(runtime);
if (_properties.count(nameStr) == 0) {
_properties.emplace(
nameStr,
JsiWrapper::wrap(runtime, value, this, getUseProxiesForUnwrapping()));
} else {
_properties.at(nameStr)->updateValue(runtime, value);
}
// 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()));
}

/**
Expand Down
7 changes: 7 additions & 0 deletions example/Tests/sharedvalue-tests.ts
Expand Up @@ -188,4 +188,11 @@ export const sharedvalue_tests = {
});
return ExpectValue(w(), true);
},

set_object_property_to_undefined_after_being_an_object: () => {
const sharedValue = Worklets.createSharedValue({ a: { b: 200 } });
// @ts-ignore
sharedValue.value.a = undefined;
return Promise.resolve();
},
};

0 comments on commit 11e674c

Please sign in to comment.