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

Don't require local resources and getters to have globally unique names #1051

Open
wants to merge 1 commit into
base: remove-pinia
Choose a base branch
from

Conversation

matthew-white
Copy link
Member

This PR continues the work of #1050 in trying to simplify requestData. #1050 removed Pinia, making it such that different local resources are more independent of one another. Under Pinia, two local resources with the same name (created at different times) would share the same Pinia store. We've now removed these shared Pinia stores, but there is still a constraint on local resources: it's not possible for two local resources created at the same time to have the same name, even if they are created in different components. In other words, resource names must be globally unique, even for local resources.

My goal in this PR is to make local resources and getters as similar to provide/inject as possible. That's already the mechanism that they're using under the hood. provide/inject is happy to shadow an existing value with the same name. Now requestData will be fine if a local resource or getter shadows one from an ancestor component. It's not like we have a pressing need for shadowing, but by allowing it, we can simplify requestData. For example, we can consolidate all cleanup in onUnmounted() rather than using onUnmounted() for some things and onBeforeUnmount() for other things. I also think that allowing shadowing clarifies the mental model around local resources: local resources should be fully independent of one another.

Before submitting this PR, please make sure you have:

  • run npm run test and npm run lint and confirmed all checks still pass OR confirm CircleCI build passes
  • verified that any code or assets from external sources are properly credited in comments or that everything is internally sourced

However, do require that of app-wide resources.
Copy link
Member Author

@matthew-white matthew-white left a comment

Choose a reason for hiding this comment

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

Notes from interactive review

const createGetter = (name, ref) => {
if (getters.has(name)) throw new Error(`the name ${name} is in use`);
getters.set(name, ref);
Copy link
Member Author

Choose a reason for hiding this comment

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

getters[name] = ref;

Copy link
Member Author

Choose a reason for hiding this comment

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

Do we even need getters anymore? They seem rarely used. We could probably just use provide/inject instead. Let's see about removing them in a follow-up PR.

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