-
-
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
Singleton for styles processor was a bad idea #6091
Comments
We've got 👍 from @scofalik for the first option, so let's do this :) |
Yes, singletons are always bad :D The other idea was to not allow extend the style processing rules. This is not feasible as we want to have this style processing rules added only when needed. Taken this into consideration I don't see any other "clean" way of doing this. The style processing rules should be added per document context so the |
After adding the
I am still trying to understand one test that fails:
After fixing that, I'll be ready for closing the first part of the issue. |
Ok, I found it. https://github.com/ckeditor/ckeditor5-engine/blob/7ab19cff179b375e3bd1fb7e5413529423a473c6/src/conversion/downcasthelpers.js#L546 will be always true.
and all the tests are green. |
During this point in the issue, we decided to create a single instance of the StyleProcessor in the core Editor class. Why? The result of the downcast and the upcast conversions must be the same. It's also safer and easier to add processing rules in a single place instead of creating a few instances of SP. It means, we need to pass the instance of SP to:
All I need to do now is fix all failing tests because (again) we changed APIs of many classes. But I guess, we achieved the goal. cc: @jodator |
Yes. Looking at where it is passed we need to have a single instance injected as a dependency on all of those classes so the behavior is consistent in all of the pipelines. Another thing is that to allow extensibility of this system we have The other way around this I see is to have
|
Internal: Adjusted the code to changes required for replacing the `StylesProcessor` singleton with an instance of the class. See ckeditor/ckeditor5#6091.
Internal: Adjusted the code to changes required for replacing the `StylesProcessor` singleton with an instance of the class. See ckeditor/ckeditor5#6091.
Internal: Adjusted the code to changes required for replacing the `StylesProcessor` singleton with an instance of the class. See ckeditor/ckeditor5#6091.
Internal: Adjusted the code to changes required for replacing the `StylesProcessor` singleton with an instance of the class. See ckeditor/ckeditor5#6091.
Internal: Adjusted the code to changes required for replacing the `StylesProcessor` singleton with an instance of the class. See ckeditor/ckeditor5#6091.
Internal: Adjusted the code to changes required for replacing the `StylesProcessor` singleton with an instance of the class. See ckeditor/ckeditor5#6091.
Internal: Adjusted the code to changes required for replacing the `StylesProcessor` singleton with an instance of the class. See ckeditor/ckeditor5#6091.
Other: Adjusted the data processor implementation to changes in `ckeditor5-engine`. See ckeditor/ckeditor5#6091. MAJOR BREAKING CHANGES: The `GFMDataProcessor()` requires the view document instance as its first parameter.
Internal: Adjusted the code to changes required for replacing the `StylesProcessor` singleton with an instance of the class. See ckeditor/ckeditor5#6091.
Internal: Adjusted the code to changes required for replacing the `StylesProcessor` singleton with an instance of the class. See ckeditor/ckeditor5#6091.
Internal: Adjusted the code to changes required for replacing the `StylesProcessor` singleton with an instance of the class. See ckeditor/ckeditor5#6091.
Internal: Adjusted the code to changes required for replacing the `StylesProcessor` singleton with an instance of the class. See ckeditor/ckeditor5#6091.
Internal: Adjusted the code to changes required for replacing the `StylesProcessor` singleton with an instance of the class. See ckeditor/ckeditor5#6091.
Internal: Adjusted the code to changes required for replacing the `StylesProcessor` singleton with an instance of the class. See ckeditor/ckeditor5#6091.
Internal: Adjusted the code to changes required for replacing the `StylesProcessor` singleton with an instance of the class. See ckeditor/ckeditor5#6091.
Other: `StylesProcessor` rules will not be stored in a singleton, which made them shared between editor instances. In order to allow binding a styles processor instance to a specific view document, we had to replace a dynamic `#document` property in view nodes with a static one, set upon node creation. Closes ckeditor/ckeditor5#6091. MAJOR BREAKING CHANGES: `EditingController` requires an instance of StylesProcessor in its constructor. MAJOR BREAKING CHANGES: `DataController` requires an instance of StylesProcessor in its constructor. MAJOR BREAKING CHANGES: `DomConverter`, `HtmlDataProcessor` and `XmlDataProcessor` require an instance of the view document in their constructors. MAJOR BREAKING CHANGES: The `View` class requires an instance of `StylesProcessor` as its first argument. MAJOR BREAKING CHANGES: The `createViewElementFromHighlightDescriptor()` function that is exported by `src/conversion/downcasthelpers.js` file requires an instance of the view document as its first argument. MAJOR BREAKING CHANGES: Method `view.Document#addStyleProcessorRules()` has been moved to DataController class. MINOR BREAKING CHANGES: `DataController` does not accept the data processor instance any more. MAJOR BREAKING CHANGES: The `#document` getter was removed from model nodes. Only the root element holds the reference to the model document. For attached nodes, use `node.root.document` to access it.
Internal: Adjusted the code to changes required for replacing the `StylesProcessor` singleton with an instance of the class. See ckeditor/ckeditor5#6091.
Internal: Adjusted the code to changes required for replacing the `StylesProcessor` singleton with an instance of the class. See ckeditor/ckeditor5#6091.
📝 Provide a description of the improvement
So, when making a decision that we can go with a styles processor singleton I was only thinking how one editor can affect another. That was a bit fishy, but acceptable.
However, then, thank god, I realized that test files will affect one another and that's just too ugly. There's no reasonable way to clean this up other than just stop using singleton.
Why didn't we use a singleton in the first place? Because we need an access to a view document from all elements. Through that document we ca access a styles processor of that particular view document.
Interestingly, I've just checked that view nodes have the
#document
property but it's going to work only for elements that are in the document already. This is not going to work for document fragments and detached nodes unfortunately.I can see two options here:
#document
return the document based on a writer which created it. Both writers (upcast and downcast) will have to have the#document
property too. The#document
could only be changed when a node is inserted to an element/docfrag from a different#document
.#document
that I proposed in the former point.cc @scofalik @jodator
Steps
#document
property toview.Node
andview.DocumentFragment
. This property will be passed to those nodes/dfs through the first param of their constructors. This requires passingdocument
toUpcastWriter
(DowncastWriter
already knows about the document).view.Element#_styles
map.If you'd like to see this improvement implemented, add a 👍 reaction to this post.
The text was updated successfully, but these errors were encountered: