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

POC for discussion #1

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open

POC for discussion #1

wants to merge 4 commits into from

Conversation

pleek91
Copy link
Contributor

@pleek91 pleek91 commented Mar 24, 2024

Description

More than just the basics but covers all the pieces I think we need here. I think there are some opportunities for simplification for sure as this mostly follows the structure I've used before. The primary things I want to call out

createQuery

Creates an instance of the query function and a query composition. The query function is designed to be used on its own in non component use cases. Including scaffolding for dispose which means you could do things like

function test() {
  using value = query(action, [])
  // do stuff
  // dispose automatically unsubscribes
}

The project exports a default query and useQuery function to use.

const subscriptions = new Map<number, QueryOptions>()
const { next: nextId } = sequence()

function execute(): void {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Something to call out here. This isn't async. And I want to keep it that way so that when used with sync functions there isn't an automatic delay. I think we can update this to support async actions by using Promise functions.

Comment on lines +49 to +58
return reactive({
...toRefs(query),
unsubscribe: () => {
query.unsubscribe()

if(channel.subscriptions.size === 0) {
deleteChannel(action, parameters)
}
}
})
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a pattern you'll see a couple times. You cannot spread a reactive object or you'll lose the reactivity. But you can call toRefs and spread that into a new reactive.

Using this so that I can add logic to the unsubscribe function at each level.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is neat. Great find ❤️

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I haven't implemented intervals or refreshing or anything like that. This is just cache a value based on queries existing.

Comment on lines +24 to +26
[Symbol.dispose]: () => {
query.unsubscribe()
},
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is all we need for dispose to work. But was getting build errors when testing. Might be too new for vite/vitest.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was able to get this working in 91cfc4c

Comment on lines +5 to +7
export {
query,
useQuery,
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

library exports a default query and useQuery which is what I'd expect most implementations to use rather than actually calling createQuery

Comment on lines +13 to +18
export type QueryLifecycle = 'app' | 'route' | 'component'

export type QueryOptions = {
maxAge?: number,
lifecycle?: QueryLifecycle
}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Non of this is implemented.

Copy link

@stackoverfloweth stackoverfloweth left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm super excited to see the progress you've made so far. Seeing things like the support for using makes me super excited for what our next iteration of this will look like in the end.

The feedback I have right now is mostly just half baked ideas around possibilities to simplify.

I'm concerned that it's a bit confusing to have 3 different syntaxes (createQuery, query, useQuery), each with their own intended use cases but not extremely clear in naming. Do you think it's feasible that we combine syntaxes?

Another simplification I'd like to explore is dropping the separation of channel and manager. It's been a bit since I've worked with the version at Prefect but the last couple iterations I've built only have a manager, which keeps subscriptions and subscribers.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

utils.ts AND utilities.ts?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would say they both need to be renamed lol, "utility" is just a dumping ground

Comment on lines +49 to +58
return reactive({
...toRefs(query),
unsubscribe: () => {
query.unsubscribe()

if(channel.subscriptions.size === 0) {
deleteChannel(action, parameters)
}
}
})

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is neat. Great find ❤️

useQuery: QueryComposition
}

const noop = () => undefined

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why do we need this? can't we just delay execute until we have args?

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