-
-
Notifications
You must be signed in to change notification settings - Fork 4.6k
Closed
Description
Describe the problem
There's a TODO in the codebase for making reactive maps and sets:
svelte/packages/svelte/src/internal/client/proxy/proxy.js
Lines 44 to 54 in 434a587
// TODO handle Map and Set as well | |
if (prototype === object_prototype || prototype === array_prototype) { | |
const proxy = new Proxy(value, handler); | |
define_property(value, STATE_SYMBOL, { | |
value: init(value, proxy 7B56 , immutable), | |
writable: false | |
}); | |
// @ts-expect-error not sure how to fix this | |
return proxy; | |
} |
We could implement it, but there are several problems:
- we'd need to add the logic for making reactive map/set wrappers in a way that would be impossible to treeshake away for people who weren't using them
- that cost would increase if we wanted to add support for other built-ins (such as
Date
, and possiblyWeakSet
andWeakMap
) — including future additions to the language - adding support for other built-ins couldn't be done without a breaking change necessitating a major version bump
- it wouldn't be totally clear which non-POJOs get the reactive treatment
- there's also no particularly good opt-out mechanism
Describe the proposed solution
Instead, we could just create our own wrappers:
<script>
import { Map } from 'svelte/reactivity';
const map = new Map();
map.set('message', 'hello');
function update_message() {
map.set('message', 'goodbye');
}
</script>
<p>{map.get('message')}</p>
Importance
nice to have
dummdidumm, trueadm, stolinski, rmunn, juercode and 19 morearadalvand and dankobgAloso, aradalvand, xeho91, dankobg and adlrwbrmelMass, FoHoOV, pokedotdev and dei8bitHebilicious and Serator
Metadata
Metadata
Assignees
Labels
No labels