Comprehending import statements and someone's else old react code
up vote
2
down vote
favorite
I was trying to comprehend Dimitar Valchanov React code for the game 2048 via his github repo.
He have also written a blog about it but he wants a person to go through the code himself and have rather explained the structure of the code in this blog. (*Although he have included the comments in the code to make it more understandable).
The major problem I am facing while to trying to understand his code is 1st my lack of experience and 2nd His code is old now
While reviewing his code, I found few things which I was unable to comprehend.
[Question:1] In his import statements in this file, He have used something like this
import {Board, Result} from "js/components";
import * as Actions from "js/actions/actions";
How is he able to right js
and go back to the src
and then walk through the given repo.
If I would've been, I would have written something like this
import Board from "../components";
import Result from "../components";
Question: What does 'js' mean over here and how is he able to export two different file using single statement i.e import {Board, Result} from "js/components";
[Question:2] In the same file he have written something like this
this.actions = bindActionCreators(Actions, this.props.dispatch);
Which I thought to be dispatching all redux action together but I seem to be wrong and hence I am unable to comprehend what is inside my this.actions
And hence this line also doesn't make sense
getChildContext() {
return {
actions: this.actions
};
}
Question: Can Someone please explain me what's happening above?
javascript reactjs redux
add a comment |
up vote
2
down vote
favorite
I was trying to comprehend Dimitar Valchanov React code for the game 2048 via his github repo.
He have also written a blog about it but he wants a person to go through the code himself and have rather explained the structure of the code in this blog. (*Although he have included the comments in the code to make it more understandable).
The major problem I am facing while to trying to understand his code is 1st my lack of experience and 2nd His code is old now
While reviewing his code, I found few things which I was unable to comprehend.
[Question:1] In his import statements in this file, He have used something like this
import {Board, Result} from "js/components";
import * as Actions from "js/actions/actions";
How is he able to right js
and go back to the src
and then walk through the given repo.
If I would've been, I would have written something like this
import Board from "../components";
import Result from "../components";
Question: What does 'js' mean over here and how is he able to export two different file using single statement i.e import {Board, Result} from "js/components";
[Question:2] In the same file he have written something like this
this.actions = bindActionCreators(Actions, this.props.dispatch);
Which I thought to be dispatching all redux action together but I seem to be wrong and hence I am unable to comprehend what is inside my this.actions
And hence this line also doesn't make sense
getChildContext() {
return {
actions: this.actions
};
}
Question: Can Someone please explain me what's happening above?
javascript reactjs redux
1
Good place to start for #1 stackoverflow.com/a/36796281/1175966 . The"js/"
is just a directory path
– charlietfl
Nov 19 at 23:43
@charlietfl There is no directory with namejs
I went through that article but still couldn't figure out how did he used the wordjs
here
– KuchBhi
Nov 20 at 7:43
add a comment |
up vote
2
down vote
favorite
up vote
2
down vote
favorite
I was trying to comprehend Dimitar Valchanov React code for the game 2048 via his github repo.
He have also written a blog about it but he wants a person to go through the code himself and have rather explained the structure of the code in this blog. (*Although he have included the comments in the code to make it more understandable).
The major problem I am facing while to trying to understand his code is 1st my lack of experience and 2nd His code is old now
While reviewing his code, I found few things which I was unable to comprehend.
[Question:1] In his import statements in this file, He have used something like this
import {Board, Result} from "js/components";
import * as Actions from "js/actions/actions";
How is he able to right js
and go back to the src
and then walk through the given repo.
If I would've been, I would have written something like this
import Board from "../components";
import Result from "../components";
Question: What does 'js' mean over here and how is he able to export two different file using single statement i.e import {Board, Result} from "js/components";
[Question:2] In the same file he have written something like this
this.actions = bindActionCreators(Actions, this.props.dispatch);
Which I thought to be dispatching all redux action together but I seem to be wrong and hence I am unable to comprehend what is inside my this.actions
And hence this line also doesn't make sense
getChildContext() {
return {
actions: this.actions
};
}
Question: Can Someone please explain me what's happening above?
javascript reactjs redux
I was trying to comprehend Dimitar Valchanov React code for the game 2048 via his github repo.
He have also written a blog about it but he wants a person to go through the code himself and have rather explained the structure of the code in this blog. (*Although he have included the comments in the code to make it more understandable).
The major problem I am facing while to trying to understand his code is 1st my lack of experience and 2nd His code is old now
While reviewing his code, I found few things which I was unable to comprehend.
[Question:1] In his import statements in this file, He have used something like this
import {Board, Result} from "js/components";
import * as Actions from "js/actions/actions";
How is he able to right js
and go back to the src
and then walk through the given repo.
If I would've been, I would have written something like this
import Board from "../components";
import Result from "../components";
Question: What does 'js' mean over here and how is he able to export two different file using single statement i.e import {Board, Result} from "js/components";
[Question:2] In the same file he have written something like this
this.actions = bindActionCreators(Actions, this.props.dispatch);
Which I thought to be dispatching all redux action together but I seem to be wrong and hence I am unable to comprehend what is inside my this.actions
And hence this line also doesn't make sense
getChildContext() {
return {
actions: this.actions
};
}
Question: Can Someone please explain me what's happening above?
javascript reactjs redux
javascript reactjs redux
asked Nov 19 at 23:33
KuchBhi
707220
707220
1
Good place to start for #1 stackoverflow.com/a/36796281/1175966 . The"js/"
is just a directory path
– charlietfl
Nov 19 at 23:43
@charlietfl There is no directory with namejs
I went through that article but still couldn't figure out how did he used the wordjs
here
– KuchBhi
Nov 20 at 7:43
add a comment |
1
Good place to start for #1 stackoverflow.com/a/36796281/1175966 . The"js/"
is just a directory path
– charlietfl
Nov 19 at 23:43
@charlietfl There is no directory with namejs
I went through that article but still couldn't figure out how did he used the wordjs
here
– KuchBhi
Nov 20 at 7:43
1
1
Good place to start for #1 stackoverflow.com/a/36796281/1175966 . The
"js/"
is just a directory path– charlietfl
Nov 19 at 23:43
Good place to start for #1 stackoverflow.com/a/36796281/1175966 . The
"js/"
is just a directory path– charlietfl
Nov 19 at 23:43
@charlietfl There is no directory with name
js
I went through that article but still couldn't figure out how did he used the word js
here– KuchBhi
Nov 20 at 7:43
@charlietfl There is no directory with name
js
I went through that article but still couldn't figure out how did he used the word js
here– KuchBhi
Nov 20 at 7:43
add a comment |
1 Answer
1
active
oldest
votes
up vote
0
down vote
Question #1:
The import statement is not old syntax or deprecated. Its simply another way of importing code from an ES6 module.
import {Board, Result} from "js/components";
and
import Board from "../components/Board";
import Result from "../components/Result";
are both perfectly valid ways of importing code. Its up to you how you want to do it.
Here is a link that explains Named Exports vs Default Exports.
The js/components
is just a directory path that points to his file here
Question #2:
Whats inside this.actions
is many functions wrapped in dispatch(...) ready to be dispatched to Redux to perform actions on the store upon being called.
In the following method
getChildContext() {
return {
actions: this.actions
};
}
it just returns this.actions, basically.
This code is not old and still used on the Redux site when explaining the bindActionCreators method.
Thanks for answering There is no directory with namejs
I went through that article but still couldn't figure out how did he used the wordjs
here
– KuchBhi
Nov 20 at 7:43
I'm not sure either, but if you were wanting to replicate this program and it gives you an error that it cant find "js/components" then you can just replace it with "../../components"
– Shawn Andrews
Nov 20 at 18:23
add a comment |
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
0
down vote
Question #1:
The import statement is not old syntax or deprecated. Its simply another way of importing code from an ES6 module.
import {Board, Result} from "js/components";
and
import Board from "../components/Board";
import Result from "../components/Result";
are both perfectly valid ways of importing code. Its up to you how you want to do it.
Here is a link that explains Named Exports vs Default Exports.
The js/components
is just a directory path that points to his file here
Question #2:
Whats inside this.actions
is many functions wrapped in dispatch(...) ready to be dispatched to Redux to perform actions on the store upon being called.
In the following method
getChildContext() {
return {
actions: this.actions
};
}
it just returns this.actions, basically.
This code is not old and still used on the Redux site when explaining the bindActionCreators method.
Thanks for answering There is no directory with namejs
I went through that article but still couldn't figure out how did he used the wordjs
here
– KuchBhi
Nov 20 at 7:43
I'm not sure either, but if you were wanting to replicate this program and it gives you an error that it cant find "js/components" then you can just replace it with "../../components"
– Shawn Andrews
Nov 20 at 18:23
add a comment |
up vote
0
down vote
Question #1:
The import statement is not old syntax or deprecated. Its simply another way of importing code from an ES6 module.
import {Board, Result} from "js/components";
and
import Board from "../components/Board";
import Result from "../components/Result";
are both perfectly valid ways of importing code. Its up to you how you want to do it.
Here is a link that explains Named Exports vs Default Exports.
The js/components
is just a directory path that points to his file here
Question #2:
Whats inside this.actions
is many functions wrapped in dispatch(...) ready to be dispatched to Redux to perform actions on the store upon being called.
In the following method
getChildContext() {
return {
actions: this.actions
};
}
it just returns this.actions, basically.
This code is not old and still used on the Redux site when explaining the bindActionCreators method.
Thanks for answering There is no directory with namejs
I went through that article but still couldn't figure out how did he used the wordjs
here
– KuchBhi
Nov 20 at 7:43
I'm not sure either, but if you were wanting to replicate this program and it gives you an error that it cant find "js/components" then you can just replace it with "../../components"
– Shawn Andrews
Nov 20 at 18:23
add a comment |
up vote
0
down vote
up vote
0
down vote
Question #1:
The import statement is not old syntax or deprecated. Its simply another way of importing code from an ES6 module.
import {Board, Result} from "js/components";
and
import Board from "../components/Board";
import Result from "../components/Result";
are both perfectly valid ways of importing code. Its up to you how you want to do it.
Here is a link that explains Named Exports vs Default Exports.
The js/components
is just a directory path that points to his file here
Question #2:
Whats inside this.actions
is many functions wrapped in dispatch(...) ready to be dispatched to Redux to perform actions on the store upon being called.
In the following method
getChildContext() {
return {
actions: this.actions
};
}
it just returns this.actions, basically.
This code is not old and still used on the Redux site when explaining the bindActionCreators method.
Question #1:
The import statement is not old syntax or deprecated. Its simply another way of importing code from an ES6 module.
import {Board, Result} from "js/components";
and
import Board from "../components/Board";
import Result from "../components/Result";
are both perfectly valid ways of importing code. Its up to you how you want to do it.
Here is a link that explains Named Exports vs Default Exports.
The js/components
is just a directory path that points to his file here
Question #2:
Whats inside this.actions
is many functions wrapped in dispatch(...) ready to be dispatched to Redux to perform actions on the store upon being called.
In the following method
getChildContext() {
return {
actions: this.actions
};
}
it just returns this.actions, basically.
This code is not old and still used on the Redux site when explaining the bindActionCreators method.
answered Nov 20 at 0:18
Shawn Andrews
930416
930416
Thanks for answering There is no directory with namejs
I went through that article but still couldn't figure out how did he used the wordjs
here
– KuchBhi
Nov 20 at 7:43
I'm not sure either, but if you were wanting to replicate this program and it gives you an error that it cant find "js/components" then you can just replace it with "../../components"
– Shawn Andrews
Nov 20 at 18:23
add a comment |
Thanks for answering There is no directory with namejs
I went through that article but still couldn't figure out how did he used the wordjs
here
– KuchBhi
Nov 20 at 7:43
I'm not sure either, but if you were wanting to replicate this program and it gives you an error that it cant find "js/components" then you can just replace it with "../../components"
– Shawn Andrews
Nov 20 at 18:23
Thanks for answering There is no directory with name
js
I went through that article but still couldn't figure out how did he used the word js
here– KuchBhi
Nov 20 at 7:43
Thanks for answering There is no directory with name
js
I went through that article but still couldn't figure out how did he used the word js
here– KuchBhi
Nov 20 at 7:43
I'm not sure either, but if you were wanting to replicate this program and it gives you an error that it cant find "js/components" then you can just replace it with "../../components"
– Shawn Andrews
Nov 20 at 18:23
I'm not sure either, but if you were wanting to replicate this program and it gives you an error that it cant find "js/components" then you can just replace it with "../../components"
– Shawn Andrews
Nov 20 at 18:23
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53384164%2fcomprehending-import-statements-and-someones-else-old-react-code%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
1
Good place to start for #1 stackoverflow.com/a/36796281/1175966 . The
"js/"
is just a directory path– charlietfl
Nov 19 at 23:43
@charlietfl There is no directory with name
js
I went through that article but still couldn't figure out how did he used the wordjs
here– KuchBhi
Nov 20 at 7:43