创建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应用程序

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

  1. 利用python写时钟程序_如何用python编写一个番茄钟程序

    今天,我们尝试用python来编写一个简单的PC端番茄钟,需要实现的功能如下:启动时"滴"一声并询问:"休息时间结束!是否开始一个新的番茄钟?" 如果用户点击& ...

  2. js摇号程序_用JavaScript写的一个摇号程序(随机数)

    老弟叫我帮忙他找个摇号程序,号码从001-200.最近刚看了JS高级编程的随机数这方面的知识.就自己开始动手做了一个. 代码: var theTimer; var iNum=0; //var flag ...

  3. 程序员:要想成为一个伟大的程序员

    程序员:要想成为一个伟大的程序员,首先,要有钱,没钱等着饿死,其次,需要的可不仅仅是能够编写出可以正常运行的代码.Justin James给出了能够成为业内顶尖高手的程序员应该具有的几个典型特质. 要 ...

  4. 创建react应用程序_如何将React应用程序部署到Netlify

    创建react应用程序 by Abhishek Jakhar 通过阿比舍克·贾卡(Abhishek Jakhar) 如何将React应用程序部署到Netlify (How to deploy a Re ...

  5. react.js做小程序_如何使用React.js构建现代的聊天应用程序

    react.js做小程序 In this tutorial, I will guide you to build your own group chat application using React ...

  6. 如何命令行结束react程序_前端架构React和Vue CTO的选择正确框架的指南

    快速总结:为项目选择正确的javascript框架或库是CTO和项目经理的基本任务.然而,选择的范围很大程度上取决于几个因素,如项目时间.学习曲线.框架性能和团队规模.这篇文章旨在指导他们选择正确的j ...

  7. react 服务器端渲染_服务器端渲染React应用程序的动手指南

    react 服务器端渲染 In the previous article, we described how to make a production build and deploy it to a ...

  8. react前端项目_如何使用React前端设置Ruby on Rails项目

    react前端项目 The author selected the Electronic Frontier Foundation to receive a donation as part of th ...

  9. react前端开发_是的,React正在接管前端开发。 问题是为什么。

    react前端开发 by Samer Buna 通过Samer Buna 是的,React正在接管前端开发. 问题是为什么. (Yes, React is taking over front-end ...

最新文章

  1. iOS 自定义双向滑块Slider
  2. c语言面向对象编程中的类_C ++中的面向对象编程
  3. 电路分析导论_生存分析导论
  4. python123百钱买百鸡_day01笔记-百钱买百鸡(100文钱,必须买100只鸡,有几种方式)
  5. 【Spring】Spring 依赖注入之手动注入
  6. 与熊论道为什么解码不了_楼上熊孩子瞎蹦跳,楼下邻居投诉无果,一招吓哭“熊一家”...
  7. 何时不应该使用 Rails?
  8. HTML5 桌面通知:Notification API
  9. 计算机应用技术需要学数学吗,学计算机应用技术能不学数学吗?
  10. android 自由落体,Android动画之属性动画1 自由落体
  11. Linux下几种文件传输命令
  12. mysql的联接算法_【MySQL—SQL编程】联接
  13. 华夏ERP前端的问题解决
  14. Unity 显示FPS
  15. 服务器开机显示0x000000ca,使用电脑出现蓝屏代码0x000000CA故障该如何解决?
  16. 国美被曝停发员工工资;支付宝正式接入鸿蒙生态;推特遭到集体诉讼;小马智行业务调整,多位高管离职 | 每日大事件...
  17. shell脚本实现分日志级别输出
  18. 富士康对苹果死心塌地,然而突然传出的消息却让富士康懵了
  19. 求臻医学文章发表:NF1胚系新突变潜在提示胃肠道多发肿瘤风险
  20. 神经网络框架及相关信息收集

热门文章

  1. Java面试题及答案,mysql类型
  2. matlab怎让3d旋转,如何在MATLAB中平滑旋转3D绘图?
  3. (二)单元测试利器 JUnit 4
  4. hadoop hive 2.1.1 将Hive启动为服务
  5. tensorflow gpu windows配置步骤教学
  6. 数据结构06树和二叉树
  7. Spring Cloud 学习 (五) Zuul
  8. Adobe After Effects CS6 操作记录
  9. 找出性能消耗是第一步,如何解决问题才是关键
  10. bzoj千题计划282:bzoj4517: [Sdoi2016]排列计数