Answer the question
In order to leave comments, you need to log in
Where can I get gradlew?
I looked at the Gradle website, but did not understand where to get the Gradle Wrapper from.
Tell a noob.
Answer the question
In order to leave comments, you need to log in
In IDEA/Android Studio projects this wrapper is created automatically.
But you can create it manually by calling gradle wrapper
If I understood your colleague correctly, then it was not about the need to call asynchronous functions through setTimeout, but it was just an example of how to make some piece of "type asynchronous".
His argument was that instead of calling dispatch from a closure (obtained with redux-thunk, for example), he called store.dispatch directly (that is, on the store object, and that store would be imported in each file).
In this case, redux-thunk has one distinct advantage - you don't have to import store in every file.
Otherwise, everything is very clearly written in the answer of Dan Abramov, who brought holymotion .
In short, you need a dispatch function, because it is through it that you "dispatch" your actions. You cannot write in an asynchronous response:
...
axios.get('/user')
.then(res => {
// успешно получили данные
dispatch({ // <-- здесь вы вызываете функцию dispatch, а если она к вам не пришла в анонимной функции, с помощью redux-thunk, то октуда вы ее возьмете?
type: GET_PROFILE_SECCUESS
payload: res.data
})
})
...
I would argue that redux-thunk, redux-saga, or some other "solution" for organizing side effects is not a necessary dependency for any application written in reactjs.
Just like redux itself is not necessary. But if your application needs a state tool (redux), it automatically follows that it also needs a side effects tool.
In redux-thunk, you dispatch a function as if it were an action. It is very important. In the container, regardless of the "nature" of the action, you will write this.props.dispatch(whateverAction).
And your colleague, on the contrary, will be forced to dispatch synchronous actions through this.props.dispatch(syncAction), and asynchronous ones simply by calling the function containing setTimeout.
Somehow it’s not very beautiful, and the container itself does not need to know which actions are synchronous and which are asynchronous.
I also suffer from this issue. Personally, on the contrary, I don’t like that logic is taken out in action creators. Sagas seem to fit better.
Indeed, most likely it is about the organization of the code.
If we are making our react application, it is possible that one day we will have to change the store. It's generally bad form to use dispatch on the component itself without wrapping it in a HOC. After all, this immediately makes it impossible to reuse. For example, we have a component that renders some kind of list and uses redux. In order for us to reuse it correctly, do this:
import React, { Component } import 'react';
import List from './List'; // Список
import { connect } from 'react-redux'
import { mutatinList } from './actions'; // Какой-то action
class ListContainer extends Component{
render(){
return(
<List {...this.props} />
)
}
}
const mapStateToProps = (state) => ({
list: state.list
})
const mapDispatchToProps = {
mutatinList: mutatinList
}
export default connect(mapStateToProps, mapDispatchToProps)(ListContainer);
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question