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

Preparation for #8452: 'jquery' package extraction #13839

Closed
wants to merge 14 commits into from

Conversation

klimov-paul
Copy link
Member

@klimov-paul klimov-paul commented Mar 23, 2017

Q A
Is bugfix? no
New feature? yes
Breaks BC? yes
Tests pass? yes
Fixed issues #12588, preparing for #8452

'jquery' package has been extracted as preparation for yii2-jquery repo extraction, which will allow to create requirements free version of Yii2 and make composer-asset-plugin installation to be optional.

@klimov-paul klimov-paul added severity:BC breaking Either breaks backwards compatibility or fixed previously made breakage status:under discussion type:enhancement labels Mar 23, 2017
@klimov-paul klimov-paul added this to the 2.1.0 milestone Mar 23, 2017
@rob006
Copy link
Contributor

rob006 commented Mar 23, 2017

Can't we just use jQuery from CDN by default?

@klimov-paul
Copy link
Member Author

Can't we just use jQuery from CDN by default?

It makes no difference. PHP framework should not be bound to any JavaScript framework.
It should be developer choice if he wishes to use 'JQuery', 'ReactJS', 'Angular' or anything else.

@rob006
Copy link
Contributor

rob006 commented Mar 23, 2017

It makes no difference.

It fixes main issue - you don't need asset plugin anymore and you can install Yii without any frontend dependencies.

I agree that framework-agnostic approach is generally good thing, but it looks like overkill and unnecessary complication. If I want write extension which extends GridView, which class I should use as a base class?

@klimov-paul
Copy link
Member Author

klimov-paul commented Mar 23, 2017

I agree that framework-agnostic approach is generally good thing, but it looks like overkill and unnecessary complication.

Following your arguments, should not we bind Yii2 to Twitter Bootstrap as well? Why keep yii2-bootstrap as a separated repo? Does not it produce an 'overkill and unnecessary complication'?

If I want write extension which extends GridView, which class I should use as a base class?

It depends on what you want to do: you may use yii\grid\GridView and provide your own JS layer for its filter - or do not use any JS layer, but a regular HTML form submit. Or you can extend yii\jquery\GridView and inherit related JQuery code with it.

I am fixing the issues, which are opened and which core team has agreed to be fixed. If you wish to debate on necessity of such changes use the related issues for that: #8452, #11792, #10557, #8709, #9525.
When you are able to convince @WadeShuler, @leandrogehlen, @graphicmist, @fabiocarneiro and others that thier arguments are unfounded I will discard this PR.

@klimov-paul
Copy link
Member Author

This PR fixes #12588

@rob006
Copy link
Contributor

rob006 commented Mar 23, 2017

Following your arguments [...]

Please, be constructive...

It depends on what you want to do [...]

My extension is not related to JS at all so I may use any of this class. But if I use yii\grid\GridView as a base class people who want use jQuery stuff in GridView will not be able to use my widget. If I use yii\jquery\GridView, I will force users to download all this frontend dependencies. So basically I need create and maintain 2 extensions instead of 1.

I am fixing the issues, which are opened and which core team has agreed to be fixed. If you wish to debate on necessity of such changes use the related issues for that: #8452, #11792, #10557, #8709, #9525.

Did you at least read these issues before linking? They are mostly about installing frontend dependencies, which may be solved by using CDN fallback. Some of them even proposing using CDN for jQuery.

@samdark
Copy link
Member

samdark commented Mar 23, 2017

Hmm... @rob006 has a point about having two separate GridViews...

You should use `yii\jquery\*` package classes instead, to make old code function as before. E.g. use `yii\jquery\ActiveForm` instead
of `yii\widgets\ActiveForm`, `yii\jquery\GridView` instead of `yii\grid\GridView` and so on.

* Assets `yii\web\JqueryAsset`, `yii\web\YiiAsset`, `yii\validators\ValidationAsset`, `yii\captcha\CaptchaAsset` have been
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was planning extracting Captcha in its own package.

@dynasource
Copy link
Member

I agree with @rob006 , I'm positive towards disentanglement of parts, but I dont like the overuse of inheritance in the framework. This is not exactly favoring 'composition' over inheritance and limits flexibility.

@samdark
Copy link
Member

samdark commented Mar 23, 2017

@dynasource any ideas on how to do it better?

@dynasource
Copy link
Member

like I said, encapsulate the logic in dependencies instead of inheritance. All these JS parts deserve their own classes and should not pollute the inheritance tree.

@dynasource
Copy link
Member

this is also an example of GridView has jQuery instead of GridView is jQuery
https://en.wikipedia.org/wiki/Composition_over_inheritance#Benefits

@samdark
Copy link
Member

samdark commented Mar 23, 2017

I understand the theory. I was asking about its practical application for this particular case.

@samdark
Copy link
Member

samdark commented Mar 24, 2017

As I said above it could be a behavior.

I like the idea. It could be configured via container as well...

@samdark
Copy link
Member

samdark commented Mar 24, 2017

Anyway both yii2-captcha and yii2-jquery should be composed inside 2.1 branch before using GIT tree subsplit.

Why? I've successfully extracted https://github.com/yiisoft/yii2-maskedinput without doing a subsplit...

@samdark
Copy link
Member

samdark commented Mar 24, 2017

The main question is where JQuery dependent part of Captcha widget should be located in the end: at yii2-captcha or at yii2-jquery?

At yii2-captcha but it should be a behavior or a separate class. Not a widget inherited from Captcha.

@samdark
Copy link
Member

samdark commented Mar 24, 2017

Client validators can be extracted into a separated classes mapped to the existing server-side validators.
But they will be almost empty containing a 3-4 lines of code. Still I can adjust code in this way if you like.

I think it would make perfect sense.

@klimov-paul
Copy link
Member Author

Why? I've successfully extracted https://github.com/yiisoft/yii2-maskedinput without doing a subsplit

Subsplit is better as it will preserve the git history.

At yii2-captcha but it should be a behavior or a separate class. Not a widget inherited from Captcha.

So it will, but my question still stands:

where JQuery dependent part of Captcha widget should be located in the end: at yii2-captcha or at yii2-jquery?

If it will be located at yii2-captcha it will mean that this package will be dependent on yii2-jquery and can not be used without it. Thus it will be impossible to create a CAPTCHA solution without installing jQuery.
If it will be located yii2-jquery it will be dependent on yii2-captcha, thus you'll have to install captcha before using jQuery even if you do not need it.
The solid way to resolve it will be creating a 3rd package, which will depend on both yii2-captcha and yii2-jquery, but this may be an overcomplication.
Another solution can be putting JS-dependent part at one of yii2-captcha or yii2-jquery without explicit dependency ('suggets' composer section can be used for example), but this can be inconsistent.

@samdark
Copy link
Member

samdark commented Mar 27, 2017

About jQuery-related part of CAPTCHA, I prefer to rewrite JS part of it without using jQuery. yii.captcha.js isn't too complicated to do it.

@leandrogehlen
Copy link
Contributor

leandrogehlen commented Mar 27, 2017

My suggestion.

yii2-widgets (base widigets without js or css dependencies)
yii2-jquery (GridViewBehavior, and assets and capcha) everthing that use jquery

and yii2-jquery must be separated from core framework

@samdark
Copy link
Member

samdark commented Mar 27, 2017

@leandrogehlen separating widgets completely isn't the goal of this pull request.

@leandrogehlen
Copy link
Contributor

Ok, then , i think that the folder grid should be moved to widgets and removed assets dependencies from this classes, this way we can write a grid with jQuery and another with Angular , thus each extension can write a grid behavior with js library desired

@klimov-paul
Copy link
Member Author

Solution has been refactored:

  • Client script for ActiveForm, GridView and Captcha extracted into a behaviors.
  • Client validation composition chnaged to use class map and special ClientValidator class
  • captcha related code packed under framework/captcha

@samdark
Copy link
Member

samdark commented Mar 27, 2017

Looks good after quick glance on it. Need to check it in depth though.

@schmunk42
Copy link
Contributor

I took a look at this and actually, the PR was looking good, at least no assets folder anymore in the framework.

I tried to merge against 2.1, but it looked to me like there were a lot of clientXyz functions added again?!

I think also that all the remaining asset-bundles should be removed from the core, but one step after the other...
bildschirmfoto 2017-09-05 um 16 43 19

Can this be made mergeable again?

@klimov-paul
Copy link
Member Author

Can this be made mergeable again?

At the present state I do not have time for this. I need to finish #14701 and underlying tasks, which depends on it. Otherwise, it will likely end in conflicts anyway.

Most likely, I will re-create this PR from scratch afterwards.

Since, at the present state, core team has no interest on reviewing this or attend to the underlying issue, it is not in hurry. Even if I merge this changeset, it will solves nothing until the jquery and captcha reositories will be split. While I do not have enough permissions to create a repositories under yiisoft, I am unable to to do it myself.
Without major core team suport this PR moves nowhere anyway.

@schmunk42
Copy link
Contributor

it will solves nothing until the jquery and captcha reositories will be split. While I do not have enough permissions to create a repositories under yiisoft, I am unable to to do it myself.

100% agreed! @samdark Could you create those repos for 2.1 (yii2-jquery and yii2-captcha; also yii2-pjax)? Those need to be moved out.

@samdark
Copy link
Member

samdark commented Sep 6, 2017

PJAX is to be removed so I haven't created a repo for it.

@klimov-paul
Copy link
Member Author

Migrated to #14865

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
severity:BC breaking Either breaks backwards compatibility or fixed previously made breakage status:under discussion type:enhancement
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants