-
-
Notifications
You must be signed in to change notification settings - Fork 372
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
Allow to extend Series in types #441
Comments
Sure, but in your example uPlot itself doesn't know about Certainly many corners can be circumvented by typecasts but I think that developers try to avoid it. If we extend all |
I've made a little research and came to this: As you can see example I can handle both options (example 1 or example 3), but I think that example 3 is preferable. |
what's the benefit of splitting the data and the handlers instead of using also, if we go this route, i would want all the top-level major interfaces to be extendable. at least Scale, Axis, Series, Band. not sure if making Options itself extendable would make this whole thing even more twisted, but that would be good as well. if you wanna PR it, i'll try it out and see how it goes. |
I'm not sure that
I was experimenting with types and think that we'll have to give the opportunity to reach out extended Series more or less everywhere (options - for callbacks, hooks - for plugins). I don't think that there is a reason to make Options extendable in sense of extendable Series, but in my experiments Options necessarily becomes
Great! The job is mostly routine, and if you'll grant permission I can make PR cuz I've already started experimenting and found that the result is worth it. It's really very nice when you as developer once say that you want extend uPlot series and in all your plugins and callbacks you can reach all properties in extended series. |
let's leave them merged and rely on i'm still a bit nervous about this changeset size/complexity, so don't be offended if this doesn't get merged. worst case scenario is you'll just use your own typings defs -- a nice benefit of having only external types and not generated from the source :) |
someone also mentioned this, if you want to consider this route:
|
Hi @leeoniya! I've made some experiments, and you know, once you started to extending But I prefer not close this issue, because I think in time a lot of people may go through this way and maybe there will be some solution someday. |
the module augmentation i mentioned above appears to work great, can you try it? https://codesandbox.io/s/zen-clarke-zcl58?file=/src/index.ts |
i think this is resolved with module augmentation. |
Hi @leeoniya! I've noticed that there are a lot of uPlot plugins that I wrote depends on solution where I just put some property into Series at initialization time and then I just read it in plugin or callback. For example I'm putting into series information about series unit type for correct formatting in units plugin, or putting into series reference to original series data to show it in tooltip after data transformation along with transformed series values e.g. after normalization.
So I thought it would be convenient to allow somehow to extend
Series
type. I can suggest to make Series type generic:But it immediately makes to turn all series containing types in generics too, which is pretty much annoying to handle:
Other way is to do:
class uPlot<S extends Series>
, then we'll not touchSeries
. This approach too requires to update allSeries
-containing interfaces, but it's a little bit easier to handle.What do you think?
The text was updated successfully, but these errors were encountered: