-
Notifications
You must be signed in to change notification settings - Fork 358
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 basic Redux infra based on ng-redux #2504
Conversation
Suggestions for future improvements:
Next up, I'll start working on adding basic extensible components API based on the existing proposal. |
/cc @chalettu |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thanks @vojtechszocs I've left a few inline comments, overall looking good from reading mostly the tests, I still find it much harder to read typescript.
@@ -14,6 +14,7 @@ | |||
//= require angular-bootstrap/ui-bootstrap-tpls | |||
//= require angular-sanitize | |||
//= require angular.validators | |||
//= require ng-redux/dist/ng-redux |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why do we need to load it via the asset pipeline? I was under the assumption we can load it directly to the browser from webpack.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well this is because the main angular app is bootstrapped here miq_angular_application.js#L1 and sadly you cannot add dependencies (modules), once app is loaded.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We need to run ng-redux
main script which registers the ngRedux
module and hook it to the Angular application module.
In miq_angular_application.js
we declare ngRedux
module as a dependency of ManageIQ
(application) module. The important bit is that miq_angular_application.js
is Rails-managed.
My understanding is that when Rails-managed miq_angular_application.js
executes, the ngRedux
module registration must be already done - and this implies that we need to load ng-redux
library through application.js
file.
you cannot add dependencies (modules), once app is loaded.
Officially yes, unofficially there's a way but it only works if you add those extra dependencies prior to application bootstrap (there are some undocumented APIs used by Angular injector).
@@ -0,0 +1,5 @@ | |||
import { Middleware } from 'redux'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i find the name a bit confusing with the middleware provider, maybe we should comment that this is redux middleware :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I can rename this file to redux-middleware.ts
to reduce confusion.
(Still, this file is part of miq-redux
pack which implicitly narrows down the context to Redux.)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes, the path javascript/miq-redux is pretty clear
@@ -0,0 +1,24 @@ | |||
import { IModule } from 'angular'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should we extract angular specifics into a different pack / file? just wondering if we move away from angular, ideally redux core implementation should not change
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Following files depend on Angular specifics (1.x module API):
ng-redux
based Redux store configuration:miq-redux/store.ts
- pack entry point:
packs/miq-redux-common.ts
- test helper (to allow testing specific module exports):
miq-redux/test-helper.ts
If we'd decide to move away from Angular, we'd have to change store creation, entry point code as well as tests (which currently use inject
to accept Angular managed objects).
However, I could extract all Angular stuff as shown above into a single file, say miq-redux/angular-config.ts
.
@@ -23,11 +23,15 @@ | |||
"@angular/platform-browser": "~4.0.3", | |||
"@angular/platform-browser-dynamic": "~4.0.3", | |||
"core-js": "~2.4.1", | |||
"ng-redux": "^3.5.2", | |||
"redux-devtools-extension": "^2.13.2", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No redux dependency?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No redux dependency?
redux
is pulled in through ng-redux
as transitive dependency, see here.
ng-redux@^3.5.2
relies on redux@^3.7.2
and let's say we add dependency on redux@^4.x
this might break ng-redux
expecting version 3.x APIs. This is why I didn't include redux
dependency here.
Looks good! I like that you stayed strictly to types and even used some derived types. This will definitely helps us in future, when someone will use this from some clever IDE which can make suggestions based on types. This might be interesting for you @himdel, @skateman, @dclarizio, @h-kataria, @AparnaKarve, @martinpovolny. @miq-bot add_label enhancement |
Well, I could change the code to use Flow type annotations along with The main difference for me is:
If TypeScript was used only for type checking, above mentioned difference would be irrelevant, but as of today, Note that current webpack(er) configuration supports both TypeScript and regular ES6, possibly with Flow-annotated code (using
Thanks! Question: this PR currently adds |
@vojtechszocs Would you mind dropping that The moment we start using a different name for the EDIT: if this was so that you don't have to type out + new webpack.DefinePlugin({
+ ManageIQ: 'ManageIQ'
+ }), |
What that guy said! |
@himdel I've added that |
Note that I'd really love to do things like
inside |
3efe18b
to
999b07d
Compare
I've just read about Webpacker folder structure, will do some more changes. |
Solved the issue around Global variables such as |
All done and tested locally, please review 💻 The redundant
Solution based on this comment, kudos to @geekflyer! @himdel @karelhala with TypeScript global declarations in
is subject to type checking and automatically infers |
@himdel @karelhala CC/ESLint reports that Should I update |
@vojtechszocs The latter please - we're already overriding the config for I'm guessing we should mostly stick to airbnb-es6, given we've built our es5 rules on top of their es5 ruleset. |
Signed-off-by: Vojtech Szocs <[email protected]>
Signed-off-by: Vojtech Szocs <[email protected]>
Signed-off-by: Vojtech Szocs <[email protected]>
Signed-off-by: Vojtech Szocs <[email protected]>
199c190
to
90ee5a0
Compare
@himdel @karelhala PR updated, added For now, the
Why? I've noticed that I think there should be another PR that makes the decision whether to use Standard JS or Airbnb (or whatever) and reflects that decision within Nit-pick: I see some duplicity across ESLint configs at Running |
How can I retrigger Travis if I don't have write access to the repo? |
@oourfali Once this PR is merged, component extension & reuse PR is planned as the next step. |
@vojtechszocs i was able to restart it by clicking the restart btn on travis, not sure which permissions are needed for that. |
There's an open issue on Travis CI to allow commit authors to restart builds, however without any recent activity. Looks like you need to have repo write access (e.g. be a maintainer) in order to see the restart button on Travis CI build page. A common workaround is to close PR and re-open it again, but this adds noise to the PR activity. Maybe the ManageIQ bot could handle this via some |
@martinpovolny @ohadlevy shall we merge this one? |
@himdel: is there any remaining reason NOT to merge this yet? I see none, but I'd love to get your explicit ACK ;-) |
This pull request is not mergeable. Please rebase and repush. |
@martinpovolny No reason I'm aware of :), I'm not seeing any obvious breakage, the code looks like it is not intrusive enough to give use cause to hold merging this... everything's fine 👍 (The only reason I've not merged this myself is that I haven't had the time to go through the code and properly understand this. Feel free to do so if you do.) |
as it stands, this is better merged than not, 👍 to merge. |
@vojtechszocs : Gaprindashvili almost out of the door. Please, rebase, so that we can merge this. Thx! |
Vojtech is sick.
Can someone else help rebasing?
…On Dec 23, 2017 12:25, "Martin Povolny" ***@***.***> wrote:
@vojtechszocs <https://github.com/vojtechszocs> : Gaprindashvili almost
out of the door. Please, rebases, so that we can merge this. Thx!
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#2504 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AAyzAQ2CynpZDw3zsvPVrB4JP3o3LJzqks5tDNUtgaJpZM4QEsBN>
.
|
Sure. Done. Let's see what travis thinks about it. |
Checked commits vojtechszocs/manageiq-ui-classic@53e00cc~...c363266 with ruby 2.3.3, rubocop 0.47.1, haml-lint 0.20.0, and yamllint 1.10.0 |
Thanks!
On Dec 23, 2017 7:17 PM, "Martin Povolny" <[email protected]> wrote:
Merged #2504 <#2504>.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#2504 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AAyzAaYM8jy88i9-q9CWOg11bhZLmwxeks5tDTWIgaJpZM4QEsBN>
.
|
Add basic Redux infra based on ng-redux
This PR adds new namespace,
ManageIQ.redux
, that can be used by both Rails-managed (ES5) and webpack(er)-managed (ES6+) frontend code.Redux store implementation is based on ng-redux for easy integration with existing Angular 1.x code through the
$ngRedux.connect
API. Note that the$ngRedux
object exposes all of the standard Redux store APIs likedispatch
andsubscribe
, in addition to custom APIs likeconnect
. (Behind the scenes,ng-redux
uses standard Redux createStore and augments it with additional methods.)Proposed ManageIQ Redux API is minimal, here's the TypeScript interface:
The Redux infra is represented as a new "common" pack,
app/javascript/packs/miq-redux-common.ts
, which makes it available to frontend code across all web pages (e.g. Rails views).There are currently no Redux middlewares applied, but we should consider using redux-observable (or similar) for handling async operations and side effects from within all registered reducers.
There's also support for Redux DevTools browser extension for better inspection of UI state.
All Redux-specific TypeScript declarations are in
app/javascript/packs/custom-typings.ts
. To maketsc
accept known globals, I've added a separate (utility) pack,app/javascript/packs/custom-typings.ts
.Jasmine tests include:
ManageIQ.redux
namespace$ngRedux
object$ngRedux
objectrootReducer
,addReducer
etc.Things to consider as follow-ups:
initialState
persistence across page reloads