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

WIP: Add redux #1130

Merged
merged 26 commits into from
May 15, 2018
Merged

WIP: Add redux #1130

merged 26 commits into from
May 15, 2018

Conversation

crcommons
Copy link
Contributor

@crcommons crcommons commented May 4, 2018

This pull request makes the following changes:

  • Adds Redux, Routing, and fake components to test

Testing checklist:

  • Go to home page and confirm you see in the mode bar: "junk", "Foo: 3", and "Baz: 2"

  • Go to "settings/testroute/1, click the "Click Me" link. You should be taken to data view

  • I certify that I ran my checklist

Fixes ushahidi/platform#2907
Fixes ushahidi/platform#2826

Ping @ushahidi/platform

@rjmackay
Copy link
Contributor

rjmackay commented May 6, 2018

A few thoughts as I read this code, and various docs and issues

  1. We can probably inject a store into react components like this: Add Redux store to render.  coatue-oss/react2angular#58 (comment)
  2. However ngRedux defaults to creating the store itself, so we need to either
    a. Pull the store out of ngRedux to provide it to react. I think thats just $ngRedux itself.
    b. Create a store the usual react way and inject to angular. It looks like you can now do this: Feature Request: use an already created store. angular-redux/ng-redux#19

…tate

Sadly the syntax isn't a perfect match for connect:
`connectWithStore(MyComponent, mapStateToProps, mapDispatchToProps)`
not
`connect(mapStateToProps, mapDispatchToProps)(MyComponent)`
- Export RootReducer as default
- Import RootReducer rather than require
- Replace Form with forms in root reducer
- Add some junk default state
- Output junk default state in ush logo component
@rjmackay
Copy link
Contributor

rjmackay commented May 7, 2018

@crcommons I pushed a couple of commits they

  1. make redux store connect to the component using the method I found here Add Redux store to render.  coatue-oss/react2angular#58 (comment)
  2. fix some weirdness in the state shape caused by the way you were using require/export
    Basically the state looked like this...
{
  RootReducer : {
    Forms: {
      forms: []
    }
  }
}

I figured you probably didn't want 'RootReducer' at the top? and renamed Forms to forms

@@ -0,0 +1,18 @@
import React from 'react';
Copy link
Contributor

Choose a reason for hiding this comment

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

I wasn't sure where to put this, so I started a react-transition folder. Maybe it should just be in common/ or common/react-transition

return (props) => {
// Get the injector + store at render time
// Otherwise it happens before the angular app is set up
const injector = angular.element(document).injector();
Copy link
Contributor

Choose a reason for hiding this comment

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

This is pretty gross but it works :)


MyComponent.propTypes = {
foo: PropTypes.number.isRequired,
baz: PropTypes.number.isRequired
};

export default connectWithStore(MyComponent, mapStateToProps, mapDispatchToProps);
Copy link
Contributor

Choose a reason for hiding this comment

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

I couldn't figure out if it was possible to make this work with connect style syntax ie.
connect(mapStateToProps, mapDispatchToProps)(MyComponent)
so for now it has the component as the first prop instead.

}
}

export const getFormsFromState = state => state.forms.forms;
Copy link
Contributor

@rjmackay rjmackay May 7, 2018

Choose a reason for hiding this comment

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

Kind of a tangent: but I always find it weird that the mappers selectors for a particular reducer have to know what namespace this reducer is used under. ie. if you change the name of forms in rootReducer, this code breaks. I don't know if theres a standard solution for that at all, ie only passing the forms part of state to this function?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I've done some research on this and am really not sure. Adding it as an issue to refactor later.

@@ -17,5 +17,5 @@ <h1 class="mode-context-title"><a href="/" ng-bind="nav.site.name"></a></h1>
<!-- <saved-search-create></saved-search-create> -->
<mode-context-form-filter></mode-context-form-filter>
</div>
<my-component foo=3 baz=2></my-component>
<my-component store={store} foo=3 baz=2></my-component>
Copy link
Contributor

Choose a reason for hiding this comment

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

I missed this - but we shouldn't need to pass in store here. It might break things

@@ -38,6 +40,7 @@ function (
$scope.logout = Authentication.logout;
$scope.register = Registration.openRegister;
$scope.intercomAppId = $window.ushahidi.intercomAppId;
$scope.store = $ngRedux;
Copy link
Contributor

Choose a reason for hiding this comment

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

Need to remove this.

@ushbot ushbot temporarily deployed to rackspace_pr May 10, 2018 16:12 Inactive
@ushbot ushbot temporarily deployed to rackspace_pr May 10, 2018 16:12 Inactive
@ushbot ushbot temporarily deployed to rackspace_pr May 11, 2018 16:39 Inactive
@ushbot ushbot temporarily deployed to rackspace_pr May 11, 2018 16:39 Inactive
@ushbot ushbot temporarily deployed to rackspace_pr May 11, 2018 17:41 Inactive
@ushbot ushbot temporarily deployed to rackspace_pr May 11, 2018 18:13 Inactive
@ushahidi ushahidi deleted a comment from rjmackay May 11, 2018
.gitignore Outdated
@@ -23,3 +23,4 @@ server/www/img/icons/
server/www/
app/locales/
package-lock.json
app.stats.html
Copy link
Contributor

Choose a reason for hiding this comment

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

Shouldn't that be app/stats.html ?

app/app.js Outdated
require('ng-redux');
const thunk = require('redux-thunk');
import RootReducer from './rootReducer';
// import { combineReducers } from 'redux';
Copy link
Contributor

Choose a reason for hiding this comment

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

Clean up the comments?

app/app.js Outdated
@@ -18,6 +18,15 @@ require('angular-nvd3/src/angular-nvd3');
require('angular-cache');
require('angular-linkify');

require('redux');
require('ng-redux');
const thunk = require('redux-thunk');
Copy link
Contributor

Choose a reason for hiding this comment

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

We're not using thunk yet right?

app/app.js Outdated
@@ -18,6 +18,15 @@ require('angular-nvd3/src/angular-nvd3');
require('angular-cache');
require('angular-linkify');

require('redux');
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we need to require redux? or just ng-redux?

Copy link
Contributor

@rjmackay rjmackay left a comment

Choose a reason for hiding this comment

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

Some minor clean up requested in comments.
Just clean those up and this can land

…er because app.js just simply doesn't work with new linting.
@ushbot ushbot temporarily deployed to rackspace_pr May 15, 2018 18:54 Inactive
@crcommons crcommons merged commit 3a92e18 into experiment/react-angular May 15, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants