question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[RFC]: How should we emulate methods?

See original GitHub issue

Look at this code example from Solid.js

import { For } from "solid-js";
import { createMutable } from "solid-js/store";
import { css } from "solid-styled-components";
import RenderBlocks from "../../components/render-blocks.jsx";

function Columns(props) {
  const state = createMutable({
    getGutterSize() {
      return typeof props.space === "number" ? props.space || 0 : 20;
    },

    getColumns() {
      return props.columns || [];
    },

    getWidth(index) {
      const columns = this.getColumns();
      return columns[index]?.width || 100 / columns.length;
    },

    getColumnCssWidth(index) {
      const columns = this.getColumns();
      const gutterSize = this.getGutterSize();
      const subtractWidth = gutterSize * (columns.length - 1) / columns.length;
      return `calc(${this.getWidth(index)}% - ${subtractWidth}px)`;
    },

    maybeApplyForTablet(prop) {
      const _stackColumnsAt = props.stackColumnsAt || "tablet";

      return _stackColumnsAt === "tablet" ? prop : "inherit";
    },

    get columnsCssVars() {
      const flexDir = props.stackColumnsAt === "never" ? "inherit" : props.reverseColumnsWhenStacked ? "column-reverse" : "column";
      return {
        "--flex-dir": flexDir,
        "--flex-dir-tablet": this.maybeApplyForTablet(flexDir)
      };
    },

    get columnCssVars() {
      const width = "100%";
      const marginLeft = "0";
      return {
        "--column-width": width,
        "--column-margin-left": marginLeft,
        "--column-width-tablet": this.maybeApplyForTablet(width),
        "--column-margin-left-tablet": this.maybeApplyForTablet(marginLeft)
      };
    }

  });
  return <div class={"builder-columns " + css({
    display: "flex",
    alignItems: "stretch",
    lineHeight: "normal",
    "@media (max-width: 999px)": {
      flexDirection: "var(--flex-dir-tablet)"
    },
    "@media (max-width: 639px)": {
      flexDirection: "var(--flex-dir)"
    }
  })} style={state.columnsCssVars}>
      <For each={props.columns}>
        {(column, _index) => {
        const index = _index();

        return <div class={"builder-column " + css({
          flexGrow: "1",
          "@media (max-width: 999px)": {
            width: "var(--column-width-tablet) !important",
            marginLeft: "var(--column-margin-left-tablet) !important"
          },
          "@media (max-width: 639px)": {
            width: "var(--column-width) !important",
            marginLeft: "var(--column-margin-left) !important"
          }
        })} style={{
          width: state.getColumnCssWidth(index),
          "margin-left": `${index === 0 ? 0 : state.getGutterSize()}px`,
          ...state.columnCssVars
        }} key={index}>
              <RenderBlocks blocks={column.blocks}></RenderBlocks>
            </div>;
      }}
      </For>
    </div>;
}

export default Columns;

Notice that the author is choosing to store the business logic as methods on state object. How could we do something similar in Qwik?

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:15 (10 by maintainers)

github_iconTop GitHub Comments

2reactions
akaufmanncommented, Jun 22, 2022

First of all, a great job on this innovative framework to solve one of “the” problems of current websites.

+1 to make this in smart way possible:

export const MyComponent = component$(() => {
  const store = useStore({count:0});

  function increment() {
    store.count++;
  }

  return <button onClick$={() => increment()}>{store.count}</button>
});

This is a disadvantage of the very innovative Qwik, that you can’t use (normal) functions inside event callbacks, especially if you have to provide parameters. Either you have to put every logic in the cb function, which gets messy very fast with JSX if you have complex logic or you have to use QRLs that you have to invoke. I know why this is, but I’m looking forward to a smarter way to handle these scenarios w/o seeing -> Code(3): Only primitive and object literals can be serialized (foo: Foo)=>{\n ...\n }.

1reaction
mheverycommented, Jun 22, 2022

Well no. Problem is that the callers would have to be translated form sync to async and that is no trivial. For example foo.id would now return a promise instead of value.

For now we are not blocked on this but it is something to think about.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Requirements for Pseudo-Wire Emulation Edge-to-Edge (PWE3)
Requirements for Pseudo-Wire Emulation Edge-to-Edge (PWE3) (RFC 3916, October 2004)
Read more >
RFC 1576: TN3270 Current Practices
The following areas pertaining to TN3270 implementations are covered in this ... display terminal emulation using a subset of the existing telnet protocol....
Read more >
Class method with RFC Destination - SAP Community
To emulate RMI, you'll have to serialise your class instance, send it to an RFC FM as a parameter of that FM, which...
Read more >
An RFC for RFCs by Meetup - Library - Slab
An RFC process, by definition, is meant to collect feedback on a proposal. There will always be different opinions, and we must encourage...
Read more >
Writing Practices and Culture - How HashiCorp Works
Any team member can comment on and approve an RFC, but you need explicit approval only from the appropriate team leads in order...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found