reactjs - 在 Aurelia 框架内的 React 中使用 redux
问题描述
我正在为我的客户端应用程序使用 Aurelia 框架。但是,出于某种特殊原因,我在某些屏幕上使用了 react。在客户端应用程序中实现 redux,我发现它非常复杂,因为 redux 已经用于 react 部分。有人知道如何将同一家商店与 react 和 aurelia 一起使用吗?提前致谢。
解决方案
好吧,没有什么能阻止您在 Aurelia 中使用同一家商店。这是我的一篇关于在 Aurelia 中使用 Redux 的博客文章,其中包含如下示例:
import marked from 'marked';
import { bindable } from 'aurelia-framework';
import { createStore } from 'redux';
export class MarkdownRedux {
@bindable raw;
html = '';
store = createStore(textUpdater);
正如您在上面的行中看到的那样,此时它实际上创建了一个新商店。因此,您应该只从 React 获取对先前创建和导出的存储的引用,而不是那样做。
constructor() {
this.store.subscribe(this.update.bind(this));
}
update() {
const state = this.store.getState();
this.html = state.html;
this.raw = state.raw;
}
keyupHandler(newValue) {
this.store.dispatch(updateText(newValue));
}
attached() {
this.keyupHandler(this.raw);
}
}
在此之下,所有状态的调度和获取都与往常一样。
推荐阅读
- python - 如何在多个 relplot 图表上叠加 pyplot 视觉元素
- jenkins - 如何在管道中使用多分支管道文件夹属性?
- python - 计算熊猫时间窗口中列值重复的次数
- snakemake - 如何定位包含通配符的中间 Snakemake 规则
- xamarin.ios - FFImageLoading 在发布模式 Xamarin.iOS 中不显示 webp 图像
- git - 我的头和主人是分开的(git)。我怎样才能重新加入他们?
- python - 为什么这个组合函数会输出一定长度的集合?
- node.js - 当颜色存储为十六进制或 RGB 值时如何搜索颜色?
- jenkins - Jenkins Pipeline:如何用变量替换部分 sh 命令 arg
- java - Apache POI 从不存在的文件中读取