Skip to content

Commit

Permalink
(fix) don't run binding init unnecessarily
Browse files Browse the repository at this point in the history
Fixes part of sveltejs#7032
Fixes sveltejs#6298
  • Loading branch information
dummdidumm committed Oct 27, 2022
1 parent 146e7a6 commit 80b09b5
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 3 deletions.
Expand Up @@ -393,7 +393,7 @@ export default class InlineComponentWrapper extends Wrapper {

component.partly_hoisted.push(body);

return b`@binding_callbacks.push(() => @bind(${this.var}, '${binding.name}', ${id}));`;
return b`@binding_callbacks.push(() => @bind(${this.var}, '${binding.name}', ${id}, ${snippet}));`;
});

const munged_handlers = this.node.handlers.map(handler => {
Expand Down
6 changes: 4 additions & 2 deletions src/runtime/internal/Component.ts
Expand Up @@ -5,11 +5,13 @@ import { children, detach, start_hydrating, end_hydrating } from './dom';
import { transition_in } from './transitions';
import { T$$ } from './types';

export function bind(component, name, callback) {
export function bind(component, name, callback, value) {
const index = component.$$.props[name];
if (index !== undefined) {
component.$$.bound[index] = callback;
callback(component.$$.ctx[index]);
if (value === undefined) {
callback(component.$$.ctx[index]);
}
}
}

Expand Down
@@ -0,0 +1,3 @@
<script>
export let tab;
</script>
@@ -0,0 +1,7 @@
export default {
async test({ assert, target }) {
assert.htmlEqual(target.innerHTML, `
<p>0</p>
`);
}
};
@@ -0,0 +1,17 @@
<script>
import { writable } from "svelte/store";
import Tab from "./Tab.svelte";
let i = 0;
const { set, subscribe } = writable({ id: 1, name: "tab1" });
const tab = {
set(value) {
i++;
set(value);
},
subscribe,
};
</script>

<Tab bind:tab={$tab} />
<p>{i}</p>

0 comments on commit 80b09b5

Please sign in to comment.