-
Notifications
You must be signed in to change notification settings - Fork 11.9k
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
Have scales and plugins register themselves #6979
Conversation
Tree shaking works with So I think it should be possible already to only import one scale and for example extend that. Now, for extending a scale (for example), the self registering would be a bit annoying, wouldn't it? I think the 2. is actually required for tree shaking. Given that I'm quite a noob still in JS, anything I write should be considered with caution 🤣 |
I like the self registration. I'm a bit hesitant on replacing the strings, just because they are so easy to use. I'd be up to look at an implementation though to see how it could work and I'm happy to be proven wrong. Re tree shaking, yes they need to be not imported. That will mean we have to get rid of all the |
Why do you say that? The parent scale and child scale would both end up registered in that case, but I don't think there's any harm in registering a scale that's not used (we register all of them today). The parent scale won't be able to be tree shaken out anyway because it's imported by the child scale
I'm not sure I follow why you say that
I'm unclear as to whether we will need to do that. If the user just imports what they need instead of For the tests, it's not easy to |
Lets think of a
Not sure either 🤣 . The thought was Example: import {Chart, TimeScale, CategoryScale, Line} from 'chart.js';
new Chart(ctx, {type: Line, scales: {x: {type: TimeScale}, y: {type: CategoryScale}}); vs import Chart from `chart.js`;
new Chart(ctx, {type: 'line', scales: {x: {type: 'time'}, y: {type: 'category'}}); First one does not actually need any registration, and 2nd one can not shake the other types.
I think that could be the one. |
I'm not following. If it was built 2 years ago it would be using v2 and I don't think we should have to worry about mixing v2 and v3 scales in the same project. Or do you mean someone makes a version with v3 and then two years later makes another new version with v3?
Why would there be two different versions of the same scale in the project? That seems like it'd be a problem even today. How do you know you're getting a reference to the correct one to register?
Yeah, that sounds like my option 2 above. Are you suggesting you prefer that one? |
Unfortunately it seems this won't work unless we figure out a way to remove the custom css rollup plugin |
Adding a note here for posterity. The custom css rollup plugin has now been removed in |
This should hopefully allow users to import just the scales that they need and allow the others to be tree-shaken out
We will need to do one of two things to really make this work:
Chart.controllers
as suggested in the docs'yime'
scale instead of'time'
then you won't find out until runtime. But if instead you passed inYimeScale
then that should be able to be caught at build timeThese aren't necessarily mutually exclusive and we could possibly support them both, but I personally don't have time to do both and I think it would be potentially confusing to users to support multiple ways of creating charts (have to document everything twice, all the stackoverflow answers and docs look different, etc.). @etimberg @kurkle do you have a preference on approach here?