Skip to content
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

Handle remote data while editor initialization #2932

Closed
oskarwrobel opened this issue Mar 3, 2018 · 1 comment · Fixed by ckeditor/ckeditor5-core#123
Closed

Handle remote data while editor initialization #2932

oskarwrobel opened this issue Mar 3, 2018 · 1 comment · Fixed by ckeditor/ckeditor5-core#123
Assignees
Labels
package:core type:improvement This issue reports a possible enhancement of an existing feature.
Milestone

Comments

@oskarwrobel
Copy link
Contributor

To set editor initial data we are using ElementApiMixin#loadDataFromElement that gets data from DOM element and sets it using DataController#set. After that Editor#dataReadyevent is fired.

This works fine when DOM is the only data source but does not make possible to sync editor with remote data while initialization process.

The idea is to decorate DataController#set method to make possible to override it and do some additional stuff. Besides ElementApiMixin#loadDataFromElement should return DataController#set in case that overridden method will return promise.

@oskarwrobel oskarwrobel self-assigned this Mar 3, 2018
@Reinmar
Copy link
Member

Reinmar commented Mar 5, 2018

We're entering a thin ice here. For now, the entire editor API was synchronous. As soon as some methods become asynchronous, you can never be sure how to use them unless we have a very good plan for that.

This situation is, unfortunately, very well known to me from CKEditor 4. In CKEditor 4 setData() was asynchronous because we used iframed editables (by default). However, sometimes (not sure if still, but that was true for some time), it acted synchronously if different kind of editor was used. This caused serious confusion and a lot of bugs.

However, fortunately, CKEditor 5 introduced a little detail which heavily affects this situation – the custom data model. What does it give us here? It means that setData() might be asynchronous, but the data will be available immediately.

In CKEditor 4 the data is only available from the editable. Which means that for a brief moment between setData() and dataReady, you cannot operate on your model/view.

In CKEditor 5, setData() will change the model synchronously and it will synchronously be rendered. The only thing which is asynchronous will be the dataReady event. It means that, e.g., two subsequent setData() calls or setData(); getData() will work. Actually – we must make them work!

So, to sum up – I can only agree to make setData() asynchronous if the only asynchronous thing in it is dataReady.

cc @pjasiun

pjasiun referenced this issue in ckeditor/ckeditor5-core Mar 9, 2018
Other: Removed loadDataFromElement method from ElementApiMixin. Closes #120.
pjasiun referenced this issue in ckeditor/ckeditor5-engine Mar 9, 2018
Feature: Introduced decorable DataController#init metohd. Closes ckeditor/ckeditor5-core#120.
@mlewand mlewand added this to the iteration 14 milestone Oct 9, 2019
@mlewand mlewand added status:confirmed type:improvement This issue reports a possible enhancement of an existing feature. package:core labels Oct 9, 2019
@mlewand mlewand transferred this issue from ckeditor/ckeditor5-core Oct 9, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
package:core type:improvement This issue reports a possible enhancement of an existing feature.
Projects
None yet
3 participants