1. Model is everything

  models are  the heart of your app. If you have models separated from th rest of your application, maintaince will be much easier,regradless of how complicated your application becomes. Even for complicated applications, good model implementation can result in extremely expressive code.And to achieve that, start by making sure that your models do only what they meat to do ,and don't concern thenselves with what the app built around it does. Furthermore, it doesn't concern itself with what the underlying data storage layer is:does your app rely on an SQl database,or dose it store everything in text files.

  As we continue this article, you will realize how great code is a lot about separatiuon of concern.

  数据模型是一个应用的心脏,当数据模型与应用的其它模块分离开来的时候,应用的可维护性将变得容易。一个应用的数据模型应该保持单一职责原则,不应该考虑建立的数据模型上的其它模块,同时也不应该关注数据是如何存储的。 (MVC)

  整洁的代码

  1.Clean code is a consistent style of programming that makes your code easier to write,read ,and maintain.

  2.Clean code is DRY (don't repeat yourself)

  3.Clean code is predictable and testable

  4.Clean code is self-commenting

  5.Naming things

    1.Boolean variables,or functions that return a boolean value, should start with "is","has","should"

    2.Functions should be named for what they do,not how they do it.In other words ,don't expose details of the implementation in the name

  6.Clean code follows proven design patterns and best practices

    1.Use samll fuctions,each with a single responsibility.Ensure that each function does one job and does it well . that also will lead to better testability.

    2.Be on the lookout for leaky abstractions. In onther words, don't impose your internal requirements on consumers of your code.

    3.Follow stric linting rules. This will help you write clean , consistent code.

  7.Separate stateful aspects from rendering

    Mixing your stateful data-loading logic with your rendering (or resentation) logic can lead to component complexity. Instead, write a stateful container component whose single responsibility is to load the data. Then write another component whose sole responsibility is to display the data. This is called the container pattern. Stateless functional component, the results are predictable.

  8.Use stateless function components

    Through optimization of React's core,it posible to use far less memory as no instance is created.

  9. Object destructing

    componentWillReceiveProps(newProps){

       this.setSate({active:newProps.active})

      }

    componentWillReceiveProps({active}){

      this.setState({active})
      }

React整洁的代码的一些原则的更多相关文章

  1. 代码整洁 vs 代码肮脏

    写出整洁的代码,是每个程序员的追求.<clean code>指出,要想写出好的代码,首先得知道什么是肮脏代码.什么是整洁代码:然后通过大量的刻意练习,才能真正写出整洁的代码. WTF/mi ...

  2. 通过利用immutability的能力编写更安全和更整洁的代码

    通过利用immutability的能力编写更安全和更整洁的代码 原文:Write safer and cleaner code by leveraging the power of "Imm ...

  3. 王家林系列之scala--第69讲:Scala并发编程react、loop代码实战详解

    刚才看了一下,群里王家林老师又更新课程了,真为王老师的勤奋感到佩服,于是迫不及待的下载下来观看学习.本期讲的是关于scala并发编程的react.loop代码实战. 信息来源于 DT大数据梦工厂微信公 ...

  4. 高效整洁CSS代码原则(上)

    CSS学起来并不难,但在大型项目中,就变得难以管理,特别是不同的人在CSS书写风格上稍有不同,团队上就更加难以沟通,为此总结了一些如何实现高效整洁的CSS代码原则: 1. 使用Reset但并非全局Re ...

  5. 高效整洁CSS代码原则 (下)

    6. 适当的代码注释 代码注释可以让别人更容易读懂你的代码,且合理的组织代码注释,可使得结构更加清晰.你可以选择做的样式表的开始添加目录: /*---------------------------- ...

  6. 代码重构方向原则指导(转载 cnblogs)

    英文原文:Hill Climbing (Wonkish)   重构是一种对软件进行修改的行为,但它并不改变软件的功能特征,而是通过让软件程序更清晰,更简洁和更条理来改进软件的质量.代码重构之于软件,相 ...

  7. Scala并发编程react、loop代码实战具体解释

    演示样例代码及凝视: //scala并发编程中的react和loop,共同特点: //通过线程存用的方式让性能有所提升. //Actor本身的运行,被actor子系统管理的时候,会有一个或者多个远程的 ...

  8. 【React】在React中 JSX 代码如何转成 JS 代码?

    一.介绍 写 React 代码的朋友应该都是直接写 JSX 代码,JSX 让我们可以在 JS 中直接写 HTML 代码,可阅读性较高.本章节主要介绍 JSX 通过 babel 转换后会生成什么样式代码 ...

  9. webstorm编写react native,代码修改后,重新编译运行没有变化的问题

    w我是拷贝一份react native代码到另一台电脑,发现修改代码运行之后不显示修改后的效果,即仍然与原来的效果一样,暂时不知道什么原因, 后来我运行了npm install 就可以了,不知道是不是 ...

  10. react native 示例代码

    https://react.rocks/tag/ReactNative?show=60 https://github.com/ReactNativeNews/React-Native-Apps

随机推荐

  1. ES5 绑定 this 的方法

    this的动态切换,固然为 JavaScript 创造了巨大的灵活性,但也使得编程变得困难和模糊.有时,需要把this固定下来,避免出现意想不到的情况.JavaScript 提供了call.apply ...

  2. 用windows 定时任务执行kettle的ktr文件,以及问题处理

    新建.bat文件,输入下面的批处理语句 d: cd D:\kettle\data-integration\ pan /file D:\etltest\EtltestTrans.ktr 第一行:进入你的 ...

  3. win10 + emacs + sml

    1.官网下载sml编译器是smi安装包,安装结束之后把bin文件夹放到环境变量Path中 2.下载emacs压缩包,直接解压 3.emacs中alt+x,输入package-list 然后选择sml- ...

  4. Java基础学习:12、代码块

    1.定义: 代码块又称为初始化块,属于类中的成员,将逻辑语句封装在方法体中,通过{}包围起来. 2.分类: 普通代码块.静态代码块(有static修饰) public class Block { pu ...

  5. 与IE浏览器相关的问题(一)

    使用<input class="input" type="password" /> 密码框时,会出现密码显示状态的图标, 可以使用以下代码消除, . ...

  6. 【Pr】如何将音频剪成多段批量导出

    如何将音频剪成多段批量导出 需要软件: Pr, Adobe Media Encoder (时间线窗口中) 用剃刀将音频割成多段 (时间线窗口中) 选中音频右键 | 嵌套 | 输入名字 (嵌套快捷键:A ...

  7. 【B站】B站计算集数时长,调节任意倍速

    打开浏览器,任意收藏一个网址,将URL替换为下面的代码并保存 打开任意B站视频页面,点击这个收藏的网址,即可在页面右边看到如下窗口 javascript: (function () { var hou ...

  8. ES6-Promise上

    一.Promise作用:解决回调地狱问题 transitionend是过渡结束事件,只要过渡结束就会触发: 回调地狱:指的是层层嵌套的回调函数,代码看起来非常晕 <!DOCTYPE html&g ...

  9. 阻塞I/O,非阻塞I/O,同步I/O,异步I/O

    根据应用程序是否阻塞自身运行分为: 阻塞I/O:是指应用程序在执行I/O操作后,如果没有获得响应,          就会阻塞当前线程,不能执行其他任务. 非阻塞I/O:是指应用程序在执行I/O操作后 ...

  10. mysql 导入问题排查

    ERR] 2006 - MySQL server has gone away -- 查询最大数 show global variables like 'max_allowed_packet'; -- ...