Skip to content

feat(qwik): Experimental support for synchronous QRL sync$(). #5545

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

Merged
merged 3 commits into from
Dec 15, 2023

Conversation

mhevery
Copy link
Contributor

@mhevery mhevery commented Dec 8, 2023

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.

  <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

Overview

What is it?

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

Description

Please include a summary of the change and which issue is fixed. Please also include relevant motivation and context. List any dependencies that are required for this change.

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 8, 2023

Deploy Preview for qwik-insights canceled.

Name Link
🔨 Latest commit 787cd7f
🔍 Latest deploy log https://app.netlify.com/sites/qwik-insights/deploys/657cb3fde3be5a000808f45f

Copy link

cloudflare-workers-and-pages bot commented Dec 8, 2023

Deploying with  Cloudflare Pages  Cloudflare Pages

Latest commit: 787cd7f
Status: ✅  Deploy successful!
Preview URL: https://153a6815.qwik-docs.pages.dev
Branch Preview URL: https://build-sync-qrl.qwik-docs.pages.dev

View logs

@mhevery mhevery force-pushed the build/sync-qrl branch 2 times, most recently from 78c2c11 to ffba343 Compare December 9, 2023 00:10
@zanettin zanettin added TYPE: enhancement New feature or request COMP: runtime labels Dec 10, 2023
@mhevery mhevery force-pushed the build/sync-qrl branch 4 times, most recently from 65693a4 to 371ad9b Compare December 11, 2023 22:10
@mhevery mhevery changed the title feat(qwik): Experimental support for synchronous QRL $sync(). feat(qwik): Experimental support for synchronous QRL sync$(). Dec 11, 2023
@mhevery mhevery force-pushed the build/sync-qrl branch 2 times, most recently from 9248059 to 330322b Compare December 11, 2023 22:57
@PatrickJS
Copy link
Member

works on my machine 👍

mhevery and others added 2 commits December 15, 2023 08:49
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$

* refactor(core): sync$ inlineFns key
@mhevery mhevery force-pushed the build/sync-qrl branch 7 times, most recently from 16f35b0 to f52ee03 Compare December 15, 2023 20:13
@mhevery mhevery enabled auto-merge (squash) December 15, 2023 20:14
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
@mhevery mhevery merged commit d50ceaa into main Dec 15, 2023
@mhevery mhevery deleted the build/sync-qrl branch December 15, 2023 20:49
kodiakhq bot referenced this pull request in ascorbic/unpic-img Dec 17, 2023
[![Mend Renovate](https://app.renovatebot.com/images/banner.svg)](https://renovatebot.com)

This PR contains the following updates:

| Package | Change | Age | Adoption | Passing | Confidence |
|---|---|---|---|---|---|
| [@builder.io/qwik](https://qwik.builder.io/) ([source](https://togithub.com/BuilderIO/qwik/tree/HEAD/packages/qwik)) | [`1.3.0` -> `1.3.1`](https://renovatebot.com/diffs/npm/@builder.io%2fqwik/1.3.0/1.3.1) | [![age](https://developer.mend.io/api/mc/badges/age/npm/@builder.io%2fqwik/1.3.1?slim=true)](https://docs.renovatebot.com/merge-confidence/) | [![adoption](https://developer.mend.io/api/mc/badges/adoption/npm/@builder.io%2fqwik/1.3.1?slim=true)](https://docs.renovatebot.com/merge-confidence/) | [![passing](https://developer.mend.io/api/mc/badges/compatibility/npm/@builder.io%2fqwik/1.3.0/1.3.1?slim=true)](https://docs.renovatebot.com/merge-confidence/) | [![confidence](https://developer.mend.io/api/mc/badges/confidence/npm/@builder.io%2fqwik/1.3.0/1.3.1?slim=true)](https://docs.renovatebot.com/merge-confidence/) |

---

### Release Notes

<details>
<summary>BuilderIO/qwik (@&#8203;builder.io/qwik)</summary>

### [`v1.3.1`](https://togithub.com/BuilderIO/qwik/releases/tag/v1.3.1)

[Compare Source](https://togithub.com/BuilderIO/qwik/compare/v1.3.0...v1.3.1)

##### What's Changed

-   fix(playground): block 1.3.0 by [@&#8203;wmertens](https://togithub.com/wmertens) in [https://github.com/BuilderIO/qwik/pull/5538](https://togithub.com/BuilderIO/qwik/pull/5538)
-   docs: show-updated-docs by [@&#8203;AmirSa12](https://togithub.com/AmirSa12) in [https://github.com/BuilderIO/qwik/pull/5516](https://togithub.com/BuilderIO/qwik/pull/5516)
-   docs: (add list item) Add qwik-d3 to the library list by [@&#8203;gilf](https://togithub.com/gilf) in [https://github.com/BuilderIO/qwik/pull/5544](https://togithub.com/BuilderIO/qwik/pull/5544)
-   docs: add qwik-storefront-ui library by [@&#8203;gioboa](https://togithub.com/gioboa) in [https://github.com/BuilderIO/qwik/pull/5548](https://togithub.com/BuilderIO/qwik/pull/5548)
-   docs: change image url by [@&#8203;gioboa](https://togithub.com/gioboa) in [https://github.com/BuilderIO/qwik/pull/5549](https://togithub.com/BuilderIO/qwik/pull/5549)
-   chore(starters): add type module to package.json  by [@&#8203;nelsonprsousa](https://togithub.com/nelsonprsousa) in [https://github.com/BuilderIO/qwik/pull/5553](https://togithub.com/BuilderIO/qwik/pull/5553)
-   refactor(types): optimize, QRL props, PropsOf, track(Signal) type, ... by [@&#8203;wmertens](https://togithub.com/wmertens) in [https://github.com/BuilderIO/qwik/pull/5550](https://togithub.com/BuilderIO/qwik/pull/5550)
-   fix(repl): don't propose broken versions by [@&#8203;wmertens](https://togithub.com/wmertens) in [https://github.com/BuilderIO/qwik/pull/5560](https://togithub.com/BuilderIO/qwik/pull/5560)
-   fix: remove dependency on vitefu causing playground failures by [@&#8203;mhevery](https://togithub.com/mhevery) in [https://github.com/BuilderIO/qwik/pull/5562](https://togithub.com/BuilderIO/qwik/pull/5562)
-   fix: better deprecation notice on qwikevents by [@&#8203;wmertens](https://togithub.com/wmertens) in [https://github.com/BuilderIO/qwik/pull/5568](https://togithub.com/BuilderIO/qwik/pull/5568)
-   fix: use existing local .eslintrc configuration by [@&#8203;gioboa](https://togithub.com/gioboa) in [https://github.com/BuilderIO/qwik/pull/5563](https://togithub.com/BuilderIO/qwik/pull/5563)
-   test(lint): break up lint tests into separate files by [@&#8203;mhevery](https://togithub.com/mhevery) in [https://github.com/BuilderIO/qwik/pull/5572](https://togithub.com/BuilderIO/qwik/pull/5572)
-   refactor(qwik): add `__qwik_serializable__` brand to types by [@&#8203;mhevery](https://togithub.com/mhevery) in [https://github.com/BuilderIO/qwik/pull/5576](https://togithub.com/BuilderIO/qwik/pull/5576)
-   fix(lint): allow event methods to capture `PropFunction` by [@&#8203;mhevery](https://togithub.com/mhevery) in [https://github.com/BuilderIO/qwik/pull/5578](https://togithub.com/BuilderIO/qwik/pull/5578)
-   chore(eslint-plugin-qwik): add 'qwik/no-use-visible-task': 'warn' to strict by [@&#8203;maiieul](https://togithub.com/maiieul) in [https://github.com/BuilderIO/qwik/pull/5575](https://togithub.com/BuilderIO/qwik/pull/5575)
-   fix: `server$` and AbortSignal types by [@&#8203;mhevery](https://togithub.com/mhevery) in [https://github.com/BuilderIO/qwik/pull/5581](https://togithub.com/BuilderIO/qwik/pull/5581)
-   fix(qwik): restore bivarience hack by [@&#8203;mhevery](https://togithub.com/mhevery) in [https://github.com/BuilderIO/qwik/pull/5587](https://togithub.com/BuilderIO/qwik/pull/5587)
-   chore(insights): correct failing build by [@&#8203;mhevery](https://togithub.com/mhevery) in [https://github.com/BuilderIO/qwik/pull/5586](https://togithub.com/BuilderIO/qwik/pull/5586)
-   docs(usevisibletask$): reduce eslint noUseVisibleTask message + transfer to docs by [@&#8203;maiieul](https://togithub.com/maiieul) in [https://github.com/BuilderIO/qwik/pull/5583](https://togithub.com/BuilderIO/qwik/pull/5583)
-   docs: remove console warning by [@&#8203;gioboa](https://togithub.com/gioboa) in [https://github.com/BuilderIO/qwik/pull/5590](https://togithub.com/BuilderIO/qwik/pull/5590)
-   fix(qwik-city): Scroll Position doesn't reset to 0 when it was triggered by an Action. by [@&#8203;iamriajul](https://togithub.com/iamriajul) in [https://github.com/BuilderIO/qwik/pull/5588](https://togithub.com/BuilderIO/qwik/pull/5588)
-   feat(qwik): Experimental support for synchronous QRL `sync$()`. by [@&#8203;mhevery](https://togithub.com/mhevery) in [https://github.com/BuilderIO/qwik/pull/5545](https://togithub.com/BuilderIO/qwik/pull/5545)
-   chore: 1.3.1 by [@&#8203;mhevery](https://togithub.com/mhevery) in [https://github.com/BuilderIO/qwik/pull/5595](https://togithub.com/BuilderIO/qwik/pull/5595)

##### New Contributors

-   [@&#8203;AmirSa12](https://togithub.com/AmirSa12) made their first contribution in [https://github.com/BuilderIO/qwik/pull/5516](https://togithub.com/BuilderIO/qwik/pull/5516)
-   [@&#8203;iamriajul](https://togithub.com/iamriajul) made their first contribution in [https://github.com/BuilderIO/qwik/pull/5588](https://togithub.com/BuilderIO/qwik/pull/5588)

**Full Changelog**: QwikDev/qwik@v1.3.0...v1.3.1

</details>

---

### Configuration

📅 **Schedule**: Branch creation - "after 9pm on sunday" (UTC), Automerge - At any time (no schedule defined).

🚦 **Automerge**: Disabled by config. Please merge this manually once you are satisfied.

♻ **Rebasing**: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox.

🔕 **Ignore**: Close this PR and you won't be reminded about this update again.

---

 - [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check this box

---

This PR has been generated by [Mend Renovate](https://www.mend.io/free-developer-tools/renovate/). View repository job log [here](https://developer.mend.io/github/ascorbic/unpic-img).
<!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiIzNy45My4xIiwidXBkYXRlZEluVmVyIjoiMzcuOTMuMSIsInRhcmdldEJyYW5jaCI6Im1haW4ifQ==-->
@sarat1669
Copy link

stopPropagation doesn't work. No tests were added for it as well.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[✨] stopPropagation:{eventName} [✨] prevent default functions
4 participants