用增强器扩展 Redux 的 createStore 的模式是什么?

What is the pattern of extending createStore of Redux with enhancers?

在写一篇关于将 Redux 状态与组件解耦的博客 post 时,我注意到 enhancercreateStore link:

中的用法
export default function createStore(reducer, preloadedState, enhancer) {
  /* .... */
  if (typeof enhancer !== 'undefined') {
    if (typeof enhancer !== 'function') {
      throw new Error('Expected the enhancer to be a function.')
    }

    return enhancer(createStore)(reducer, preloadedState)
  }
  /* ... */
  return store;
}

因此,通用模式是:

function func(arg1, /* ... */, argN, enhancer) {
  /* .... */
  if (typeof enhancer === 'function') {    
    return enhancer(func)(arg1, /* ... */, argN);
  }
  /* ... */
  return result;
}

我对此很兴奋。现在我想知道您将如何对其进行分类/命名,以及它是一段特别优秀的代码还是某种系统方法的结果,这些方法是我想学习并开始应用的更大事物的一部分。

我想你会称之为 Decorator