创建react应用程序_如何使用React创建一个三层应用程序

创建react应用程序

Discover Functional JavaScript was named one of the best new Functional Programming books by BookAuthority!

“发现功能JavaScript”BookAuthority评为最佳新功能编程书籍之一

Splitting a Single Page Application into layers has a set of advantages:

将单页应用程序拆分为多个层具有一系列优点:

  • a better separation of concerns

    更好的关注点分离
  • the layer implementation can be replaced

    层实现可以替换
  • the UI layer can be hard to test. By moving the logic to other layers, it becomes easier to test.

    UI层可能很难测试。 通过将逻辑移到其他层,测试变得更加容易。

Below we can see the diagram of an application split in the three main layers:

在下面,我们可以看到将应用程序的图分为三个主要层:

  • UI (aka Presentation, View)

    用户界面(又名演示文稿,视图)
  • Domain (aka Business)

    域(又名业务)
  • Data Access

    资料存取

展示柜 (The showcase)

I’ll take the case of an application managing a list of to-dos. The user is able to see and search for to-dos.

我将以一个应用程序管理待办事项列表为例。 用户能够查看和搜索待办事项。

检查git-hub的完整实现 。 (Check the full implementation on git-hub.)

UI层 (UI Layer)

The UI layer is responsible for displaying data on the page, and for handling user interactions. The UI Layer is made up of components.

UI层负责在页面上显示数据,并负责处理用户交互。 UI层由组件组成。

I split the page in the following components:

我将页面分为以下几个部分:

  • TodoContainer manages the communication between TodoSearch, TodoList and other external objects

    TodoContainer管理TodoSearchTodoList与其他外部对象之间的通信

  • TodoSearchForm is the form for searching to-dos

    TodoSearchForm是用于搜索待办事项的表单

  • TodoList displays the list of to-dos

    TodoList显示待办事项列表

  • TodoListItem: displays a single to-do in the list

    TodoListItem:在列表中显示一个待办事项

待办事项搜索 (TodoSearch)

The component uses the handleChange handler to read the input value on any change. TodoSearch exposes a new property: onSearch . It can be used by the parent component to handle the search click.

组件使用handleChange 处理程序以读取任何更改的输入值。 TodoSearch公开了一个新属性: onSearch 。 父组件可以使用它来处理搜索单击。

The component doesn't communicate with any other external objects, except its parent. TodoSearch is a presentation component.

该组件不与其父对象以外的任何其他外部对象进行通信。 TodoSearch是一个演示组件。

export default class TodoSearch extends React.Component { constructor(props){super(props);this.search = this.search.bind(this);this.handleChange = this.handleChange.bind(this);this.state = { text: "" };}search(){const query = Object.freeze({ text: this.state.text });if(this.props.onSearch)this.props.onSearch(query);}handleChange(event) {this.setState({text: event.target.value});}render() {return <form><input onChange={this.handleChange} value={this.state.text} /><button onClick={this.search} type="button">Search</button></form>;}
}

待办事项清单 (TodoList)

TodoList gets the list of todos to render using a property. It sends the todos, one by one, to the TodoListItem.

TodoList获取列表中todos使用属性来呈现。 它发送todos ,一个接一个,到TodoListItem

TodoList is a stateless functional component.

TodoList是无状态功能组件。

export default function TodoList(props) {function renderTodoItem(todo){return <TodoListItem todo={todo} key={todo.id}></TodoListItem>;}return <div className="todo-list"><ul>{ props.todos.map(renderTodoItem) }</ul></div>;
}

TodoListItem (TodoListItem)

TodoListItem displays the todo received as a parameter. It is implemented as a stateless functional component.

TodoListItem将接收到的todo显示为参数。 它被实现为无状态功能组件。

export default function TodoListItem(props){return       <li><div>{ props.todo.title}</div><div>{ props.todo.userName }</div></li>;
}

Read Functional Architecture with React and Redux and learn how to build apps in function style.

阅读具有React和Redux的功能架构,并学习如何以函数样式构建应用程序。

Discover Functional JavaScript was named one of the best new Functional Programming books by BookAuthority!

发现功能JavaScript被称为 BookAuthority最好的新功能编程书籍

For more on applying functional programming techniques in React take a look at Functional React.

有关在React中应用函数式编程技术的更多信息,请查看 Functional React

You can find me on Medium and Twitter.

您可以在Medium和Twitter上找到我。

翻译自: https://www.freecodecamp.org/news/how-to-create-a-three-layer-application-with-react-8621741baca0/

创建react应用程序

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/392997.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

linux update语句,MySQL 多表 update sql语句总结

MySQL 多表 update 有几种不同的写法。假定我们有两张表&#xff0c;一张表为Product表存放产品信息&#xff0c;其中有产品价格列Price&#xff1b;另外一张表是ProductPrice表&#xff0c;我们要将ProductPrice表中的价格字段Price更新为Price表中价格字段的80%。在Mysql中我…

linux延时与定时操作

1、at ---系统延迟任务发起命令 at time >command ---任务指令 >ctrld ---发起任务 at -l ---列出延时任务Id at -r id ---删除改id任务 at -m ---让无输出的命令产生邮件 at -M ---让有输…

windows修改PowerShell(命令提示符)默认中文编码方式

如果以下方法都没有作用的话&#xff0c;可以直接在代码中调用<stdlib.h>中的system("mode con cp select65001")或者是system("chcp 65001")。当然&#xff0c;前提是你用的也是C、C、C#等强类型编程语言。 **************************************…

leetcode面试题 17.07. 婴儿名字(并查集)

每年&#xff0c;政府都会公布一万个最常见的婴儿名字和它们出现的频率&#xff0c;也就是同名婴儿的数量。有些名字有多种拼法&#xff0c;例如&#xff0c;John 和 Jon 本质上是相同的名字&#xff0c;但被当成了两个名字公布出来。给定两个列表&#xff0c;一个是名字及对应…

appium+python+iOS 环境搭建与使用中常见问题的解决方案链接

&#xff08;1&#xff09;WebDriverAgent 安装入门篇&#xff1a;https://www.cnblogs.com/zhanggui/p/9239827.html 重点摘要&#xff1a; 在WDA的Github上也给出了WDA的特性&#xff1a; 1.支持真机 &&模拟器 在模拟器上运行还是比较方便的&#xff0c;在真机上需要…

api工厂接口路径是什么_为什么(几乎)永远不要再使用绝对路径访问API

api工厂接口路径是什么by Vitaly Kondratiev通过维塔利康德拉季耶夫(Vitaly Kondratiev) 为什么(几乎)永远不要再使用绝对路径访问API (Why you should (almost) never use an absolute path to your APIs again) Recent advances in web apps architecture show that a decou…

双机通信c语言程序,上传一个自己编写的I2C双机通信程序

本帖最后由 micro_听海 于 2012-11-24 19:58 编辑这几天一直在搞AVR的twi(twi就是i2c)双机通信程序&#xff0c;使用的是两块arduino开发板。因为最总要这个通信程序最总是要放在winavr的编译环境中&#xff0c;所以没有使用arduino自带的库函数。但是这没关系&#xff0c;因为…

leetcode684. 冗余连接(并查集)

在本问题中, 树指的是一个连通且无环的无向图。 输入一个图&#xff0c;该图由一个有着N个节点 (节点值不重复1, 2, …, N) 的树及一条附加的边构成。附加的边的两个顶点包含在1到N中间&#xff0c;这条附加的边不属于树中已存在的边。 结果图是一个以边组成的二维数组。每一…

Windows Server 2008 部署权限管理RMS

1.1 实战&#xff1a;部署权限管理 试验目的&#xff1a; 在单域环境中部署活动目录权限管理服务&#xff0c;实现文档的保护。 试验环境&#xff1a; ? DCServer安装Windows Server 2008企业版&#xff0c;是ess.com的域控制器&#xff0c;安装企业CA。 ? RMSServer安装Wind…

day5 Python爬虫学习

一 实现京东上的自动搜索并提取信息 from selenium import webdriver # 导入键盘Keys from selenium.webdriver.common.keys import Keys import timedriver webdriver.Chrome()# 检测代码块 try:# 隐式等待&#xff0c;等待标签加载driver.implicitly_wait(10)# 往京东主页…

虚拟dom添加虚拟dom_虚拟DOM缓慢。 认识记忆化的DOM

虚拟dom添加虚拟domby Sindre Osen Aarsaether通过Sindre Osen Aarsaether 虚拟DOM缓慢。 符合已记忆的DOM。 (The Virtual DOM is slow. Meet the Memoized DOM.) 超越虚拟DOM和状态管理 (Moving beyond the Virtual DOM and State Management) The virtual DOM was a fantas…

编写一个字节数的rtu C语言校验程序,Modbus通信协议中CRC校验的快速C语言算法

Modbus通信协议中CRC校验的快速C语言算法2004年第11期            福 建 电 脑  63Modbus通信协议中CRC校验的快速C语言算法孟开元(西安石油大学计算机学院陕西西安710065)【摘 要】 本文主要讨论了Modbus通信协议的RTU帧格式中常用的错误校验方法,即循环冗…

leetcode1319. 连通网络的操作次数(并查集)

用以太网线缆将 n 台计算机连接成一个网络&#xff0c;计算机的编号从 0 到 n-1。线缆用 connections 表示&#xff0c;其中 connections[i] [a, b] 连接了计算机 a 和 b。 网络中的任何一台计算机都可以通过网络直接或者间接访问同一个网络中其他任意一台计算机。 给你这个…

Codeforces 600E Lomsat gelral (树上启发式合并)

题目链接 Lomsat gelral 占坑……等深入理解了再来补题解…… #include <bits/stdc.h>using namespace std;#define rep(i, a, b) for (int i(a); i < (b); i)typedef long long LL;const int N 600010;int n; int cc[N], col[N], sz[N], son[N]; LL ans[N];vect…

如何让CloudStack使用KVM创建Windows实例成功识别并挂载数据盘

问题产生背景&#xff1a; 使用CloudStack KVM组合进行资源池纳管工作&#xff0c;通过ISO镜像文件创建了两个模板&#xff1a; RHEL6U3 64位系统以及WindowsServer2008 R2 SP1 64位系统。然后通过模板创建实例&#xff0c;挂载外接存储&#xff0c;实例启动后&#xff0c;通过…

云计算openstack介绍

转载于:https://www.cnblogs.com/WIU1905/p/11107593.html

C语言Node lt T gt,c语言论坛填空;#includelt;stdio.hgt;# 爱问知识人

填空&#xff1b;#include #include #define N 6typedef struct node {int data;struct node *next;填空&#xff1b;#include #include #define N 6typedef struct node {int data;struct node *next;} NODE;void fun(NODE *h){ NODE *p, *q; int t;/**********found*********…

gitlab设置邮件服务器_如何设置您自己的一次性电子邮件服务器

gitlab设置邮件服务器by Oren Geva由Oren Geva 如何设置您自己的一次性电子邮件服务器 (How To Setup Your Own Disposable Email Server) Disposable email services are online services that provide temporary email addresses for registering or signing up on websites…

leetcode442. 数组中重复的数据

给定一个整数数组 a&#xff0c;其中1 ≤ a[i] ≤ n &#xff08;n为数组长度&#xff09;, 其中有些元素出现两次而其他元素出现一次。 找到所有出现两次的元素。 你可以不用到任何额外空间并在O(n)时间复杂度内解决这个问题吗&#xff1f; 示例&#xff1a; 输入: [4,3,2…

C语言基础注意点

一、基础知识篇 &#xff08;一&#xff09;关键字 1&#xff0c;存储类型 A、auto 声明自动变量&#xff0c;一般不使用 B、static 声明静态变量 C、extern 声明变量是在其他文件正声明&#xff08;可看做引用变量&#xff09; D、register 声明积有器变量 2、常用…