Skip to content

Commit 67e9509

Browse files
committed
binding callback only call when value changes internally
1 parent d472bd2 commit 67e9509

File tree

44 files changed

+143
-48
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+143
-48
lines changed

src/compiler/compile/render_dom/index.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,6 @@ export default function dom(
8686
const set = (uses_props || uses_rest || writable_props.length > 0 || component.slots.size > 0)
8787
? x`
8888
${$$props} => {
89-
${(uses_props || uses_rest) && b`if (@is_empty(${$$props})) return;`}
9089
${uses_props && renderer.invalidate('$$props', x`$$props = @assign(@assign({}, $$props), @exclude_internal_props($$new_props))`)}
9190
${uses_rest && !uses_props && x`$$props = @assign(@assign({}, $$props), @exclude_internal_props($$new_props))`}
9291
${uses_rest && renderer.invalidate('$$restProps', x`$$restProps = ${compute_rest}`)}
@@ -421,7 +420,7 @@ export default function dom(
421420
422421
${component.partly_hoisted}
423422
424-
${set && b`$$self.$set = ${set};`}
423+
${set && b`$$self.$$set = ${set};`}
425424
426425
${capture_state && b`$$self.$capture_state = ${capture_state};`}
427426

src/runtime/internal/Component.ts

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { add_render_callback, flush, schedule_update, dirty_components } from './scheduler';
22
import { current_component, set_current_component } from './lifecycle';
3-
import { blank_object, is_function, run, run_all, noop } from './utils';
3+
import { blank_object, is_empty, is_function, run, run_all, noop } from './utils';
44
import { children, detach } from './dom';
55
import { transition_in } from './transitions';
66

@@ -33,6 +33,7 @@ interface T$$ {
3333
context: Map<any, any>;
3434
on_mount: any[];
3535
on_destroy: any[];
36+
skip_bound: boolean;
3637
}
3738

3839
export function bind(component, name, callback) {
@@ -120,7 +121,8 @@ export function init(component, options, instance, create_fragment, not_equal, p
120121

121122
// everything else
122123
callbacks: blank_object(),
123-
dirty
124+
dirty,
125+
skip_bound: false
124126
};
125127

126128
let ready = false;
@@ -129,7 +131,7 @@ export function init(component, options, instance, create_fragment, not_equal, p
129131
? instance(component, prop_values, (i, ret, ...rest) => {
130132
const value = rest.length ? rest[0] : ret;
131133
if ($$.ctx && not_equal($$.ctx[i], $$.ctx[i] = value)) {
132-
if ($$.bound[i]) $$.bound[i](value);
134+
if (!$$.skip_bound && $$.bound[i]) $$.bound[i](value);
133135
if (ready) make_dirty(component, i);
134136
}
135137
return ret;
@@ -166,6 +168,7 @@ export let SvelteElement;
166168
if (typeof HTMLElement === 'function') {
167169
SvelteElement = class extends HTMLElement {
168170
$$: T$$;
171+
$$set?: ($$props: any) => void;
169172
constructor() {
170173
super();
171174
this.attachShadow({ mode: 'open' });
@@ -199,14 +202,19 @@ if (typeof HTMLElement === 'function') {
199202
};
200203
}
201204

202-
$set() {
203-
// overridden by instance, if it has props
205+
$set($$props) {
206+
if (this.$$set && !is_empty($$props)) {
207+
this.$$.skip_bound = true;
208+
this.$$set($$props);
209+
this.$$.skip_bound = false;
210+
}
204211
}
205212
};
206213
}
207214

208215
export class SvelteComponent {
209216
$$: T$$;
217+
$$set?: ($$props: any) => void;
210218

211219
$destroy() {
212220
destroy_component(this, 1);
@@ -223,7 +231,11 @@ export class SvelteComponent {
223231
};
224232
}
225233

226-
$set() {
227-
// overridden by instance, if it has props
234+
$set($$props) {
235+
if (this.$$set && !is_empty($$props)) {
236+
this.$$.skip_bound = true;
237+
this.$$set($$props);
238+
this.$$.skip_bound = false;
239+
}
228240
}
229241
}

test/js/samples/action-custom-event-handler/expected.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ function instance($$self, $$props, $$invalidate) {
5555
let { bar } = $$props;
5656
const foo_function = () => handleFoo(bar);
5757

58-
$$self.$set = $$props => {
58+
$$self.$$set = $$props => {
5959
if ("bar" in $$props) $$invalidate(0, bar = $$props.bar);
6060
};
6161

test/js/samples/bind-open/expected.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ function instance($$self, $$props, $$invalidate) {
5252
$$invalidate(0, open);
5353
}
5454

55-
$$self.$set = $$props => {
55+
$$self.$$set = $$props => {
5656
if ("open" in $$props) $$invalidate(0, open = $$props.open);
5757
};
5858

test/js/samples/bind-width-height/expected.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ function instance($$self, $$props, $$invalidate) {
4646
$$invalidate(1, h);
4747
}
4848

49-
$$self.$set = $$props => {
49+
$$self.$$set = $$props => {
5050
if ("w" in $$props) $$invalidate(0, w = $$props.w);
5151
if ("h" in $$props) $$invalidate(1, h = $$props.h);
5252
};

test/js/samples/bindings-readonly-order/expected.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ function instance($$self, $$props, $$invalidate) {
6868
$$invalidate(0, files);
6969
}
7070

71-
$$self.$set = $$props => {
71+
$$self.$$set = $$props => {
7272
if ("files" in $$props) $$invalidate(0, files = $$props.files);
7373
};
7474

test/js/samples/capture-inject-state/expected.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ function instance($$self, $$props, $$invalidate) {
118118
let { $$slots = {}, $$scope } = $$props;
119119
validate_slots("Component", $$slots, []);
120120

121-
$$self.$set = $$props => {
121+
$$self.$$set = $$props => {
122122
if ("prop" in $$props) $$subscribe_prop($$invalidate(0, prop = $$props.prop));
123123
if ("alias" in $$props) $$invalidate(1, realName = $$props.alias);
124124
};

test/js/samples/collapses-text-around-comments/expected.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ function create_fragment(ctx) {
4848
function instance($$self, $$props, $$invalidate) {
4949
let { foo = 42 } = $$props;
5050

51-
$$self.$set = $$props => {
51+
$$self.$$set = $$props => {
5252
if ("foo" in $$props) $$invalidate(0, foo = $$props.foo);
5353
};
5454

test/js/samples/computed-collapsed-if/expected.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ function instance($$self, $$props, $$invalidate) {
1212
return x * 3;
1313
}
1414

15-
$$self.$set = $$props => {
15+
$$self.$$set = $$props => {
1616
if ("x" in $$props) $$invalidate(0, x = $$props.x);
1717
};
1818

test/js/samples/data-attribute/expected.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ function create_fragment(ctx) {
4747
function instance($$self, $$props, $$invalidate) {
4848
let { bar } = $$props;
4949

50-
$$self.$set = $$props => {
50+
$$self.$$set = $$props => {
5151
if ("bar" in $$props) $$invalidate(0, bar = $$props.bar);
5252
};
5353

test/js/samples/debug-empty/expected.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ function instance($$self, $$props, $$invalidate) {
7979
let { $$slots = {}, $$scope } = $$props;
8080
validate_slots("Component", $$slots, []);
8181

82-
$$self.$set = $$props => {
82+
$$self.$$set = $$props => {
8383
if ("name" in $$props) $$invalidate(0, name = $$props.name);
8484
};
8585

test/js/samples/debug-foo-bar-baz-things/expected.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ function instance($$self, $$props, $$invalidate) {
183183
let { $$slots = {}, $$scope } = $$props;
184184
validate_slots("Component", $$slots, []);
185185

186-
$$self.$set = $$props => {
186+
$$self.$$set = $$props => {
187187
if ("things" in $$props) $$invalidate(0, things = $$props.things);
188188
if ("foo" in $$props) $$invalidate(1, foo = $$props.foo);
189189
if ("bar" in $$props) $$invalidate(2, bar = $$props.bar);

test/js/samples/debug-foo/expected.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ function instance($$self, $$props, $$invalidate) {
175175
let { $$slots = {}, $$scope } = $$props;
176176
validate_slots("Component", $$slots, []);
177177

178-
$$self.$set = $$props => {
178+
$$self.$$set = $$props => {
179179
if ("things" in $$props) $$invalidate(0, things = $$props.things);
180180
if ("foo" in $$props) $$invalidate(1, foo = $$props.foo);
181181
};

test/js/samples/deconflict-builtins/expected.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ function create_fragment(ctx) {
104104
function instance($$self, $$props, $$invalidate) {
105105
let { createElement } = $$props;
106106

107-
$$self.$set = $$props => {
107+
$$self.$$set = $$props => {
108108
if ("createElement" in $$props) $$invalidate(0, createElement = $$props.createElement);
109109
};
110110

test/js/samples/deconflict-globals/expected.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ function instance($$self, $$props, $$invalidate) {
1010
alert(JSON.stringify(data()));
1111
});
1212

13-
$$self.$set = $$props => {
13+
$$self.$$set = $$props => {
1414
if ("foo" in $$props) $$invalidate(0, foo = $$props.foo);
1515
};
1616

test/js/samples/dev-warning-missing-data-computed/expected.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ function instance($$self, $$props, $$invalidate) {
7676
let { $$slots = {}, $$scope } = $$props;
7777
validate_slots("Component", $$slots, []);
7878

79-
$$self.$set = $$props => {
79+
$$self.$$set = $$props => {
8080
if ("foo" in $$props) $$invalidate(0, foo = $$props.foo);
8181
};
8282

test/js/samples/each-block-array-literal/expected.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ function instance($$self, $$props, $$invalidate) {
106106
let { d } = $$props;
107107
let { e } = $$props;
108108

109-
$$self.$set = $$props => {
109+
$$self.$$set = $$props => {
110110
if ("a" in $$props) $$invalidate(0, a = $$props.a);
111111
if ("b" in $$props) $$invalidate(1, b = $$props.b);
112112
if ("c" in $$props) $$invalidate(2, c = $$props.c);

test/js/samples/each-block-changed-check/expected.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ function instance($$self, $$props, $$invalidate) {
152152
let { time } = $$props;
153153
let { foo } = $$props;
154154

155-
$$self.$set = $$props => {
155+
$$self.$$set = $$props => {
156156
if ("comments" in $$props) $$invalidate(0, comments = $$props.comments);
157157
if ("elapsed" in $$props) $$invalidate(1, elapsed = $$props.elapsed);
158158
if ("time" in $$props) $$invalidate(2, time = $$props.time);

test/js/samples/each-block-keyed-animated/expected.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ function foo(node, animation, params) {
128128
function instance($$self, $$props, $$invalidate) {
129129
let { things } = $$props;
130130

131-
$$self.$set = $$props => {
131+
$$self.$$set = $$props => {
132132
if ("things" in $$props) $$invalidate(0, things = $$props.things);
133133
};
134134

test/js/samples/each-block-keyed/expected.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ function create_fragment(ctx) {
9797
function instance($$self, $$props, $$invalidate) {
9898
let { things } = $$props;
9999

100-
$$self.$set = $$props => {
100+
$$self.$$set = $$props => {
101101
if ("things" in $$props) $$invalidate(0, things = $$props.things);
102102
};
103103

test/js/samples/if-block-no-update/expected.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ function create_fragment(ctx) {
8888
function instance($$self, $$props, $$invalidate) {
8989
let { foo } = $$props;
9090

91-
$$self.$set = $$props => {
91+
$$self.$$set = $$props => {
9292
if ("foo" in $$props) $$invalidate(0, foo = $$props.foo);
9393
};
9494

test/js/samples/if-block-simple/expected.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ function create_fragment(ctx) {
6666
function instance($$self, $$props, $$invalidate) {
6767
let { foo } = $$props;
6868

69-
$$self.$set = $$props => {
69+
$$self.$$set = $$props => {
7070
if ("foo" in $$props) $$invalidate(0, foo = $$props.foo);
7171
};
7272

test/js/samples/inline-style-optimized-multiple/expected.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ function instance($$self, $$props, $$invalidate) {
4444
let { x } = $$props;
4545
let { y } = $$props;
4646

47-
$$self.$set = $$props => {
47+
$$self.$$set = $$props => {
4848
if ("color" in $$props) $$invalidate(0, color = $$props.color);
4949
if ("x" in $$props) $$invalidate(1, x = $$props.x);
5050
if ("y" in $$props) $$invalidate(2, y = $$props.y);

test/js/samples/inline-style-optimized-url/expected.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ function create_fragment(ctx) {
3737
function instance($$self, $$props, $$invalidate) {
3838
let { data } = $$props;
3939

40-
$$self.$set = $$props => {
40+
$$self.$$set = $$props => {
4141
if ("data" in $$props) $$invalidate(0, data = $$props.data);
4242
};
4343

test/js/samples/inline-style-optimized/expected.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ function create_fragment(ctx) {
3737
function instance($$self, $$props, $$invalidate) {
3838
let { color } = $$props;
3939

40-
$$self.$set = $$props => {
40+
$$self.$$set = $$props => {
4141
if ("color" in $$props) $$invalidate(0, color = $$props.color);
4242
};
4343

test/js/samples/inline-style-unoptimized/expected.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ function instance($$self, $$props, $$invalidate) {
5454
let { key } = $$props;
5555
let { value } = $$props;
5656

57-
$$self.$set = $$props => {
57+
$$self.$$set = $$props => {
5858
if ("style" in $$props) $$invalidate(0, style = $$props.style);
5959
if ("key" in $$props) $$invalidate(1, key = $$props.key);
6060
if ("value" in $$props) $$invalidate(2, value = $$props.value);

test/js/samples/input-files/expected.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ function instance($$self, $$props, $$invalidate) {
4949
$$invalidate(0, files);
5050
}
5151

52-
$$self.$set = $$props => {
52+
$$self.$$set = $$props => {
5353
if ("files" in $$props) $$invalidate(0, files = $$props.files);
5454
};
5555

test/js/samples/input-range/expected.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ function instance($$self, $$props, $$invalidate) {
6060
$$invalidate(0, value);
6161
}
6262

63-
$$self.$set = $$props => {
63+
$$self.$$set = $$props => {
6464
if ("value" in $$props) $$invalidate(0, value = $$props.value);
6565
};
6666

test/js/samples/input-without-blowback-guard/expected.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ function instance($$self, $$props, $$invalidate) {
5353
$$invalidate(0, foo);
5454
}
5555

56-
$$self.$set = $$props => {
56+
$$self.$$set = $$props => {
5757
if ("foo" in $$props) $$invalidate(0, foo = $$props.foo);
5858
};
5959

test/js/samples/media-bindings/expected.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ function instance($$self, $$props, $$invalidate) {
173173
$$invalidate(10, ended);
174174
}
175175

176-
$$self.$set = $$props => {
176+
$$self.$$set = $$props => {
177177
if ("buffered" in $$props) $$invalidate(0, buffered = $$props.buffered);
178178
if ("seekable" in $$props) $$invalidate(1, seekable = $$props.seekable);
179179
if ("played" in $$props) $$invalidate(2, played = $$props.played);

test/js/samples/optional-chaining/expected.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ function instance($$self, $$props, $$invalidate) {
167167
let { f } = $$props;
168168
let Component;
169169

170-
$$self.$set = $$props => {
170+
$$self.$$set = $$props => {
171171
if ("a" in $$props) $$invalidate(0, a = $$props.a);
172172
if ("b" in $$props) $$invalidate(1, b = $$props.b);
173173
if ("c" in $$props) $$invalidate(2, c = $$props.c);

test/js/samples/reactive-values-non-topologically-ordered/expected.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ function instance($$self, $$props, $$invalidate) {
66
let a;
77
let b;
88

9-
$$self.$set = $$props => {
9+
$$self.$$set = $$props => {
1010
if ("x" in $$props) $$invalidate(0, x = $$props.x);
1111
};
1212

test/js/samples/reactive-values-non-writable-dependencies/expected.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ function instance($$self, $$props, $$invalidate) {
55
let { a = 1 } = $$props;
66
let { b = 2 } = $$props;
77

8-
$$self.$set = $$props => {
8+
$$self.$$set = $$props => {
99
if ("a" in $$props) $$invalidate(0, a = $$props.a);
1010
if ("b" in $$props) $$invalidate(1, b = $$props.b);
1111
};

test/js/samples/select-dynamic-value/expected.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ function create_fragment(ctx) {
5050
function instance($$self, $$props, $$invalidate) {
5151
let { current } = $$props;
5252

53-
$$self.$set = $$props => {
53+
$$self.$$set = $$props => {
5454
if ("current" in $$props) $$invalidate(0, current = $$props.current);
5555
};
5656

test/js/samples/src-attribute-check/expected.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ function instance($$self, $$props, $$invalidate) {
6767
let { url } = $$props;
6868
let { slug } = $$props;
6969

70-
$$self.$set = $$props => {
70+
$$self.$$set = $$props => {
7171
if ("url" in $$props) $$invalidate(0, url = $$props.url);
7272
if ("slug" in $$props) $$invalidate(1, slug = $$props.slug);
7373
};

0 commit comments

Comments
 (0)