我注意到,如果我调度一个碰巧不修改状态的操作,无论如何都会重新渲染组件。
例子:
// for simplicity sake, we simply pass state on (no mutation)
const someReducer = (state, action) => state
const App = () => {
const [state, dispatch] = useReducer(someReducer, 0)
// in my use case, I want to dispatch an action if some specific condition in state occurs
if(state === 0) {
dispatch({ type: 'SOME ACTION' }) // type doesn't matter
}
// return some JSX
}
Run Code Online (Sandbox Code Playgroud)
我得到:
Error in app.js (16929:26)
Too many re-renders. React limits the …
Run Code Online (Sandbox Code Playgroud) 我必须部署一个第三方 Web 应用程序,前端服务器充当负载均衡器,并在其后面部署多个实际应用程序服务器的实例。出于与我无关的原因,我必须将唯一 id 作为环境变量传递给每个应用服务器实例。我的 docker-compose.yml 简化后如下:
version: '3'
services:
lb:
image: lb_image
app:
image: app_image
depends_on:
- lb
links:
- "server:lb"
environment:
- LB_HOST=server
Run Code Online (Sandbox Code Playgroud)
现在,我想运行:
docker-compose up -d --scale app=3
Run Code Online (Sandbox Code Playgroud)
但传递给每个实例不同的环境变量值。我听说过模板,有这样的东西会很好:
environment:
- CONTAINER_ID={{.Node.Id}}
Run Code Online (Sandbox Code Playgroud)
在我的 docker-compose.yml 中,是否有可能(到目前为止我听说过的每个解决方案都涉及编写外部脚本,在我看来,这完全放弃了使用 Compose 的好处)?
我最近花了一些时间来研究转换器(函数式编程中的工具,可以在不失去代码可读性/灵活性的情况下提高性能),当我开始测试它们的实际速度时,我得到了一些非常令人失望的结果。考虑:
const inc = x => x + 1;
const isEven = x => x % 2 === 0;
// simplest, shortest way I would be comfortable with if performance wasn't an issue
const mapFilter = xs => xs.filter(isEven).map(inc);
// transducers way
// function composition
const compose = (...fns) => x => fns.reduceRight((y, f) => f(y), x);
const map = f => step => (a, c) => step(a, f(c));
const filter = p => step => (a, c) => (p(c) …
Run Code Online (Sandbox Code Playgroud)