-
-
Notifications
You must be signed in to change notification settings - Fork 3.7k
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
Limit inheritance of Editor and EditorUI classes #327
Comments
In fact, even for me, who knows part of these classes very well, it is unclear what class I should use and reading the code is hard because of the long chains.
I agree. I believe it is much simpler to understand code when it uses helpers instead of base classes.
In fact, the class was the most unclear part for me: should I use it? When? I think even if we merge part of the logic and user does not need it all, it is still simpler for him to copy the class and modify it. Now I need to merge classes first to change them later. Also, I think it is partially the matter of the documentation. We do not have a good docs overview about the UI library, what does not help. For instance, I have no idea what this code do: https://github.com/ckeditor/ckeditor5-ui-default/blob/d4a6ee75e5ef50317fd0637c86c6b79a61522eeb/src/editorui/editorui.js#L48 and this doc does not help: https://github.com/ckeditor/ckeditor5-ui/blob/eca89ac35ad4b14896a05a6b1c2c8d67ceb52086/src/controller.js#L156 At the same time, our way of building |
And when I was thinking about this, I realised that |
It only depends on what |
I understand |
Dunno if that was mentioned already, but we definitely discussed this – one of the main goals here should be to create such interfaces which the features will be able to rely on. Right now, most features require big part of StandardEditor, but with the exception of EDIT: I think that it was covered by #303. |
I think that we need to answer here one question – what kind of editors we use really. I can see two types:
I suggested merging So, either we'll keep this split and layer this code horizontally, or try a different approach. Who said that we can have just one base |
On the one hand, I agree, on the other, we need to have well-defined plugins API anyway, the set of properties every plugin can expect that every editor has. It might be better to have such API defined as base |
Base The problem with the base class is deciding what should be there and then handling situations when you want to have an editor which doesn't implement these properties (like |
This was heavily reviewed and changed over the last months, so I think we can close this ticket. |
In order to create your custom editor you need to understand currently the following paths of classes (assuming that you're creating your editor based on the classic one):
Editor
->StandardEditor
->ClassicEditor
Controller
) ->EditorUI
->BoxedEditorUI
->ClassicEditorUI
View
) ->EditorUIView
->BoxedEditorUIView
Both chains are long and smell bad (cause you should favor composition over inheritance). We also noticed that the editor interfaces must be exposed (#303) for the feature authors to understand whether a proper editor was used.
OTOH, this chain of inheritance let us limit the length of the
ClassicEditor
to the real minimum. Also, there's nothing wrongly placed at the moment – each class indeed defines the behaviours that it introduces. If you know the base classes that you want to use for your editor (e.g.StandardEditor
,BoxedEditorUI
andBoxedEditorUIView
, you really don't need to code or care much.So, I'm curious whether we could change much in this picture. Some ideas that I have:
Editor
intoStandardEditor
and document what part comes from where by defining interfaces (theStandardEditor
will implement a couple of them).StandardEditor
and their implementers will need to know only this one.Editor
class and all this will have to be moved to theStandardEditor
. It can also be moved to a helper function (kinda mixin which could e.g. be applied in thecreate()
method – in fact, theinitPlugins
method is already used there, so it could also be moved out of the class).EditorUIView
doesn't make much sense (at least at the moment) – we could get rid of it by extracting the icon logic to a helper. It'd also be nice if we could symmetrically removeEditorUI
, but this class makes more sense.BoxedEditorUI
– it's similar toEditorUIView
– it doesn't contain any interesting behaviour. It only defines things.The resulting architecture would be:
StandardEditor
(see ad1) ->ClassicEditor
Controller
) ->EditorUI
->ClassicEditorUI
(see ad2)View
) ->BoxedEditorUIView
(see ad3)(ad1) implements sth like
EditorInterface
,StandardEditorInterface
.(ad2) needs to contain the minimum code which
BoxedEditorUI
contains now.(ad3) defines everything that this specific view has.
The text was updated successfully, but these errors were encountered: