Reputation: 5157
I am (totally) newbie in JavaScript (or to be exact, in ES6), and using this article to guide me. What I want to ask is the second line. What does type
means in that import statement? Is type
a keyword in JavaScript? Because if understand it correctly, I know that the line: import type { fromJS } from 'immutable'
, is meant to import fromJS
function from package immutable
(I come from Python background).
I also see that in the line action: {type: string, payload: any }) => {
, there is a type
parameter. But I guess that is just coincidence, right?
import Immutable from 'immutable'
import type { fromJS } from 'immutable'
import { SAY_HELLO } from '../action/hello'
const initialState = Immutable.fromJS({
message: 'Initial message',
})
const helloReducer = (state: fromJS = initialState, action: {type: string, payload: any }) => {
switch(action.type) {
case SAY_HELLO:
return state.set('message', action.payload)
default:
return state
}
}
export default helloReducer
dd
Upvotes: 0
Views: 46
Reputation: 32174
the article you refer to is using the flow type library you can read more about it here: https://flow.org/
Upvotes: 1