Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(qrl.ts): dedupe sync$ #5566

Merged
merged 2 commits into from
Dec 12, 2023
Merged

fix(qrl.ts): dedupe sync$ #5566

merged 2 commits into from
Dec 12, 2023

Conversation

PatrickJS
Copy link
Member

@PatrickJS PatrickJS commented Dec 12, 2023

Overview

dedupe sync$ functions

What is it?

  • Feature / enhancement
  • Bug
  • Docs / tests / types / typos

Description

ensure sync$ functions are only included once

Use cases and why

    1. One use case
    1. Another use case

Checklist:

  • My code follows the developer guidelines of this project
  • I have performed a self-review of my own code
  • I have made corresponding changes to the documentation
  • Added new tests to cover the fix / functionality

Copy link

netlify bot commented Dec 12, 2023

👷 Deploy request for qwik-insights pending review.

Visit the deploys page to approve it

Name Link
🔨 Latest commit 3833398

@mhevery mhevery merged commit 8375887 into QwikDev:build/sync-qrl Dec 12, 2023
22 checks passed
@PatrickJS PatrickJS deleted the patch-6 branch December 12, 2023 05:43
mhevery pushed a commit that referenced this pull request Dec 15, 2023
* fix(qrl.ts): dedupe sync$

* refactor(core): sync$ inlineFns key
mhevery added a commit that referenced this pull request Dec 15, 2023
* feat(qwik): Experimental support for synchronous QRL `sync$()`.

It is often desirable to have call API on events synchronously. For example, `event.preventDefault()` and `event.stopPropagation()` must be called synchronously in order to have a helpful effect.

```TypeScript
  <button onClick$={[
    $sync(event => event.preventDefault()),
    $(() => {
      // normal behavior.
    })
  ]}>Click Me</button>
```

The idea is that `$sync()` will be inlined into HTML. For this reason, the function, `$sync()`, must not only be a pure function but also can not depend on any external code, such as imports.

The best way to think about it is that the function inside `$sync()` must be able to survive `fn.toString()` and then be reconstructed from the string into a proper function.

In practice, this means that the function must be a simple function which can't:
- Close over any state.
- Close over any imports.

Fix #5322
Fix #4496

* fix(qrl.ts): dedupe sync$ (#5566)

* fix(qrl.ts): dedupe sync$

* refactor(core): sync$ inlineFns key

* feat(qwik): Experimental support for synchronous QRL `sync$()`.

It is often desirable to have call API on events synchronously. For example, `event.preventDefault()` and `event.stopPropagation()` must be called synchronously in order to have a helpful effect.

```TypeScript
  <button onClick$={[
    $sync(event => event.preventDefault()),
    $(() => {
      // normal behavior.
    })
  ]}>Click Me</button>
```

The idea is that `$sync()` will be inlined into HTML. For this reason, the function, `$sync()`, must not only be a pure function but also can not depend on any external code, such as imports.

The best way to think about it is that the function inside `$sync()` must be able to survive `fn.toString()` and then be reconstructed from the string into a proper function.

In practice, this means that the function must be a simple function which can't:
- Close over any state.
- Close over any imports.

Fix #5322
Fix #4496

---------

Co-authored-by: PatrickJS <github@patrickjs.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants