React Native + Flux,无响应调度程序
React Native + Flux, unresponsive dispatcher
我正在构建我的第一个原生响应应用程序。我习惯使用Flux MVC模式构建React应用程序。我已经(正确地)将Flux集成到我的React Native项目中,但是dispatcher上的register
函数似乎完全没有响应。
Actions.js
import AppConstants from '../constants';
import AppDispatcher from '../dispatcher';
export default {
setUser (user) {
AppDispatcher.dispatch({
actionType: AppConstants.SET_USER,
user: user
})
}
}
Store.js
import AppDispatcher from '../dispatcher';
import AppConstants from '../constants';
import assign from 'object-assign';
import { EventEmitter } from 'events';
const CHANGE_EVENT = 'change';
const AppStore = assign({}, EventEmitter.prototype, {
emitChange () {
this.emit(CHANGE_EVENT);
},
addChangeListener (callback) {
this.on(CHANGE_EVENT, callback);
},
removeChangeListener (callback) {
this.removeListener(CHANGE_EVENT, callback);
},
dispatcherIndex: register(function (action) {
console.log(action); // <-- No response
})
});
export default AppStore;
Dispatcher.js
import { Dispatcher } from 'flux';
module.exports = new Dispatcher();
我甚至尝试重写Dispatcher.js文件,以便dispatch
和register
函数是硬编码的。我得到了dispatch()
的响应,但从来没有得到register()
的响应。
Dispatcher2.js
import { Dispatcher } from 'flux';
const flux = new Dispatcher();
export function register (callback) {
console.log('event!');
return flux.register(callback);
}
export function dispatch (action) {
console.log(action);
flux.dispatch(action);
}
通读本文档。我不知道你的代码,但这样我们也可以使用flux。http://fluxxor.com/。这是非常简单和容易使用。如果这对你的问题有帮助,请接受这个答案。
你从哪里得到商店的代码?无论如何,当其他属性都是纯函数时,dispatchIndex被作为方法调用是有原因的吗?
冒着给你的代码没有帮助的风险,这里是我如何根据react flux文档来使用香草flux的存储:
import Immutable from 'immutable'
import {ReduceStore} from 'flux/utils'
import myActionTypes from './../data/myThing/myActionTypes'
import dispatcher from '../data/dispatcher'
import AppConstant from '../data/myThing/AppConstant'
class myStore extends ReduceStore{
constructor(){
super(dispatcher);
}
getInitialState(){
return Immutable.OrderedMap({});
}
reduce(state,action){
switch(action.actionType){
case AppConstant.SET_USER:
return state.set({//data you want to set})
case AppConstant.OTHER_THING:
//additional logic
希望这是有用的,而不仅仅是我告诉你放弃你的代码为一些不相关的
相关文章:
- 在dhtmlx调度程序中多次触发OnEventSave
- React/flux - 子组件用户事件 - 是否应通过调度程序路由所有内容
- dhtmlx多个调度器不工作错误”;调度程序未定义”;
- DHTMLX调度程序筛选
- DHTMLX 移动调度程序事件详细信息视图高度问题
- 如何自动单击 AJAX 响应处理程序中自动生成的链接
- fuelUx 调度程序在选择每周重复周期时会丢失一天的信息
- 调度程序未在开玩笑单元测试中注册回调
- 如何将复杂对象绑定到剑道调度程序中的字段
- 将请求调度程序与 Jquery/AJAX 一起使用
- 寻找AngularJS日历调度程序
- 剑道调度程序不显示数据
- JavaScript 任务调度程序(批处理处理)
- 剑道 UI 调度程序 - JSON 数据未显示
- 重新加载剑道 UI 调度程序
- RxJS测试可观察序列,无需传递调度程序
- 在剑道调度程序中获取所选事件的 html 元素
- 带有 JSON 数据的 JavaScript Kendo 调度程序仅移动事件一次
- 有没有像tungle.me这样的日历调度程序的javascript/jquery实现
- React Native + Flux,无响应调度程序