Skip to content

Align build with react/solid/… instead of svelte | fix default error typing | add simple example | add mutation controller #1

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

Open
wants to merge 6 commits into
base: feat/lit-query-example
Choose a base branch
from

Conversation

JulianCataldo
Copy link

Hi :) Thanks for chiming in making Lit compatible with React Query!

This fixes build, so the root nx command, build:all, can succeed.

See
```ts
if (error) return 'An error has occurred: ' + error.message
```

in react/simple example
@JulianCataldo
Copy link
Author

JulianCataldo commented Sep 14, 2024

Added a working "lit simple" example + fixed a typing mismatch. It looks like react-query is using Error | null instead of unknown.

Was using `unknown` at the beginning.
It's now aligned with others implementations.
@JulianCataldo JulianCataldo changed the title build: align with react/solid… instead of svelte-package Align build with react/solid/… instead of svelte-package | fix default error typing | add simple example Sep 14, 2024
@JulianCataldo JulianCataldo changed the title Align build with react/solid/… instead of svelte-package | fix default error typing | add simple example Align build with react/solid/… instead of svelte | fix default error typing | add simple example Sep 14, 2024
@JulianCataldo
Copy link
Author

JulianCataldo commented Sep 14, 2024

Added a mutation observer controller, with correct typings (from react-query etc.)
Build is OK.
A very quick runtime test was done, at least onSuccess seems to work.

@customElement('child-element')
export class ChildElement extends LitElement {
  @state() todoId = 1

  private todoQuery = todoQueryController(this)

  private todoMutation = new MutationController(this, () => ({
    mutationFn: (newTodo: { id: string }) => {
      console.log('OK')

      return new Promise((r) => r({}))
    },
  }))

 render() {
    const { isPending, error, data, isFetching } = this.todoQuery.result

    if (error) return 'An error has occurred: ' + error.message

    return html`

        <button
          @click=${() => {
            this.todoMutation.result.mutate(
              { id: 'string' },
              {
                onSuccess: () => {
                  console.log('OK')
                  queryClient.invalidateQueries({ queryKey: ['todo'] })
                },
              },
            )
          }}
        >
          MUTATE
        </button>
`
//...

}

@JulianCataldo JulianCataldo changed the title Align build with react/solid/… instead of svelte | fix default error typing | add simple example Align build with react/solid/… instead of svelte | fix default error typing | add simple example | add mutation controller Sep 14, 2024
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.

1 participant