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

Convert rest.ts to composition API #1774

Merged
merged 1 commit into from
Dec 14, 2023
Merged

Conversation

mvandenburgh
Copy link
Member

The rest module seems to be blocking the upgrade to Vue 3; in Vue 2, it was possible to initialize a Vue object as follows:

const dandiRest = new Vue({
	data() {
		return { user: null }
	},
	...
});

And then access a data object like this:

console.log(dandiRest.user)

But, the equivalent Vue 3 code doesn't work:

const dandiRest = Vue.createApp({
	data() {
		return { user: null }
	},
	...
});

console.log(dandiRest.user) // doesn't work

I'm not sure what the issue is or how it was changed, but I can't even find the docs that specified this behavior for Vue 2. I'd be curious to hear if anyone has any ideas why that is. But regardless, converting to Composition API avoids this issue and is also something we've planned for a long time, so I just went ahead and did that.

Fixes #1267

@@ -278,12 +295,12 @@ client.interceptors.request.use((config) => ({
},
}));

const user = () => dandiRest.user;
Copy link
Member Author

Choose a reason for hiding this comment

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

Note, this function is redundant now that we're using composition API. I made the necessary updates to the rest of the codebase to account for the fact that this is a Ref instead of a function.

@jjnesbitt
Copy link
Member

Is there a particular reason to keep the dandiRest object? Or is it just a matter of PR scope? I think we could remove the wrapping entirely and just have all those functions at the top level of rest.ts.

Copy link
Member

@jjnesbitt jjnesbitt left a comment

Choose a reason for hiding this comment

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

Looks good, tested locally. My only concern would be my other comment, but I still think we could merge this aside from that.

@mvandenburgh
Copy link
Member Author

Is there a particular reason to keep the dandiRest object? Or is it just a matter of PR scope? I think we could remove the wrapping entirely and just have all those functions at the top level of rest.ts.

Sorry, I thought I added a comment describing that but clearly I didn't. Yes, I left the dandiRest object to keep the scope of this PR minimal. Changing it would require touching a significant amount of the frontend code base, so I figured that could be left for a follow up PR while this PR only concerns itself with the core options => composition API conversion.

@mvandenburgh mvandenburgh added patch Increment the patch version when merged release Create a release when this pr is merged labels Dec 14, 2023
@mvandenburgh mvandenburgh merged commit 5cdb89c into master Dec 14, 2023
3 checks passed
@mvandenburgh mvandenburgh deleted the rest-composition-conversion branch December 14, 2023 16:04
@dandibot
Copy link
Member

🚀 PR was released in v0.3.67 🚀

@dandibot dandibot added the released This issue/pull request has been released. label Dec 14, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
patch Increment the patch version when merged release Create a release when this pr is merged released This issue/pull request has been released.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Migrate rest.ts to Composition API
3 participants