-
Notifications
You must be signed in to change notification settings - Fork 15
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
feat: expose application config as separate context #13
Conversation
More eyes and thoughts on the api welcome. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we should rethink the CurriedProviders
component. I think the main purpose of having this component, is to prevent (potentially very deep) nesting of Provider
s. But IMO the current implementation comes with too many downsides. Loosing the Provider names is my biggest objection.
import React from 'react' | ||
import PropTypes from 'prop-types' | ||
|
||
export const CurriedProviders = ({ providers, children }) => |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since this was implemented as a React component, this shows up as a component in React DevTools. We could possibly consider just implementing this as a function to prevent it happening. Or perhaps change the component name, so it reflects the purpose of this component rather than its technical implementation....
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since each provider is actually exported by its respective service
package with the name Provider
, we might need to manually override the displayName if we want them to be more informative in DevTools
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes that is a good suggestion. Just tried setting a displayName: it works fine, but TypeScript doesn't like it.
However, since we are already doing this
import { Provider as ConfigProvider } from '@dhis2/app-service-config'
import { Provider as DataProvider } from '@dhis2/app-service-data'
and additionally, we'd have to set a displayName
....
Wouldn't it make more sense to just use a descriptive prefix in the exported variable name?
Or are there compelling reasons to keep the naming identical in every service?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@HendrikThePendric I like this idea. I went ahead and renamed all the exports from service packages (both Data and Context) to be more explicit, so they show up nicely in the React tree
See below for discussion of top-level provider name
@HendrikThePendric thanks for the review! I think I agree that CurriedProviders could be improved, it's probably a premature optimization. Maybe it's best to just deeply nest the providers for now? It will only be done once (in the exported |
Accidentally closed sorry! |
Yes I would be in favour of that. |
package.json
Outdated
@@ -9,17 +9,20 @@ | |||
"services/*" | |||
], | |||
"devDependencies": { | |||
"@dhis2/cli-style": "^3.0.1", | |||
"@dhis2/cli-style": "~3.0.0", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
NOTE I had to change this to a ~ range (so <3.1.0) because eslint was introduced in cli-style@3.1.0
and doesn't play nice with Typescript. It would be nice to support Typescript with our ESLint config
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Working on supporting external ESLint plugins in: dhis2/cli-style#72
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can upgrade to 4.x of cli-style and get support for extended ESLint configs.
@HendrikThePendric at long last I have now explicitly nested providers and gotten rid of the problematic |
Question @varl @HendrikThePendric et al - What should the top-level "runtime provider" be called? I originally had it called just |
I prefer Another alternative is Either way we can drop edit: my vote goes to |
This looks nice and clear now, introducing a breaking change at this point to clean up the namespace is better to do sooner than later. Though I wonder if we will eventually end up in a place where re-export all providers individually so they can be tree-shaken out? that will never work when we deeply nest them, nor if we dynamically generate the provider tree at runtime. Only way to avoid the overhead would be if the app declares its own provider tree with the ones that it needs. Hm, sounds like a future problem. 🤔 Defer. |
@varl yeah I like We could possibly declare the component with the namespace ( Not sure I'm sold one way or the other, just some more thoughts |
In AppShell world all of these providers are "provided" by the shell, so an App should actually never need them. If apps start breaking out of the Shell and becoming standalone again then maybe separate exports with treeshaking make sense, but I still think they'd want all of them. In any case if we're flopping back to fully independent apps we've got other problems ;-) |
That's a valid concern to me, |
So |
Just as a data point: there are currently 34 hits on all of GitHub in JavaScript for "RuntimeProvider": https://github.com/search?l=JavaScript&q=RuntimeProvider&type=Code Is the simplified import { DHIS2RuntimeProvider as Provider } from '@dhis2/app-runtime` Then again on the flip-side, if they have multiple RuntimeProvider's they could also do the reverse: import { RuntimeProvider as DHIS2RuntimeProvider } from '@dhis2/app-runtime` And we could have a shorter name in our library. 🤔 I prefer being consistent though and going for one or the other. |
Following a Slack discussion last month, I've set the exported (in code) name to simply |
I re-exported DataProvider (but not ConfigProvider), so this is no longer a breaking change and can still be used as-is outside the App Shell. We can make that break later if we want. |
# [1.4.0](v1.3.0...v1.4.0) (2019-08-08) ### Features * expose application config as separate context ([#13](#13)) ([c9aa123](c9aa123))
🎉 This PR is included in version 1.4.0 🎉 The release is available on: Your semantic-release bot 📦🚀 |
This change does three things:
Add a
config
service which is the parent context of all other services, providing application configuration values such as base url and app name (to be expanded). Expose the new hookuseAppConfig
allowing access to this config informationconsolidate all runtime providers (currently just
ConfigProvider
andDataProvider
) into a single exportedProvider
component which includes everything needed by a DHIS2 appFix/update some of the top-level scripts and service/runtime build configs. Also update
examples/cra
to use hooks instead of consumer components.I'm leaving
DataProvider
in as a top-level export to prevent a breaking change at this stage, it seems like we don't need it just yet and I want to be prudent about what we'd want to include in a 2.0 release.