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: deprecated event$ #7407

Open
wants to merge 10 commits into
base: main
Choose a base branch
from
5 changes: 5 additions & 0 deletions .changeset/hip-lemons-move.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@builder.io/qwik': patch
---

Deprecated event$, it will be removed in v2. Instead, use `$()`, and inside the function add `if (isServer) { return; }`
4 changes: 2 additions & 2 deletions packages/docs/src/components/theme-toggle/theme-toggle.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { component$, event$, useContext, useStyles$ } from '@builder.io/qwik';
import { component$, $, useContext, useStyles$ } from '@builder.io/qwik';
import { SunAndMoon } from './sun-and-moon';
import { themeStorageKey } from '../router-head/theme-script';
import themeToggle from './theme-toggle.css?inline';
Expand Down Expand Up @@ -45,7 +45,7 @@ export const ThemeToggle = component$(() => {
useStyles$(themeToggle);
const state = useContext(GlobalStore);

const onClick$ = event$(() => {
const onClick$ = $(() => {
state.theme = state.theme === 'light' ? 'dark' : 'light';
setPreference(state.theme);
});
Expand Down
2 changes: 1 addition & 1 deletion packages/docs/src/routes/api/qwik/api.json
Original file line number Diff line number Diff line change
Expand Up @@ -819,7 +819,7 @@
}
],
"kind": "Function",
"content": "```typescript\nevent$: <T>(qrl: T) => QRL<T>\n```\n\n\n<table><thead><tr><th>\n\nParameter\n\n\n</th><th>\n\nType\n\n\n</th><th>\n\nDescription\n\n\n</th></tr></thead>\n<tbody><tr><td>\n\nqrl\n\n\n</td><td>\n\nT\n\n\n</td><td>\n\n\n</td></tr>\n</tbody></table>\n**Returns:**\n\n[QRL](#qrl)<!-- -->&lt;T&gt;",
"content": "> Warning: This API is now obsolete.\n> \n> It will be removed in v2. Instead, use `$()`<!-- -->, and inside the function add `if (isServer) { return; }`\n> \n\n\n```typescript\nevent$: <T>(qrl: T) => QRL<T>\n```\n\n\n<table><thead><tr><th>\n\nParameter\n\n\n</th><th>\n\nType\n\n\n</th><th>\n\nDescription\n\n\n</th></tr></thead>\n<tbody><tr><td>\n\nqrl\n\n\n</td><td>\n\nT\n\n\n</td><td>\n\n\n</td></tr>\n</tbody></table>\n**Returns:**\n\n[QRL](#qrl)<!-- -->&lt;T&gt;",
"editUrl": "https://github.com/QwikDev/qwik/tree/main/packages/qwik/src/core/qrl/qrl.public.ts",
"mdFile": "qwik.event_.md"
},
Expand Down
4 changes: 4 additions & 0 deletions packages/docs/src/routes/api/qwik/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -2168,6 +2168,10 @@ any \| undefined

## event$

> Warning: This API is now obsolete.
>
> It will be removed in v2. Instead, use `$()`, and inside the function add `if (isServer) { return; }`

```typescript
event$: <T>(qrl: T) => QRL<T>;
```
Expand Down
11 changes: 8 additions & 3 deletions packages/qwik-city/src/runtime/src/spa-init.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ import type { ClientSPAWindow } from './qwik-city-component';
import type { ScrollHistoryState } from './scroll-restoration';
import type { ScrollState } from './types';

import { isDev } from '@builder.io/qwik';
import { event$ } from '@builder.io/qwik';
import { isDev, isServer } from '@builder.io/qwik';
import { $ } from '@builder.io/qwik';

// TODO Dedupe handler code from here and QwikCityProvider?
// TODO Navigation API; check for support & simplify.
Expand All @@ -14,13 +14,18 @@ import { event$ } from '@builder.io/qwik';
// - Robust, fully relies only on history. (scrollRestoration = 'manual')

// ! DO NOT IMPORT OR USE ANY EXTERNAL REFERENCES IN THIS SCRIPT.
export default event$((_: Event, el: Element) => {
export default $((_: Event, el: Element) => {
const win: ClientSPAWindow = window;
const spa = '_qCitySPA';
const initPopstate = '_qCityInitPopstate';
const initAnchors = '_qCityInitAnchors';
const initVisibility = '_qCityInitVisibility';
const initScroll = '_qCityInitScroll';

if (isServer) {
return;
}

if (
!win[spa] &&
!win[initPopstate] &&
Expand Down
2 changes: 1 addition & 1 deletion packages/qwik/src/core/api.md
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ export interface ErrorBoundaryStore {
error: any | undefined;
}

// @public (undocumented)
// @public @deprecated (undocumented)
export const event$: <T>(qrl: T) => QRL<T>;

// @public
Expand Down
2 changes: 1 addition & 1 deletion packages/qwik/src/core/qrl/qrl.public.ts
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,7 @@ export const eventQrl = <T>(qrl: QRL<T>): QRL<T> => {
return qrl;
};

/** @public */
/** @public @deprecated It will be removed in v2. Instead, use `$()`, and inside the function add `if (isServer) { return; }` */
export const event$ = implicit$FirstArg(eventQrl);

/** @alpha */
Expand Down
4 changes: 2 additions & 2 deletions starters/apps/e2e/src/components/render/render.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import {
useStore,
useStylesScoped$,
useTask$,
event$,
$,
h,
jsx,
SkipRender,
Expand Down Expand Up @@ -549,7 +549,7 @@ export const Issue3398 = component$(() => {
export const Issue3479 = component$(() => {
const count = useSignal(0);
const attributes = {
onClick$: event$(() => count.value++),
onClick$: $(() => count.value++),
};
const countStr = String(count.value) + "";
return (
Expand Down