-
Notifications
You must be signed in to change notification settings - Fork 135
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 React and an example component #790
Conversation
Exciting! Is this something to consider or use in the new client PRs already? Is the idea of using React (instead|on top) of AngularJS mature? |
Kinda as this PR well proves; that said, there are still unknowns regarding routing and data fetching — especially the latter one will be important to figure out sooner than later but we might be able to work our way around it for a while by using Angular app as an app-shell and limiting react only to components inside the app, basically having tons of render-trees all over the place.
Definitely. It would be good to get some "framework" for doing this in place first with tiny changes like this. References list could be an interesting experiment to try with React indeed, but only if it doesn't significantly slow us down shipping references. |
I added a import helper so all react components are automatically imported, from the comment in main.js:
|
c0b8bba
to
0987046
Compare
Good idea, although the more explicit imports we can have (even at module level) and less magic around, the clearer dependencies are going to be and easier everything is to grok. This time convention over configuration (that the How do you see the path forward later on when we might have components that are very module (or "section") specific, as opposed to being more generic and re-usable? At what point we could have completely explicit imports and remove |
In the future :) I guess the magic component imports are for using them within angular templates, any other use should be explicit import (and will have to be anyway). Doesn't seem much benefit to rewrite all the global style angular files into nice es6 modules with imports just to ditch them later. Could find a way to rewrite into es6 modules + react at the route level in future perhaps, so one route goes to one react component. A few other patterns to work out though around data fetching, state, etc... |
Tests weren't working before when using react2angular, but ngreact works fine too (and has more github stars) and was easy to swap in. I would suggest this is ready, except the example component I created is not complete, or very useful. but also probably not a good idea to merge it without any react components in use, so perhaps either:
Both cases would involve removing the one I created for this proof of concept. |
Also, https://medium.com/@jrwebdev/migrating-an-angular-1-application-to-react-8891ec73d462 has some thoughts, I only skim read it. I would also suggest to keep react components simple and not try and get too much interaction between react and angular as I think it could quickly get messy, so when in react land I would try and avoid two way bindings, much/any interaction with the angular controller, using angular services, etc... So probably don't try and pass whole controller objects through to a react component, but just the information that it needs. |
... ok, well I tried out the second option actually, and implement the volunteering page in react, which involved:
I also added fancy es2018 object spread plugin. It's quite easy to start dropping browser support with some of these things if we don't get the babel options right (e.g. |
@nicksellen How shall we talk with api? Within angular, or react? Do you have any guidelines to share? I'm interesting in both reading and writing data. I'm very new to react, done the tutorial and bits of docs only. Also read a nice article about data fetching, which seems to assume full react application. What is the long-term future picture of frontend? Everything i.e. react + redux? @nicksellen @simison |
Personally, I would keep it simple/incremental. Try with just fetch (+ polyfill), and if that doesn't have enough features then axios. Basically like that second link. Although I would suggest to add one additional layer - an API service that abstracts any of the details about using fetch/axios. So inside a component you can use it something like: // login
await api.auth.login({ username, password })
// fetch contacts
const contacts = await api.contacts.list() That kind of thing... At some point it might make sense to use redux, but probably not worth it until it seems useful. The API service will still be used then, as will the components. If the presentation is getting too mixed up with logic you can always write two components:
|
I'd like to create a link (like @nicksellen @simison Do you have any experience with wiring up routing between react and angular-ui-router? Or ideas? I'm thinking about using |
Yeah, depending on where these are it should be safe and best we can have when living with two frameworks. |
rebased with master |
@mrkvon you can access all the angular services from outside angular, e.g.: var $state = angular.element(document).injector().get('$state');
// Go to messages page ("inbox" state)
$state.go('inbox')
// Get URL for messages page
$state.href('inbox')
// ... or one with params
$state.href('profile', { username: 'peter' }) And there is an example where I use an angular scope outside of angular in If you do anything more fancy outside of angular you might need to consider the digest scope to ensure things update in the angular world, but I think it should be ok for these uses. |
This was recently removed when AddThis script was removed with invite-page.
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.
@mrkvon feel free to merge once the about component is either part of the about -angular template or removed for now, since it doesn't implement most of the things for that section.
to be part of the angularjs component, not to replace it
|
Is this something you took care of, or is it yet to be done? |
Proposed Changes
Testing Instructions
It's just a proof of concept to see how it integrates. That particular component has a load of other stuff too, and maybe not worth switching it over, but yeah, just gives an example. Seems quite nice!