简体   繁体   中英

named variable filter syntax in redux

I have just finished learning javascript and typescript (I know redux is not typescript), but have been thouroughly confused by the syntax for redux filters:

function visibilityFilter(state = 'SHOW_ALL', action) {
   ...
}

I've seem default variables in javascript, but only when the default variable is AFTER the positional variable. What is going on here? Can someone point me to documentation that explains this syntax?

Basically it means that the reducer expects to receive an action, but uses the default value if the first parameter is undefined .

 function reducer(state = 'initial', action) { if (action.type === 'change') { return 'new'; } return state; } console.log( 'uses given initial state: ', reducer('what', {}) ); console.log( 'null is also considered a given state: ', reducer(null, {}) ); console.log( 'uses default state if first param is undefined: ', reducer(undefined, {}) ); const myServerState = undefined; console.log( 'passing undefined might not be so obvious: ', reducer(myServerState, {}) ); // throws error because action is undefined console.log(reducer({ type: 'change' })); 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM