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

Pinia setup store syntax support #1888

Open
1 of 2 tasks
jhercog opened this issue Jul 6, 2024 · 2 comments · May be fixed by #1905
Open
1 of 2 tasks

Pinia setup store syntax support #1888

jhercog opened this issue Jul 6, 2024 · 2 comments · May be fixed by #1905
Labels
enhancement New feature or request

Comments

@jhercog
Copy link

jhercog commented Jul 6, 2024

Describe the feature

The title says it all.

Would you consider supporting Pinia setup stores syntax? Currently, pinia-orm supports only the option stores syntax. Using setup stores would provide much more flexibility, allowing us to utilize watchers and composables inside the store itself. Not to mention, this intervention would make the plugin more compatible with Pinia.

After reviewing your code, it seems relatively straightforward to implement. As I understand it (though I could be wrong), the main change involves how the plugin uses the useDataStore function.

Here’s the current function:

function useDataStore(id, options, query) {
  return defineStore(id, {
    state: () => ({ data: {} }),
    actions: useStoreActions(query),
    ...options
  });
}

To support setup stores, the second argument in the defineStore call needs to be a function that returns an object with reactive properties and methods. There is also an optional third parameter representing a custom options object for additional plugin configurations (e.g., pinia-plugin-persistedstate).

The modified function could look something like this:

function useDataStore(id, options, customOptions, query) {
  return defineStore(id, () => ({
    data: ref({}),
    ...useStoreActions(query),
    ...options
  }), customOptions);
}

As a starting point, perhaps you could provide a way to override this function? You might consider including it as a method in the Query and Repository classes so we can extend those classes.

Regardless, I must point out that you are doing a great job in creating and maintaining this plugin, and it is already excellent even without the proposed feature.

Additional information

  • Would you be willing to help implement this feature?

Final checks

@jhercog jhercog changed the title Pinia setup syntax support Pinia setup store syntax support Jul 6, 2024
@CodeDredd CodeDredd added enhancement New feature or request and removed pending triage labels Jul 8, 2024
@CodeDredd CodeDredd linked a pull request Jul 21, 2024 that will close this issue
@CodeDredd
Copy link
Owner

Well the code part is done. Only the docs needed to be updated. But i don't know yet because the solution adds also 4KB to the bundle size.

@psarin
Copy link

psarin commented Oct 19, 2024

Hope this makes it in soon. Would be extremely useful.

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

Successfully merging a pull request may close this issue.

3 participants