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

Simplify batches/deltas and change event #3882

Closed
pjasiun opened this issue Nov 14, 2016 · 7 comments
Closed

Simplify batches/deltas and change event #3882

pjasiun opened this issue Nov 14, 2016 · 7 comments

Comments

@pjasiun
Copy link

pjasiun commented Nov 14, 2016

I do not believe anymore that users will create their own Deltas. It will not gonna happen. So we can simplify this piece of the API:

I'm not sure about two thinks:

  • how relations between Batch, Delta and applyDelta should look like: do I need to pass Batch to the Delta constructor? Do I need to add Delta to the Batch? In fact, I need to add delta to the batch and apply it at the same time so, maybe I should pass both Delta and Batch to the applyDelta and it will add delta to the batch? Or adding Delta to the Batch should apply it since Batch knows about the document?
  • if there will be a reach constructor in each Delta class won't it be a problem for the OT where we need to create a delta in a custom way? The simplest solution would be to keep the constructor empty and move the register logic to the init method, which can not be called in the OT, but then we make the API more complicated again.
@Reinmar Reinmar changed the title Simplified batches/deltas Simplify batches/deltas Nov 15, 2016
@Reinmar
Copy link
Member

Reinmar commented Nov 15, 2016

https://github.com/ckeditor/ckeditor5-engine/issues/678 describes the bigger picture of this change.

@Reinmar
Copy link
Member

Reinmar commented Nov 15, 2016

Quick thought, without much of an analysis: Each delta module should expose a function called like today's Batch methods. So instead of:

model.batch().insert( what, where );

you'd do:

const batch = model.createBatch();
insert( batch, what, where );

That insert() would do all the steps:

  1. create delta,
  2. add it to the batch,
  3. apply the delta.

We have hundreds of batch.xxx() usage and this made me think that we must not complicate this too much. So the 3 steps above shouldn't be required to be done manually.

@pjasiun
Copy link
Author

pjasiun commented Jan 31, 2017

Reviewing ckeditor/ckeditor5-engine#793 I realized that we should also update the change event. Now it's very messy. It could be fired not per operation, but per delta and contains operations as internal. Fortunately, because big part of the code is listening on the dispatcher, not on the change event, it might be not that hard to change as it looks like.

@Reinmar
Copy link
Member

Reinmar commented Jan 31, 2017

That's a part of a whole topic – https://github.com/ckeditor/ckeditor5-engine/issues/678.

@pjasiun pjasiun changed the title Simplify batches/deltas Simplify batches/deltas and change event Aug 25, 2017
@pjasiun
Copy link
Author

pjasiun commented Aug 25, 2017

Fixing https://github.com/ckeditor/ckeditor5-engine/issues/1099 we decided to fire change event also when there is no real change (for instance rename to the same value). This is because there is no other event which let you notice that operation was applied and some plugins need such information. We should consider having a more abstract change event for regular plugins which is fired only when there is real change (this is what most plugins except) and some internal event (operationApplied) for deeper integration.

@Reinmar
Copy link
Member

Reinmar commented Oct 17, 2017

A case that we need to consider here is that people will try to use the change event to handle... changes. And the problem with this event is that after each atomic change is applied is that the temporary state may be incorrect.

E.g. see #599 (comment). This code is not only unnecessarily slow but also dangerous because after some changes getData() might not work.

If we'll introduce API for postfixer there's a chance that we should hide the atomic change event and only expose event like changesDone (perhaps with more info) which is going to be the one that people should use. In other words – I don't see use cases for atomic change event.

@pjasiun pjasiun closed this as completed Dec 19, 2017
@mlewand mlewand transferred this issue from ckeditor/ckeditor5-engine Oct 9, 2019
@mlewand mlewand added this to the iteration 14 milestone Oct 9, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants