Skip to content

Commit 9d3578d

Browse files
committed
alternative approach to mutating props
1 parent 8a7e540 commit 9d3578d

File tree

2 files changed

+12
-13
lines changed
  • packages/svelte/src

2 files changed

+12
-13
lines changed

packages/svelte/src/compiler/phases/3-transform/client/utils.js

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -470,12 +470,14 @@ export function serialize_set_binding(node, context, fallback, options) {
470470
if (binding.kind === 'prop') {
471471
return b.call(
472472
left,
473-
b.assignment(
474-
node.operator,
475-
/** @type {import('estree').Pattern} */ (visit(node.left)),
476-
value
477-
),
478-
b.literal(true)
473+
b.sequence([
474+
b.assignment(
475+
node.operator,
476+
/** @type {import('estree').Pattern} */ (visit(node.left)),
477+
value
478+
),
479+
b.call(left)
480+
])
479481
);
480482
} else {
481483
return b.call(

packages/svelte/src/internal/client/reactivity/props.js

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -175,13 +175,10 @@ export function prop(props, key, flags, initial) {
175175
// intermediate mode — prop is written to, but the parent component had
176176
// `bind:foo` which means we can just call `$$props.foo = value` directly
177177
if (setter) {
178-
return function (/** @type {V} */ value, mutation = false) {
178+
return function (/** @type {V} */ value) {
179179
if (arguments.length === 1) {
180180
/** @type {Function} */ (setter)(value);
181181
return value;
182-
} else if (mutation) {
183-
/** @type {Function} */ (setter)(getter());
184-
return value;
185182
} else {
186183
return getter();
187184
}
@@ -213,7 +210,7 @@ export function prop(props, key, flags, initial) {
213210

214211
if (!immutable) current_value.equals = safe_equals;
215212

216-
return function (/** @type {V} */ value, mutation = false) {
213+
return function (/** @type {V} */ value) {
217214
var current = get(current_value);
218215

219216
// legacy nonsense — need to ensure the source is invalidated when necessary
@@ -229,9 +226,9 @@ export function prop(props, key, flags, initial) {
229226
}
230227

231228
if (arguments.length > 0) {
232-
if (mutation || (immutable ? value !== current : safe_not_equal(value, current))) {
229+
if (!current_value.equals(value)) {
233230
from_child = true;
234-
set(inner_current_value, mutation ? current : value);
231+
set(inner_current_value, value);
235232
get(current_value); // force a synchronisation immediately
236233
}
237234

0 commit comments

Comments
 (0)