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

Add is() method to other model/view objects #4479

Closed
Reinmar opened this issue Feb 7, 2019 · 10 comments · Fixed by ckeditor/ckeditor5-engine#1736
Closed

Add is() method to other model/view objects #4479

Reinmar opened this issue Feb 7, 2019 · 10 comments · Fixed by ckeditor/ckeditor5-engine#1736
Assignees
Labels
package:engine type:improvement This issue reports a possible enhancement of an existing feature.
Milestone

Comments

@Reinmar
Copy link
Member

Reinmar commented Feb 7, 2019

After https://github.com/ckeditor/ckeditor5-engine/issues/1663 Range, Position, Marker and perhaps something else will still miss this method. Let's add it.

Also, lets remove as many instanceof checks from packages other than engine.

One remaining thing to check would be how often we use instanceof to distinguish between model and view things. Perhaps we could also have is( 'view:element' ) and secure our code a bit with this.

@msamsel
Copy link
Contributor

msamsel commented May 10, 2019

Also, lets remove as many instanceof checks from packages other than engine.

I search through CKE5 repositories and I couldn't find any relations outside of engine package. Do you have some example where it is used? Maybe I make wrong search query.

@jodator
Copy link
Contributor

jodator commented May 10, 2019

@msamsel some of them were removed already or doesn't really existed for view entries. You can double check it with imports from engine - they shouldn't be necessary for affected elements.

Ie I've only see imports of Observers (separate issue),

@msamsel
Copy link
Contributor

msamsel commented May 13, 2019

Thx @jodator for the hint. So I make double check for the import to have sure that haven't missed anything.

@Reinmar
Copy link
Member Author

Reinmar commented May 14, 2019

One remaining thing to check would be how often we use instanceof to distinguish between model and view things. Perhaps we could also have is( 'view:element' ) and secure our code a bit with this.

What do you think about this? cc @pjasiun

@msamsel
Copy link
Contributor

msamsel commented May 14, 2019

Perhaps we could also have is( 'view:element' ) and secure our code a bit with this.

I've already make this change as it was quite simple and I already work with related code.

@scofalik
Copy link
Contributor

scofalik commented May 14, 2019

Ugh, no. If you don't know if you are dealing with the view or with the model you did something horribly wrong.

Is there any use case for this? I can't imagine...

@msamsel
Copy link
Contributor

msamsel commented May 15, 2019

if you are dealing with the view or with the model you did something horribly wrong.

It's quite good point. I haven't thought about it from such perspective.

@Reinmar
Copy link
Member Author

Reinmar commented May 15, 2019

@scofalik, that may be a part of some method's input validation. That you check whether the input are the proper positions. And if you'd do is( 'position' ) then it will accept both positions – from the model and the view. And this is actually a quite common issue that people use the wrong type of arguments and also quite tough to find, because e.g. view and model ranges have both start and end properties and couple others too.

@scofalik
Copy link
Contributor

We almost never did this kind of validation and simply disregarded issues when people use wrong parameters in functions. I still think this is not needed.

@Reinmar
Copy link
Member Author

Reinmar commented May 21, 2019

Really? I would love if e.g. all writer methods were secured. And perhaps a lot of conversion and other plugin-developer-facing things.

Also, I'm really unsure if we can say that we're not doing this yet. Whenever we use instanceof now we're actually checking the type (model/view). If we'll replace those things with is() then we lose that.

However, we don't plan to change the engine (the only place where we use instanceofs), so I'm fine with that.

Reinmar referenced this issue in ckeditor/ckeditor5-engine Aug 14, 2019
Feature: Introduced the `is()` method to additional objects from the model and view realms. Closes #1667.
@mlewand mlewand transferred this issue from ckeditor/ckeditor5-engine Oct 9, 2019
@mlewand mlewand added this to the iteration 26 milestone Oct 9, 2019
@mlewand mlewand added status:confirmed type:improvement This issue reports a possible enhancement of an existing feature. package:engine labels Oct 9, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
package:engine type:improvement This issue reports a possible enhancement of an existing feature.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants