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的更多相关文章

  1. 构建具有用户身份认证的 React + Flux 应用程序

    原文:Build a React + Flux App with User Authentication 译者:nzbin 译者的话:这是一篇内容详实的 React + Flux 教程,文章主要介绍了 ...

  2. React容器组件和展示组件

    Presentational and Container Components   展示组件   - 只关心它们的样子.   - 可能同时包含子级容器组件和展示组件,一般含DOM标签和自定的样式.   ...

  3. Flux 普及读本

    话说当时做 APP 时,三月不知肉味,再次将眼光投放前端,有种天上一天,地下一年的感觉. Flux 是一种思想 了解的最好方式当然是看Flux官方文档了.React 中文站点也能找到对应的翻译版本,但 ...

  4. redux+flux(一:入门篇)

    React是facebook推出的js框架,React 本身只涉及UI层,如果搭建大型应用,必须搭配一个前端框架.也就是说,你至少要学两样东西,才能基本满足需要:React + 前端框架. Faceb ...

  5. 【原】flux学习笔记

    最近React(web/native)依旧如火如荼,相信大家都跃跃欲试,入职新公司,现在的团队也开始在React领域有所尝试. 2016年应该是React 逐渐走向成熟的一年.之前在原来公司搞不懂的问 ...

  6. 【go】脑补框架 Express beego tornado Flux reFlux React jsx jpg-ios出品

    http://goexpresstravel.com/ 今天 Express 的作者 TJ Holowaychuk 发了一篇文章,正式宣告和 Node.js 拜拜了,转向 Go 语言. Go vers ...

  7. [Flux] 2. Overview and Dispatchers

    Flux has four major components: Stores, Dispatchers, Views, and Actions. These components interact l ...

  8. Flux

    Ken Wheeler 构建React 应用的一套架构.  应用程序架构, 单向数据流方案. Dispatcher 的开源库.   一种全局pub/sub 系统的事件处理器, 用于 向所注册的加调函数 ...

  9. 使用 React 和 Flux 创建一个记事本应用

    React,来自 Facebook,是一个用来创建用户界面的非常优秀的类库.唯一的问题是 React 不会关注于你的应用如何处理数据.大多数人把 React 当做 MV* 中的 V.所以,Facebo ...

随机推荐

  1. 生产环境CentOS服务器系统安全配置

    转http://www.centoscn.com/CentosSecurity/CentosSafe/2014/1126/4192.html 账户安全及权限 禁用root以外的超级用户 删除不必要的账 ...

  2. 更改input【type=file】样式

    <!DOCTYPE html> <html> <head> <meta http-equiv="Content-Type" content ...

  3. socket+网路编程

    1.网络编程: 通过某种计算机语言来实现不同设备间的资源共享和信息传递.计算机网络的创造可能比计算机本身意义更重大!!!(否则,你只能玩单机版游戏 OSI模型 OSI模型定义了不同计算机互联的标准,是 ...

  4. C++11老关键字的新含义(auto, using,extern)

    http://blog.csdn.net/cnsword/article/details/8034947 公司可以使用c++11.看大牛的代码模仿使用,所以现在已经不知道什么使用的是c++的语法还是c ...

  5. go bytes缓冲区使用介绍

    缓冲区原理简介: go字节缓冲区底层以字节切片做存储,切片存在长度len与容量cap, 缓冲区写从长度len的位置开始写,当len>cap时,会自动扩容.缓冲区读会从内置标记off位置开始读(o ...

  6. 浅谈.Net和Java互相调用的三种方式

    在很多的大型系统开发中,开发工具往往不限制于同一种开发语言,而是会使用多种开发语言的混合型开发.目前Java和.Net都声称自己占85%的市场份 额,不管谁对谁错,Java和.Net是目前应用开发的两 ...

  7. Initializing Spring root WebApplicationContext

    最近 我部署ssh项目的时候经常出现这样的问题,我的解决办法是 log4j:WARN No appenders could be found for logger (org.springframewo ...

  8. Qt中连接到同一signal的多个slots的执行顺序问题(4.6以后按连接顺序执行)

    起源 前些天忘记在哪儿讨论过这个问题,今天在csdn又看到有网友问这个问题,而其他网友却无一例外的给出了“无序”这个答案. Manual Qt的问题,当manual中有明确文字说明时,我们应该以Qt的 ...

  9. 使用Sass和Compass组合写CSS

    最近开始在尝试开始使用Sass来写CSS代码,刚开始虽然还是不太习惯用链式的方式写css,不过这是暂时的阶段. 如果你还不了解Sass,可以看之前发表过的文章来了解详情,Sass主要有下面这几种特性( ...

  10. 利用ROWID快速执行关联更新

    一.构造相关表P1,P2 create table p1(id int,name char(10)); create table p2(id int,name char(10)); 二.批量插入数据 ...