Opened 10 years ago
Closed 10 years ago
#12150 closed New Feature (fixed)
Expose getNestedEditable and is* widget helper functions
Reported by: | Piotrek Koszuliński | Owned by: | Artur Delura |
---|---|---|---|
Priority: | Normal | Milestone: | CKEditor 4.5.0 Beta |
Component: | UI : Widgets | Version: | 4.3 Beta |
Keywords: | Cc: |
Description
They are useful also for widgets definitions, so they should not be private.
Change History (31)
comment:1 Changed 10 years ago by
Status: | new → confirmed |
---|---|
Version: | → 4.3 Beta |
comment:2 Changed 10 years ago by
Owner: | set to Artur Delura |
---|---|
Status: | confirmed → assigned |
comment:4 Changed 10 years ago by
Status: | assigned → review |
---|
comment:5 Changed 10 years ago by
We have a standard that says - constructors in the public API are lowercased. You can find this everywhere except undo plugin. So in this case the undo plugin is incorrect and moreover, what the undo plugin exposes is private, so we could change that, but what the widget plugin exposes is public so we can't touch this.
comment:6 follow-up: 7 Changed 10 years ago by
Status: | review → review_failed |
---|
Since we are adding methods to public API we need at least basic tests for them.
Moreover:
@returns {CKEDITOR.dom.element|null} Element
- this notation is incorrect - null is not a type. Null is "not an object". Usually we explain in the textual part of returned value's description that null may be returned. For example: "Widget wrapper ornull
if wrapper was not found.".- The newly defined methods should be moved to the right place - this can be e.g. right after Widget class prototype. Now they are surrounded by private stuff.
comment:7 Changed 10 years ago by
Replying to Reinmar:
@returns {CKEDITOR.dom.element|null} Element
- this notation is incorrect - null is not a type. Null is "not an object". Usually we explain in the textual part of returned value's description that null may be returned. For example: "Widget wrapper ornull
if wrapper was not found.".
Why null
is not a type? Why null
is not an object? And finally: Why overcomplicate things and not keep them semantic? I know that there is no constructor for null
, but AFAIK JSDuck support values in @param
, @return
etc. See here.
comment:8 Changed 10 years ago by
Agree. CKEDITOR.dom.element|null}
is far more readable then description. On the other hand if we use one convention we should stick to it.
comment:9 follow-up: 10 Changed 10 years ago by
Hmm... You're right. I must have remembered this incorrectly.
So - I'm ok with null
in the type of returned value, but remember that we use /
, not |
. And still it's sometimes good to explain when null
may be returned (not in this case though).
comment:10 Changed 10 years ago by
Replying to Reinmar:
Hmm... You're right. I must have remembered this incorrectly.
So - I'm ok with
null
in the type of returned value, but remember that we use/
, not|
. And still it's sometimes good to explain whennull
may be returned (not in this case though).
Added extra commit with fixes. Do we need test for is* methods? They are simple as hell, I dunno. Changes in branch:t/12150.
comment:12 Changed 10 years ago by
Status: | review_failed → review |
---|
I added extra tests. Plase don't check jscs
because they will be fixed directly in major
. Changes in branch:t/12150.
comment:13 Changed 10 years ago by
Plase don't check jscs because they will be fixed directly in major.
I don't understand. Major is clean, so the branch should be clean too.
comment:14 Changed 10 years ago by
Status: | review → assigned |
---|
Major is dirty, but I'll handle all so I'm getting off from review for a while.
comment:15 Changed 10 years ago by
Status: | assigned → review |
---|
comment:16 Changed 10 years ago by
I measured how big is the file size increase of minified widgets plugin.js and minified ckeditor.js build with the widget plugin, before and after changes:
branch | major | diff | % increase | |
---|---|---|---|---|
plugins.js | 28649 | 28041 | 608 | 2 |
plugins.js.gz | 9314 | 9238 | 76 | 0.8 |
ckeditor.js | 559108 | 558481 | 627 | 0.11 |
ckeditor.js.gz | 166127 | 166019 | 108 | 0.065 |
Change is not very big, but making methods public makes editor package definitely bigger.
comment:17 Changed 10 years ago by
Very interesting analysis. One more thing that I'm curious is what would be the result if in the widget plugin we used these functions via their names (as isXxx()
) instead by using them as Widget.isXxx()
and we exported them to the Widget
constructor in one place.
comment:18 follow-up: 22 Changed 10 years ago by
Anyway R- because of this test. Generally it is bad practice to create big tests. If such tests fail, you do not know what goes wrong and need to learn how the whole test works. Tests should be as small and as simple as possible. One test should check only one thing. Especially in this case when you have multiple isTrue
/isFalse
assertions without descriptions, so if one of then will fail you will have no idea what is wrong.
comment:19 Changed 10 years ago by
Status: | review → review_failed |
---|
comment:20 Changed 10 years ago by
BTW. I noticed that API documentation needs to be fixed.
- Order of tags is incorrect.
- The @member tag does not have to be specified.
- Some descriptions are missing.
- In few places I found
{boolean}
. The type is{Boolean}
.
comment:21 Changed 10 years ago by
Also this commit should be squashed with the previous one with introduce these changes.
comment:22 Changed 10 years ago by
Replying to pjasiun:
Anyway R- because of this test. Generally it is bad practice to create big tests. If such tests fail, you do not know what goes wrong and need to learn how the whole test works.
Generally speaking yes, but this is test for static functions. Each part is independent, I think this test need more comments (each assert might have a message what is expected, and DOM elements might be described) rather than split into parts.
comment:23 Changed 10 years ago by
Generally speaking yes, but this is test for static functions. Each part is independent, I think this test need more comments (each assert might have a message what is expected, and DOM elements might be described) rather than split into parts.
This test should be split into far more than 2 test. Basically - one test per one method. You should avoid testing more than one thing at a time. Sometimes it's hard, but this time it's simple.
comment:24 Changed 10 years ago by
Status: | review_failed → assigned |
---|
comment:25 Changed 10 years ago by
Owner: | changed from Artur Delura to Piotrek Koszuliński |
---|---|
Status: | assigned → review |
I pushed two fixes to branch:t/12150:
- First adds docs.
- Second hides two methods which have no value for other developers.
comment:26 Changed 10 years ago by
Status: | review → review_failed |
---|
Tests are still not good enough.
Firstly I have no idea what this test do. Why the first and third assertion should be false
, and the second true
? I have also no simple why to check if the method is covered properly. If such test fail I will not know which assertion is red and why. The same about the rest of the refactored tests.
The simplest solution is to add description message to assertions, but it is better to create separate tests with that description in the tests name. It is not more work and this way we would know which assertions fails (not only the first) and why.
Secondly parserEl1..5 are meaningless names for variables. Test would be far more readable if you would use:
assert.isFalse( Widget.isParserWidgetElement( parserElDataWidgetFalse ) );
Instead of:
assert.isFalse( Widget.isParserWidgetElement( parserEl3 ) );
Finally, we do not check if static functions exists, especially when we check if it works properly in the same test suit, so this test is not needed.
comment:27 Changed 10 years ago by
Owner: | changed from Piotrek Koszuliński to Artur Delura |
---|---|
Status: | review_failed → review |
Changes in branch:t/12150.
comment:28 Changed 10 years ago by
I rebased branch on newest major and pushed one more tests improvement. But I have one more doubt.
Would not it better to have isWidgetElement
method which accept both CKEDITOR.dom.node
and CKEDITOR.htmlParser.node
instead of two methods? The same for is*WidgetWrapper
. Our API would be simpler and build smaller. Also we could replace isDom*
with just is*
, because this is not clear what this Dom
stands for? I understand that this is the type of the parameter and it makes sense for internal usage, but as an API it looks bad and the type of the parameter is described anyway.
comment:29 Changed 10 years ago by
Those functions cannot be merged without complicating them internally (it must be checked whether an argument is an instance of X or Y or none), writing more tests etc. Complication will affect performance and tests will need time. Both are things I would like to avoid, especially at this stage of working on this ticket.
comment:30 Changed 10 years ago by
Also, we need to remember that these are helper methods, not a first-level API which should be optimised in terms of usage and clarity.
comment:31 Changed 10 years ago by
Resolution: | → fixed |
---|---|
Status: | review → closed |
Ok. So I closed this ticket as it is. git:96d5130
I think we should expose constructors in such way. I see that we don't have standard for that.
Changes in branch:t/12150, but I think we should also make changes listed above.