From b8051aaff959129d3ba4fb2e8613ccf7d3350571 Mon Sep 17 00:00:00 2001 From: Richard Harris Date: Mon, 21 Jan 2019 00:35:19 -0500 Subject: [PATCH] fix binding groups --- src/compile/render-dom/index.ts | 6 ++++++ src/compile/render-dom/wrappers/Element/Binding.ts | 4 ++-- src/internal/Component.js | 2 -- 3 files changed, 8 insertions(+), 4 deletions(-) diff --git a/src/compile/render-dom/index.ts b/src/compile/render-dom/index.ts index da6573e456..c7d79fb5d2 100644 --- a/src/compile/render-dom/index.ts +++ b/src/compile/render-dom/index.ts @@ -274,6 +274,10 @@ export default function dom( filtered_declarations.push(...arr.map(name => `$$slot_${sanitize(name)}`), '$$scope'); } + if (renderer.bindingGroups.length > 0) { + filtered_declarations.push(`$$binding_groups`); + } + const has_definition = ( component.javascript || filtered_props.length > 0 || @@ -313,6 +317,8 @@ export default function dom( ${renderer.slots.size && `let { ${[...renderer.slots].map(name => `$$slot_${sanitize(name)}`).join(', ')}, $$scope } = $$props;`} + ${renderer.bindingGroups.length > 0 && `const $$binding_groups = [${renderer.bindingGroups.map(_ => `[]`).join(', ')}];`} + ${component.partly_hoisted.length > 0 && component.partly_hoisted.join('\n\n')} ${reactive_store_subscriptions} diff --git a/src/compile/render-dom/wrappers/Element/Binding.ts b/src/compile/render-dom/wrappers/Element/Binding.ts index a9fa106def..7fd65c2e07 100644 --- a/src/compile/render-dom/wrappers/Element/Binding.ts +++ b/src/compile/render-dom/wrappers/Element/Binding.ts @@ -124,7 +124,7 @@ export default class BindingWrapper { const bindingGroup = getBindingGroup(parent.renderer, this.node.expression.node); block.builders.hydrate.addLine( - `(ctx.$$binding_groups[${bindingGroup}] || (ctx.$$binding_groups[${bindingGroup}] = [])).push(${parent.var});` + `ctx.$$binding_groups[${bindingGroup}].push(${parent.var});` ); block.builders.destroy.addLine( @@ -278,7 +278,7 @@ function getValueFromDom( if (name === 'group') { const bindingGroup = getBindingGroup(renderer, binding.node.expression.node); if (type === 'checkbox') { - return `@getBindingGroupValue($$self.ctx.$$binding_groups[${bindingGroup}])`; + return `@getBindingGroupValue($$binding_groups[${bindingGroup}])`; } return `this.__value`; diff --git a/src/internal/Component.js b/src/internal/Component.js index 63350bbd1c..223e00687f 100644 --- a/src/internal/Component.js +++ b/src/internal/Component.js @@ -98,8 +98,6 @@ export function init(component, options, instance, create_fragment, not_equal) { }) : props; - $$.ctx.$$binding_groups = []; // TODO this is awkward and usually unncessary - $$.update(); ready = true; run_all($$.before_render);