Guest User

Svelte component overhead

a guest
Apr 14th, 2021
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // WITHOUT BUTTON COMPONENT
  2.  
  3.  
  4. /* App.svelte generated by Svelte v3.37.0 */
  5. import {
  6.     SvelteComponent,
  7.     detach,
  8.     element,
  9.     init,
  10.     insert,
  11.     listen,
  12.     noop,
  13.     safe_not_equal
  14. } from "svelte/internal";
  15.  
  16. function create_fragment(ctx) {
  17.     let button;
  18.     let mounted;
  19.     let dispose;
  20.  
  21.     return {
  22.         c() {
  23.             button = element("button");
  24.             button.textContent = "Haha";
  25.         },
  26.         m(target, anchor) {
  27.             insert(target, button, anchor);
  28.  
  29.             if (!mounted) {
  30.                 dispose = listen(button, "click", lol);
  31.                 mounted = true;
  32.             }
  33.         },
  34.         p: noop,
  35.         i: noop,
  36.         o: noop,
  37.         d(detaching) {
  38.             if (detaching) detach(button);
  39.             mounted = false;
  40.             dispose();
  41.         }
  42.     };
  43. }
  44.  
  45. function lol() {
  46.     console.log("lol");
  47. }
  48.  
  49. class App extends SvelteComponent {
  50.     constructor(options) {
  51.         super();
  52.         init(this, options, null, create_fragment, safe_not_equal, {});
  53.     }
  54. }
  55.  
  56. export default App;
  57.  
  58.  
  59.  
  60. // WITH BUTTON COMPONENT
  61.  
  62. /* App.svelte generated by Svelte v3.37.0 */
  63. import {
  64.     SvelteComponent,
  65.     create_component,
  66.     destroy_component,
  67.     detach,
  68.     init,
  69.     insert,
  70.     mount_component,
  71.     safe_not_equal,
  72.     text,
  73.     transition_in,
  74.     transition_out
  75. } from "svelte/internal";
  76.  
  77. import Button from "./Button.svelte";
  78.  
  79. function create_default_slot(ctx) {
  80.     let t;
  81.  
  82.     return {
  83.         c() {
  84.             t = text("Haha");
  85.         },
  86.         m(target, anchor) {
  87.             insert(target, t, anchor);
  88.         },
  89.         d(detaching) {
  90.             if (detaching) detach(t);
  91.         }
  92.     };
  93. }
  94.  
  95. function create_fragment(ctx) {
  96.     let button;
  97.     let current;
  98.  
  99.     button = new Button({
  100.             props: {
  101.                 $$slots: { default: [create_default_slot] },
  102.                 $$scope: { ctx }
  103.             }
  104.         });
  105.  
  106.     button.$on("click", lol);
  107.  
  108.     return {
  109.         c() {
  110.             create_component(button.$$.fragment);
  111.         },
  112.         m(target, anchor) {
  113.             mount_component(button, target, anchor);
  114.             current = true;
  115.         },
  116.         p(ctx, [dirty]) {
  117.             const button_changes = {};
  118.  
  119.             if (dirty & /*$$scope*/ 1) {
  120.                 button_changes.$$scope = { dirty, ctx };
  121.             }
  122.  
  123.             button.$set(button_changes);
  124.         },
  125.         i(local) {
  126.             if (current) return;
  127.             transition_in(button.$$.fragment, local);
  128.             current = true;
  129.         },
  130.         o(local) {
  131.             transition_out(button.$$.fragment, local);
  132.             current = false;
  133.         },
  134.         d(detaching) {
  135.             destroy_component(button, detaching);
  136.         }
  137.     };
  138. }
  139.  
  140. function lol() {
  141.     console.log("lol");
  142. }
  143.  
  144. class App extends SvelteComponent {
  145.     constructor(options) {
  146.         super();
  147.         init(this, options, null, create_fragment, safe_not_equal, {});
  148.     }
  149. }
  150.  
  151. export default App;
  152.  
  153.  
  154. /* Button.svelte generated by Svelte v3.37.0 */
  155. import {
  156.     SvelteComponent,
  157.     append,
  158.     bubble,
  159.     detach,
  160.     element,
  161.     init,
  162.     insert,
  163.     listen,
  164.     noop,
  165.     safe_not_equal,
  166.     set_data,
  167.     text
  168. } from "svelte/internal";
  169.  
  170. function create_fragment(ctx) {
  171.     let button;
  172.     let t;
  173.     let mounted;
  174.     let dispose;
  175.  
  176.     return {
  177.         c() {
  178.             button = element("button");
  179.             t = text(/*haha*/ ctx[0]);
  180.         },
  181.         m(target, anchor) {
  182.             insert(target, button, anchor);
  183.             append(button, t);
  184.  
  185.             if (!mounted) {
  186.                 dispose = listen(button, "click", /*click_handler*/ ctx[1]);
  187.                 mounted = true;
  188.             }
  189.         },
  190.         p(ctx, [dirty]) {
  191.             if (dirty & /*haha*/ 1) set_data(t, /*haha*/ ctx[0]);
  192.         },
  193.         i: noop,
  194.         o: noop,
  195.         d(detaching) {
  196.             if (detaching) detach(button);
  197.             mounted = false;
  198.             dispose();
  199.         }
  200.     };
  201. }
  202.  
  203. function instance($$self, $$props, $$invalidate) {
  204.     let { haha = 1 } = $$props;
  205.  
  206.     function click_handler(event) {
  207.         bubble($$self, event);
  208.     }
  209.  
  210.     $$self.$$set = $$props => {
  211.         if ("haha" in $$props) $$invalidate(0, haha = $$props.haha);
  212.     };
  213.  
  214.     return [haha, click_handler];
  215. }
  216.  
  217. class Button extends SvelteComponent {
  218.     constructor(options) {
  219.         super();
  220.         init(this, options, instance, create_fragment, safe_not_equal, { haha: 0 });
  221.     }
  222. }
  223.  
  224. export default Button;
Add Comment
Please, Sign In to add comment