Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // WITHOUT BUTTON COMPONENT
- /* App.svelte generated by Svelte v3.37.0 */
- import {
- SvelteComponent,
- detach,
- element,
- init,
- insert,
- listen,
- noop,
- safe_not_equal
- } from "svelte/internal";
- function create_fragment(ctx) {
- let button;
- let mounted;
- let dispose;
- return {
- c() {
- button = element("button");
- button.textContent = "Haha";
- },
- m(target, anchor) {
- insert(target, button, anchor);
- if (!mounted) {
- dispose = listen(button, "click", lol);
- mounted = true;
- }
- },
- p: noop,
- i: noop,
- o: noop,
- d(detaching) {
- if (detaching) detach(button);
- mounted = false;
- dispose();
- }
- };
- }
- function lol() {
- console.log("lol");
- }
- class App extends SvelteComponent {
- constructor(options) {
- super();
- init(this, options, null, create_fragment, safe_not_equal, {});
- }
- }
- export default App;
- // WITH BUTTON COMPONENT
- /* App.svelte generated by Svelte v3.37.0 */
- import {
- SvelteComponent,
- create_component,
- destroy_component,
- detach,
- init,
- insert,
- mount_component,
- safe_not_equal,
- text,
- transition_in,
- transition_out
- } from "svelte/internal";
- import Button from "./Button.svelte";
- function create_default_slot(ctx) {
- let t;
- return {
- c() {
- t = text("Haha");
- },
- m(target, anchor) {
- insert(target, t, anchor);
- },
- d(detaching) {
- if (detaching) detach(t);
- }
- };
- }
- function create_fragment(ctx) {
- let button;
- let current;
- button = new Button({
- props: {
- $$slots: { default: [create_default_slot] },
- $$scope: { ctx }
- }
- });
- button.$on("click", lol);
- return {
- c() {
- create_component(button.$$.fragment);
- },
- m(target, anchor) {
- mount_component(button, target, anchor);
- current = true;
- },
- p(ctx, [dirty]) {
- const button_changes = {};
- if (dirty & /*$$scope*/ 1) {
- button_changes.$$scope = { dirty, ctx };
- }
- button.$set(button_changes);
- },
- i(local) {
- if (current) return;
- transition_in(button.$$.fragment, local);
- current = true;
- },
- o(local) {
- transition_out(button.$$.fragment, local);
- current = false;
- },
- d(detaching) {
- destroy_component(button, detaching);
- }
- };
- }
- function lol() {
- console.log("lol");
- }
- class App extends SvelteComponent {
- constructor(options) {
- super();
- init(this, options, null, create_fragment, safe_not_equal, {});
- }
- }
- export default App;
- /* Button.svelte generated by Svelte v3.37.0 */
- import {
- SvelteComponent,
- append,
- bubble,
- detach,
- element,
- init,
- insert,
- listen,
- noop,
- safe_not_equal,
- set_data,
- text
- } from "svelte/internal";
- function create_fragment(ctx) {
- let button;
- let t;
- let mounted;
- let dispose;
- return {
- c() {
- button = element("button");
- t = text(/*haha*/ ctx[0]);
- },
- m(target, anchor) {
- insert(target, button, anchor);
- append(button, t);
- if (!mounted) {
- dispose = listen(button, "click", /*click_handler*/ ctx[1]);
- mounted = true;
- }
- },
- p(ctx, [dirty]) {
- if (dirty & /*haha*/ 1) set_data(t, /*haha*/ ctx[0]);
- },
- i: noop,
- o: noop,
- d(detaching) {
- if (detaching) detach(button);
- mounted = false;
- dispose();
- }
- };
- }
- function instance($$self, $$props, $$invalidate) {
- let { haha = 1 } = $$props;
- function click_handler(event) {
- bubble($$self, event);
- }
- $$self.$$set = $$props => {
- if ("haha" in $$props) $$invalidate(0, haha = $$props.haha);
- };
- return [haha, click_handler];
- }
- class Button extends SvelteComponent {
- constructor(options) {
- super();
- init(this, options, instance, create_fragment, safe_not_equal, { haha: 0 });
- }
- }
- export default Button;
Add Comment
Please, Sign In to add comment