redux - NgRx(或 Redux)实际上在哪里存储数据?
问题描述
显然它在客户端内存中,但是是什么将它保存在引擎盖下?本地存储?网络存储?
解决方案
这只是一些 Javascript 变量。
这是 Redux 商店的一个小版本:
function createStore(reducer) {
var state;
var listeners = []
function getState() {
return state
}
function subscribe(listener) {
listeners.push(listener)
return function unsubscribe() {
var index = listeners.indexOf(listener)
listeners.splice(index, 1)
}
}
function dispatch(action) {
state = reducer(state, action)
listeners.forEach(listener => listener())
}
dispatch({})
return { dispatch, subscribe, getState }
}
所以,state
实际上只是一个变量,它指向你的 reducer 函数返回的任何内容。
推荐阅读
- django - 如何更改视图中表单的底层模型?
- javascript - 如何突出显示文本中包含 5 个或更多字母的所有单词
- python - 整个列的循环中 str 的时间戳
- html - HTML表格第一列比第二列大很多
- python - 循环内有超时的for循环?
- c# - 如何在 C# 中基于匹配 XmlNode 从层次结构中克隆单个 XML
- python - 写入 CSV 时操作 Pandas 输出
- macos - NFS挂载不断改变inode
- python - 如何从 docx 文件中的表中提取数据并将其转换为数据框 ARABIC DATA
- video-encoding - 无损 8 位灰度编解码器