现在我理解商店的概念作为React应用程序的真实来源,但似乎有时使用商店是过度的,特别是在仅限UI的情况下.
例如,假设我正在制作一个包含电影列表的应用.该应用程序包含一个搜索栏,可让您根据标题过滤这些电影.该搜索栏的值(让我们称之为searchTerm)是否应该包含在商店中?它唯一的影响是显示的电影列表,这纯粹是一个UI功能.它不会被发送到服务器或保存到本地存储.所以在我的handleTextChange函数中,我应该提醒商店,还是只设置组件的状态:
应该这样(使用商店):
var Actions = Reflux.createActions([
"searchChanged"
]);
var Store = Reflux.createStore({
listenables: [Actions],
getInitialState: function () {
return data;
},
onSearchChanged: function (searchTerm) {
this.trigger(data.filter(function (el) {
return el.name.toLowerCase().indexOf(searchTerm.toLowerCase()) != -1;
}));
}
});
var View = React.createClass({
mixins: [Reflux.connect(Store, "movies")],
handleTextChange: function (e) {
Actions.searchChanged(e.target.value);
},
render: function(){
//Render here. Somewhere there is this input element:
<input onChange={this.handleTextChange} type="text"/>
}
)};
Run Code Online (Sandbox Code Playgroud)
或者这个(不使用商店):
var Store = Reflux.createStore({
getInitialState: function () {
return data;
}, …Run Code Online (Sandbox Code Playgroud) 我有以下React.js应用程序结构:
<App />
<BreadcrumbList>
<BreadcrumbItem />
<BreadcrumbList/>
<App />
Run Code Online (Sandbox Code Playgroud)
问题是,当我点击时<BreadcrumbItem />,我想改变状态<App />
我使用回调来传递道具,<BreadcrumbList/>但这就是我得到了多远.有没有pattaren如何轻松地将道具传递给竞争树?
如何在<App />不进行任何回调链接的情况下将道具传递给它?
我正在使用flux-router和flux体系结构(facebook的flux实现).
目前在我的系统中,我的路线上写着"chat /:topic".
当用户进入此组件时,我正在创建订阅(使用componentWillMount上的操作创建)到websocket服务器,我正在删除componentWillUnmount上的订阅.
当用户移动到另一条路线时,整个工作流程都可以正常工作 - 因为react-router正在卸载我的组件.
当我在我的路线内转换(从"聊天/游戏"到"聊天/电视")时,组件未安装,我需要清除组件的状态.
我读到了我可以采取的不同行动以及过渡到发送行动"转移"并且每个相关商店将清除它的商店.
在我看来,这种行为 - 是错误的,它将我的商店和我的路由器结合在一起.
你会如何解决这个问题?这是一个我应该提出反应路由器并要求他们在我的路线内卸载的问题吗?
我如何将参数传递给启用通量的控制器,以便控制器操作识别它?
我使用构建器创建了一个扩展,并将以下方法添加到 ContentController。
/**
* @param string $var
*/
public function exampleAction($var = null) {
var_dump($var);
die;
}
Run Code Online (Sandbox Code Playgroud)
但无论我如何将参数添加到 URL,结果都只是“null”。
扩展目录是“test” $_EXTKEY,. 构建器将“Mac.Test”放入其中ext_tables.php以调用registerProviderExtensionKey()。所以在 URL 中我尝试了这些参数:
http://host/index.php?id=1&tx_test_content[var]=abc
http://host/index.php?id=1&tx_test[var]=abc
http://host/index.php?id=1&tx_mactest_content[var]=abc
http://host/index.php?id=1&tx_mactest[var]=abc
http://host/index.php?id=1&var=abc
Run Code Online (Sandbox Code Playgroud)
和其他一些。但无济于事。
我尝试使用f:link.actionViewHelper,结果是
http://localhost/test2/index.php?id=1&no_cache=1&tx_test_content[member]=foo&tx_test_content[action]=example&tx_test_content[controller]=Content
另外 $this->request->getArguments() 只返回一个空数组,因此肯定存在严重错误。
使用的版本:
PHP 5.6.11
TYPO3 6.2.21
vhs 2.4.0
Flux 7.2.3
Fluidpages 3.3.1
FluidContent 4.3.3
FluidContent_Core 1.3.0
builder 1.0.0
没有安装其他任何东西(新系统只是为了测试此行为)。
这是我第一次尝试使用反应.我遇到了下面显示的以下错误.Uncaught ReferenceError: FluxDispatcher is not defined.我相信我已经要求所有正确的宝石和javascript文件但是,我无法弄清楚为什么没有定义FluxDispatcher.下面我列出了一些文件,如果我需要提供更多信息,请告诉我.
的Gemfile
source 'https://rubygems.org'
gem 'rails', '4.2.2'
gem 'sqlite3'
gem 'sass-rails', '~> 5.0'
gem 'uglifier', '>= 1.3.0'
gem 'jquery-rails'
gem 'jbuilder', '~> 2.0'
gem 'awesome_print', '~> 1.7'
gem 'bootstrap', '~> 4.0.0.alpha5'
gem 'ancestry'
gem 'rails_admin'
gem 'react-rails'
gem 'flux-rails-assets'
gem 'lodash-rails'
source 'https://rails-assets.org' do
gem 'rails-assets-tether', '>= 1.1.0'
end
group :development, :test do
gem 'byebug'
gem 'web-console', '~> 2.0'
gem 'spring'
end
Run Code Online (Sandbox Code Playgroud)
appliction.js
//= require jquery
//= require jquery_ujs
//= require tether
//= …Run Code Online (Sandbox Code Playgroud) 在实现像Redux或MobX这样的状态容器时,通常会将状态和事件移动到不再能读取引用的单独类或对象.
例如,在正常组件中:
import Alert from Alert.js;
class Dummy extends React.Component {
constructor(props) {
super(props);
this.state = { clicked: false }
}
handleClick() {
fetch('api').then(function(){
this.setState({ clicked: true });
this._alert.show('Cool response!');
});
}
render() {
return (
<div>
<Alert ref={a => this._alert = a} />
<Button onClick={this.handleClick}/>
</div>
)
}
}
Run Code Online (Sandbox Code Playgroud)
如果单击该按钮,则在完成服务器请求后,将更新状态并触发警报.在某些模态和警报库中使用这样的引用是很常见的.
现在,在Redux(或任何Flux实现)中,fetch()将存在于一个动作中,该动作位于一个单独的文件中,该文件无权访问this._alert.
在不重写外部"警报"库的情况下维护功能的最佳方法是什么?
我在玩 Spring reactor,我看不出concat和mergeoperator之间有什么区别
这是我的例子
@Test
public void merge() {
Flux<String> flux1 = Flux.just("hello").doOnNext(value -> {
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
e.printStackTrace();
}
});
Flux<String> flux2 = Flux.just("reactive").doOnNext(value -> {
try {
Thread.sleep(2000);
} catch (InterruptedException e) {
e.printStackTrace();
}
});
Flux<String> flux3 = Flux.just("world");
Flux.merge(flux1, flux2, flux3)
.map(String::toUpperCase)
.subscribe(System.out::println);
}
@Test
public void concat() {
Flux<String> flux1 = Flux.just("hello").doOnNext(value -> {
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
e.printStackTrace();
}
});
Flux<String> …Run Code Online (Sandbox Code Playgroud) 我正在尝试找出无限流和无限磁通量(如果有)之间的概念差异。
为此,我想出了以下示例来说明无限的流/通量
@Test
public void infinteStream() {
//Prints infinite number of integers
Stream<Integer> infiniteStream = Stream.iterate(0, i -> i+1);
infiniteStream.forEach(System.out::println);
}
@Test
public void infiniteFlux() {
//Prints infinite number of date strings (every second)
Flux<LocalDateTime> localDateTimeFlux = Flux.interval(Duration.ofSeconds(1))
.map(t -> LocalDateTime.now());
localDateTimeFlux.subscribe(t -> System.out.println(t.format(DateTimeFormatter.ofPattern("yyyy-MM-dd hh:mm:ss"))));
}
Run Code Online (Sandbox Code Playgroud)
关于这些示例,我有一个问题:是否有带Flux的infinteStream()和带Stream的infinteFlux()的模拟?而且,更一般而言,无限流和磁通量之间有什么区别吗?
在此先感谢Felix
我有一个 s 原语Flux,String并在main()方法中运行此代码。
package com.example;
import reactor.core.publisher.Flux;
import reactor.core.scheduler.Schedulers;
import reactor.util.Logger;
import reactor.util.Loggers;
import java.util.Arrays;
import java.util.List;
public class Parallel {
private static final Logger log = Loggers.getLogger(Parallel.class.getName());
private static List<String> COLORS = Arrays.asList("red", "white", "blue");
public static void main(String[] args) throws InterruptedException {
Flux<String> flux = Flux.fromIterable(COLORS);
flux
.log()
.map(String::toUpperCase)
.subscribeOn(Schedulers.newParallel("sub"))
.publishOn(Schedulers.newParallel("pub", 1))
.subscribe(value -> {
log.info("==============Consumed: " + value);
});
}
}
Run Code Online (Sandbox Code Playgroud)
如果您尝试运行此代码,应用程序永远不会停止运行,您需要手动停止它。如果我替换.newParallel()为.parallel()一切正常,并且应用程序正常完成。
为什么它无法自行完成运行?为什么会挂?这种行为的原因是什么?
如果您将此代码作为 JUnit 测试运行,它可以正常工作并且不会挂起。
flux ×10
reactjs ×6
java ×3
javascript ×3
reactor ×2
java-stream ×1
react-router ×1
reactjs-flux ×1
redux ×1
refluxjs ×1
scheduler ×1
spring ×1
typo3 ×1
typo3-6.2.x ×1