export function mount_component(component, target, anchor, customElement) {
        const { fragment, on_mount, on_destroy, after_update } = component.$$;
        
        fragment && fragment.m(target, anchor);
        
        if (!customElement) {
        // onMount happens before the initial afterUpdate
        add_render_callback(() => {
        
          const new_on_destroy = on_mount.map(run).filter(is_function);
          if (on_destroy) {
          on_destroy.push(...new_on_destroy);
          } else {
          // Edge case - component was destroyed immediately,
          // most likely as a result of a binding initialising
          run_all(new_on_destroy);
          }
          component.$$.on_mount = [];
        });
        }
        
        after_update.forEach(add_render_callback);
      }

      Javascript language logo
      MountComponent

      CodingBook

      The code defines a function mount_component which takes three arguments: a component, a target, and an anchor. In addition, the mount_component function receives a customElement parameter.

      The fragment portion of the code first attaches the target and anchor to the customElement. Next, the on_mount and on_destroy functions are called. The on_mount function is triggered when the component is first loaded and the on_destroy function is called when the component is destroyed. The after_update function is called once per update event, and it contains a set of callbacks that are added to the customElement.

      Shortcut: mount.Component

      0 Comments

        Add Comment

        Log in to add a comment

        Codiga - All rights reserved 2022.