創建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.pswp.cn/news/392997.shtml
繁體地址,請注明出處:http://hk.pswp.cn/news/392997.shtml
英文地址,請注明出處:http://en.pswp.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、常用…