如何判断何时创建新组件? [英] How to tell when to create a new component?

查看:91
本文介绍了如何判断何时创建新组件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在探究何时有人应在angularjs/angular 上的Web应用程序中创建新组件的逻辑背后,但我想这比较笼统,并且可能适用于所有基于组件的前端最终框架.

I've been looking around behind the logic of when someone shall create a new component in a web application on angularjs / angular but I suppose this is more general and might apply on all component based front end frameworks.

我知道有一些原则,例如它应该是抽象的和可重用的,但例如我在angular文档上看到,每条单独的路线都针对特定的组件(如何可重用). 在创建新组件之前是否有任何疑问??

I know that there are some principles like it should be abstract and reusable but e.g. I have seen on angular docs that each separate route looks at a specific component (how can this be reusable). Is there any solid question which I might ask before creating a new component ?

推荐答案

为了做出是否必须创建组件的决定,我认为您必须回答以下问题:

In order to make a decision whether you have to create a component or not, i think you have to answer the following questions:

  1. 您的代码块是否有可能被重用?如果可以,构造一个新组件似乎是个好主意.
  2. 您的代码是否很复杂?如果可以,将其拆分为单独的组件是一个好主意,以使您的代码更具可读性和可维护性.

这篇关于如何判断何时创建新组件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆