-
-
Notifications
You must be signed in to change notification settings - Fork 3.7k
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Check if writer is not used outside a change block #4224
Comments
I'm pretty sure that all uses o writer are inside a block. There are a few places where writer is passed as a param but everything is wrapped by a block. I'm talking about |
This is not about checking the current state. This about adding a check for the future to ensure that third-party plugins developers will not do something stupid. |
I'm assuming that all writer tests will need the EDITED: Now I see, that this can't be done with the above hack, so all tests need to be rewritten and should use the |
This is not necessary for tests. Writer tests should create Writer instance by |
Ok, I understand now. Writer tests will throw otherwise. |
Maybe it will be OK to do something as writer = new Writer();
model._currentwriter = writer; for writer tests. |
I've thought the same. But some writer methods calls in tests internally E.g. this test uses it. (I put the
I also think, that using |
I think there are ways we could overwrite this check. For instance, the check could be done in a separate protected method which can be overwritten. However, in all cases it will be a hack and test will not check what they really should check. Especially more complicated tests could be unstable and hard to debug with such hacks. So, I think it will be better to have these tests using However, to make tests writing simpler they could use helpers like: function createElement( name ) {
model.change( writer => {
writer.createElement( 'child' );
}
} |
I was thinking about the same. |
I agree with this approach. But note, that there will be a lot of such methods and some of them will be a little bit longer. E.g. function createElement( name, attributes ) {
let element;
model.change( writer => {
element = writer.createElement( name, attributes );
}
return element;
} And it will be possible only in tests, that don't check batches. Otherwise, we'd have to implement the second method using |
Which makes me think that
|
Or maybe we could use |
It does return. You should write these methods this way. |
Oh, so I'll change them. |
Other: Prevented `Writer` from usage outside of the `change` block. Closes #1212.
The model writer should be used only inside
enqueueChange
,change
or post fixer block. It can be passed to the inner function, but should not be stored in a variable and used outside of the proper block. Fortunately, we should be able to check it easily.Each writer method, when called, should check if
this.model._currentWritter == this
and throw exception if it is not true.The text was updated successfully, but these errors were encountered: