MCPcopy
hub / github.com/livebud/bud / add_bindings

Method add_bindings

package/svelte/compiler.js:19668–19750  ·  view source on GitHub ↗
(block, binding_group)

Source from the content-addressed store, hash-verified

19666 });
19667 }
19668 add_bindings(block, binding_group) {
19669 const { renderer } = this;
19670 if (binding_group.bindings.length === 0)
19671 return;
19672 renderer.component.has_reactive_assignments = true;
19673 const lock = binding_group.bindings.some((binding) => binding.needs_lock) ? block.get_unique_name(`${this.var.name}_updating`) : null;
19674 if (lock)
19675 block.add_variable(lock, x`false`);
19676 const handler = renderer.component.get_unique_name(`${this.var.name}_${binding_group.events.join("_")}_handler`);
19677 renderer.add_to_context(handler.name);
19678 const needs_lock = binding_group.bindings.some((binding) => binding.needs_lock);
19679 const dependencies = /* @__PURE__ */ new Set();
19680 const contextual_dependencies = /* @__PURE__ */ new Set();
19681 binding_group.bindings.forEach((binding) => {
19682 add_to_set(dependencies, binding.get_update_dependencies());
19683 add_to_set(contextual_dependencies, binding.handler.contextual_dependencies);
19684 binding.render(block, lock);
19685 });
19686 let animation_frame;
19687 if (binding_group.events[0] === "timeupdate") {
19688 animation_frame = block.get_unique_name(`${this.var.name}_animationframe`);
19689 block.add_variable(animation_frame);
19690 }
19691 const has_local_function = contextual_dependencies.size > 0 || needs_lock || animation_frame;
19692 let callee = renderer.reference(handler);
19693 if (has_local_function) {
19694 const args = Array.from(contextual_dependencies).map((name) => renderer.reference(name));
19695 if (animation_frame) {
19696 block.chunks.init.push(b`
19697 function ${handler}() {
19698 @_cancelAnimationFrame(${animation_frame});
19699 if (!${this.var}.paused) {
19700 ${animation_frame} = @raf(${handler});
19701 ${needs_lock && b`${lock} = true;`}
19702 }
19703 ${callee}.call(${this.var}, ${args});
19704 }
19705 `);
19706 } else {
19707 block.chunks.init.push(b`
19708 function ${handler}() {
19709 ${needs_lock && b`${lock} = true;`}
19710 ${callee}.call(${this.var}, ${args});
19711 }
19712 `);
19713 }
19714 callee = handler;
19715 }
19716 const params = Array.from(contextual_dependencies).map((name) => ({
19717 type: "Identifier",
19718 name
19719 }));
19720 this.renderer.component.partly_hoisted.push(b`
19721 function ${handler}(${params}) {
19722 ${binding_group.bindings.map((b2) => b2.handler.mutation)}
19723 ${Array.from(dependencies).filter((dep) => dep[0] !== "$").filter((dep) => !contextual_dependencies.has(dep)).map((dep) => b`${this.renderer.invalidate(dep)};`)}
19724 }
19725 `);

Callers 1

Calls 13

xFunction · 0.85
add_to_setFunction · 0.85
bFunction · 0.85
get_unique_nameMethod · 0.80
add_variableMethod · 0.80
add_to_contextMethod · 0.80
referenceMethod · 0.80
pushMethod · 0.80
hasMethod · 0.80
invalidateMethod · 0.80

Tested by

no test coverage detected