Skip to content

Commit 2dc445a

Browse files
authored
Merge pull request #178 from margelo/fix/allow-changing-type-of-property-in-object-wrapper
fix: Added support for changing type when setting prop
2 parents c91fdae + 11e674c commit 2dc445a

File tree

2 files changed

+12
-7
lines changed

2 files changed

+12
-7
lines changed

cpp/wrappers/WKTJsiObjectWrapper.h

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -128,13 +128,11 @@ class JsiObjectWrapper : public JsiHostObject,
128128
std::unique_lock lock(_readWriteMutex);
129129

130130
auto nameStr = name.utf8(runtime);
131-
if (_properties.count(nameStr) == 0) {
132-
_properties.emplace(
133-
nameStr,
134-
JsiWrapper::wrap(runtime, value, this, getUseProxiesForUnwrapping()));
135-
} else {
136-
_properties.at(nameStr)->updateValue(runtime, value);
137-
}
131+
// Just emplace so that we can box property values, ie. a slot can
132+
// hold both an object and an int if that's what we need.
133+
_properties.emplace(
134+
nameStr,
135+
JsiWrapper::wrap(runtime, value, this, getUseProxiesForUnwrapping()));
138136
}
139137

140138
/**

example/Tests/sharedvalue-tests.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,4 +188,11 @@ export const sharedvalue_tests = {
188188
});
189189
return ExpectValue(w(), true);
190190
},
191+
192+
set_object_property_to_undefined_after_being_an_object: () => {
193+
const sharedValue = Worklets.createSharedValue({ a: { b: 200 } });
194+
// @ts-ignore
195+
sharedValue.value.a = undefined;
196+
return Promise.resolve();
197+
},
191198
};

0 commit comments

Comments
 (0)