Why does this piece of code repeat itself?

The following code snippet was found on

http://www.jchapron.com/2015/08/14/getting-started-with-redux/

import React from 'react';  
import { createStore as initialCreateStore, compose } from 'redux';

export let createStore = initialCreateStore;

if (__DEV__) {  
  createStore = compose(
    require('redux-devtools').devTools(),
    require('redux-devtools').persistState(
      window.location.href.match(/[?&]debug_session=([^&]+)\b/)
    ),
    createStore
  );

Why does the author import initialCreateStore as createStore and then reassign that same result to createStore

Wont just importing createStore from the beginning do the same thing ?

Answers


Why does the author import initialCreateStore as createStore?

He doesn't, it's the other way round. The import is creating an initialCreateStore binding in the module scope.

Why does he then reassign that same result to createStore?

Because of verbosity. He wants to be explicit that it's only the initial value of the exported binding.

Wont just importing createStore from the beginning do the same thing?

No, because in ES6 imported bindings are "immutable" - they can change (if they change in the module that exported them), but they cannot be assigned to in the importing module. The author does however want to overwrite the createStore with his own in case __DEV__ is present, so he does need to declare his own binding with export let createStore.


Need Your Help

Schema for tracking SQL Server table updates

sql-server database-schema

I have a set of 16 SQL Server tables, which get updated constantly from a Web UI. I need to track every change happening to these tables and call a separate system every 10 minutes sending each ins...