[Flux] 3. Actions
Actions contain no functionality, but rather describe an event in our application. In this lesson we will describe our Actions as they relate to our application. These Actions will then be available for triggering in our Views and for execution in our Store.
First create an list of actions in js/constants/app-constants.js
module.exports = {
ADD_ITEM: 'ADD_ITEM',
REMOVE_ITEM: 'REMOVE_ITEM',
INCREASE_ITEM: 'INCREASE_ITEM',
DECREASE_ITEM: 'DECREASE_ITEM'
};
js/actions/app-actions:
var AppConstants = require('../constants/app-constants');
var AppDispatcher = require('../dispatchers/app-dispatcher');
var AppActions = {
addItem: function (item) {
AppDispatcher.handleViewAction({
actionType: AppConstants.ADD_ITEM,
item: item
});
},
removeItem: function (index) {
AppDispatcher.handleViewAction({
actionType: AppConstants.REMOVE_ITEM,
index: index
});
},
increaseItem: function (index) {
AppDispatcher.handleViewAction({
actionType: AppConstants.INCREASE_ITEM,
index: index
});
},
descreaseItem: function (index) {
AppDispatcher.handleViewAction({
actionType: AppConstants.DECREASE_ITEM,
index: index
});
},
};
module.exports = AppActions;
For testing and see how it work, we using it for testing:
In app.js, include the actions module and bind to an click event.
var React = require('react');
var Action = require('../actions/app-actions');
var App = React.createClass({
handleClick: function () {
Action.addItem('This is an action to add');
},
render: function(){
return (<h1 onClick={this.handleClick}> My App</h1>);
}
});
module.exports = App;
Then log out the result in actions file:
addItem: function (item) {
console.log(item );
AppDispatcher.handleViewAction({
actionType: AppConstants.ADD_ITEM,
item: item
});
},
In the console, you will see it logs out "This is an action".
[Flux] 3. Actions的更多相关文章
- 构建具有用户身份认证的 React + Flux 应用程序
原文:Build a React + Flux App with User Authentication 译者:nzbin 译者的话:这是一篇内容详实的 React + Flux 教程,文章主要介绍了 ...
- React容器组件和展示组件
Presentational and Container Components 展示组件 - 只关心它们的样子. - 可能同时包含子级容器组件和展示组件,一般含DOM标签和自定的样式. ...
- Flux 普及读本
话说当时做 APP 时,三月不知肉味,再次将眼光投放前端,有种天上一天,地下一年的感觉. Flux 是一种思想 了解的最好方式当然是看Flux官方文档了.React 中文站点也能找到对应的翻译版本,但 ...
- redux+flux(一:入门篇)
React是facebook推出的js框架,React 本身只涉及UI层,如果搭建大型应用,必须搭配一个前端框架.也就是说,你至少要学两样东西,才能基本满足需要:React + 前端框架. Faceb ...
- 【原】flux学习笔记
最近React(web/native)依旧如火如荼,相信大家都跃跃欲试,入职新公司,现在的团队也开始在React领域有所尝试. 2016年应该是React 逐渐走向成熟的一年.之前在原来公司搞不懂的问 ...
- 【go】脑补框架 Express beego tornado Flux reFlux React jsx jpg-ios出品
http://goexpresstravel.com/ 今天 Express 的作者 TJ Holowaychuk 发了一篇文章,正式宣告和 Node.js 拜拜了,转向 Go 语言. Go vers ...
- [Flux] 2. Overview and Dispatchers
Flux has four major components: Stores, Dispatchers, Views, and Actions. These components interact l ...
- Flux
Ken Wheeler 构建React 应用的一套架构. 应用程序架构, 单向数据流方案. Dispatcher 的开源库. 一种全局pub/sub 系统的事件处理器, 用于 向所注册的加调函数 ...
- 使用 React 和 Flux 创建一个记事本应用
React,来自 Facebook,是一个用来创建用户界面的非常优秀的类库.唯一的问题是 React 不会关注于你的应用如何处理数据.大多数人把 React 当做 MV* 中的 V.所以,Facebo ...
随机推荐
- Discuz论坛下载与安装
Part1 Discuz下载 百度“discuz下载” 2. 找到下图这里 3. 选择你需要的版本,这里我选了X3.1版 4. 选择UTF-8简体下载 这是我下载好的文件 Part2 Discuz安装 ...
- Type 类型
修改 type 类型 UPDATE wd_order2 SET info = array_append(info, row(2,100001, now() )::info ) WHERE id_ ...
- UFLDL教程(六)之栈式自编码器
第0步:初始化一些参数和常数 第1步:利用训练样本集训练第一个稀疏编码器 第2步:利用训练样本集训练第二个稀疏编码器 第3步:利用第二个稀疏编码器提取到的特征训练softmax回归模型 ...
- 000webhost找不到文件自定义错误
1.新建一个名为.htaccess的文本文件:2.在文件中输入如下代码:ErrorDocument 404 /404.php3.保存文件,将.htaccess上传到域名的根目录,再验证,呵呵,成功了! ...
- cademy的Java习题做后感
在cademy各种语言的hello world也做了不少,好像都差不多,先是数据类型,然后条件语句,之后面向对象,再上几个特殊对象. 以前都没有做笔记,导致ruby做完就忘光了,这次好歹写点什么,比如 ...
- MYSQL常用命令集合
1.导出整个数据库 mysqldump -u 用户名 -p --default-character-set=latin1 数据库名 > 导出的文件名(数据库默认编码是latin1) mysqld ...
- 中文乱码 $dbh->do("SET NAMES utf8");
use DBI; my $dbUser='DEVOPS'; my $user="root"; my $passwd="kjk123123"; my @arr2= ...
- android gradle 多渠道打包
buildscript { repositories { mavenCentral() } dependencies { classpath 'com.android.tools.build:grad ...
- ECHO.js 纯javascript轻量级延迟加载
演示 <!DOCTYPE html> <html lang="zh-CN"> <head> <meta charset="utf ...
- bzoj2597
非常好的网络流题目 首先这里用到了求补集的思想,我们可以先求不满足的三元对的情况 设A-->B代表A赢B 由于最后所有胜负关系都确定,一定是一个完全图,所以任意一个不合法的三元对,单独取出来一定 ...