vue 设置组件不重用_与共享和管理可重用的JS组件

vue 设置组件不重用

Building an app may seem as simple as learning to code; however, building an app also involves API integration. And what better way to ensure good integration without struggling with it on your own (especially if you’re a novice app developer) than hiring a good third-party API. Though, with a large number of third-party providers that promise a smooth integration for your app, it can be easy to make mistakes during the process. And, if these mistakes aren’t rectified, and if they’re repeated, then the consequences can be taxing for both you and your app, creating negative app performance and a poor user experience.

开发一个应用似乎就像学习编码一样简单。 但是,构建应用程序还涉及API集成。 与雇用良好的第三方API相比,还有一种更好的方法来确保良好的集成而又不必自己(特别是如果您是新手应用程序开发人员)不费力气。 但是,由于许许多多的第三方提供商承诺可以为您的应用程序提供平滑的集成,因此在此过程中很容易出错。 而且,如果这些错误没有得到纠正,并且再次发生,那么后果可能是对您和您的应用造成负担,造成负面的应用性能和糟糕的用户体验。

First and foremost, when looking at APIs, look at them as off-the-shelf products, not as tools that are on-hand. Second, when building an app, you have to think of your potential users (i.e. clients), and how they’ll react if they spot an issue within the app. You wouldn’t want them to see a problem before you do.

首先,在查看API时,请将它们视为现成的产品,而不是现有的工具。 其次,在构建应用程序时,您必须考虑潜在的用户(即客户)以及他们在应用程序中发现问题时的React。 您不希望他们先遇到问题。

In this article, we’ll talk about the five common mistakes made when integrating APIs with apps, as well as point out how to avoid such mistakes.

在本文中,我们将讨论将API与应用程序集成时犯的五个常见错误,并指出如何避免此类错误。

Overlooking Legalities On API Use And User Data

忽略API使用和用户数据的合法性

“Many developers are prone to only reviewing the terms-of-use policy during integration,” says Max Raiwala, a blogger at State Of Writing and Paperfellows. “But sometimes, API providers change their terms of use without notifying users. And if you’re unaware of their new terms of use, and you happen to do something that violates those terms, then the provider would ban you from using their service, or even take you to court for said violation.”

State Of Writing and Paperfellows的博客作者Max Raiwala说:“许多开发人员倾向于在集成期间仅审查使用条款政策。” “但是有时候,API提供者会在不通知用户的情况下更改其使用条款。 而且,如果您不知道他们的新使用条款,而您碰巧做了违反这些条款的事情,那么提供商将禁止您使用他们的服务,甚至会因上述违反而将您告上法庭。”

Therefore, make sure that you’re always reading up on the rules and guidelines that your API provider has. Also, keep in mind the regulations regarding data that your country may have, or else you’ll be charged heavy fines, and face several penalties.

因此,请确保您始终阅读API提供程序所具有的规则和准则。 另外,请记住有关您的国家/地区可能拥有的数据的规定,否则将被处以高额罚款,并面临数项罚款。

Assuming That Third-Party APIs Support Is 24/7

假设第三方API支持为24/7

Some developers fail to make time to test and monitor third-party APIs, in case there are any issues. They may also fail to add code that ensures that your app is working properly, even when an API is oblivious to that failure. APIs become non-responsive or return errors for the following reasons:

万一出现任何问题,某些开发人员将没有时间测试和监视第三方API。 他们可能也无法添加代码来确保您的应用正常运行,即使API忽略了该失败。 由于以下原因,API变得无响应或返回错误:

  • Every API will eventually experience downtime, whether this event is planned or not planned.

    无论此事件是有计划的还是无计划的,每个API最终都会经历停机时间。
  • Connection timeouts are usually too short for many API providers.

    对于许多API提供程序而言,连接超时通常太短。
  • Call volumes vary. While API call volumes tend to be low during app development, call volumes will reach the rate limit once the is launched.

    通话量有所不同。 尽管在应用程序开发期间API调用量通常会很低,但启动后,调用量将达到速率限制。
  • “400 Bad Request Error” messages are common with APIs. Worst of all, it takes developers a long time for them to find out the root cause of such errors.

    API常见“ 400 Bad Request Error”消息。 最糟糕的是,开发人员需要很长时间才能找出此类错误的根本原因。

Therefore, don’t ever assume that your APIs are working well, since they might have hidden issues that you may want to look into before your customers spot them.

因此,永远不要假设您的API运行良好,因为它们可能存在隐藏的问题,您可能希望在客户发现它们之前先进行调查。

Assuming That APIs Will Alert You Of Any Changes

假设API会提醒您任何更改

Going with the theme of APIs not notifying their users of any changes, some APIs providers send notifications, while others don’t. Therefore, it’s a mistake for developers to assume that they’ll be sent alerts whenever a change happens. Chances are, any inkling of a change would be buried in the documentation without anyone noticing it.

遵循API的主题,即通知用户任何更改,一些API提供程序发送通知,而另一些则不发送。 因此,对于开发人员而言,假设发生更改时会向他们发送警报是错误的。 很有可能,任何更改的标记都会被埋在文档中,而不会有人注意到。

Here are some of the changes that API providers might do to your app without you knowing it:

以下是API提供程序可能在您不知情的情况下对您的应用所做的一些更改:

  • Change the design of an APi

    更改APi的设计
  • Reject an API

    拒绝API
  • Change used methods

    更改使用的方法
  • Remove API functionality

    删除API功能
  • Release a new version of an API

    发布新版本的API

If any of these changes are implemented at any time, they can break integrations, and bring down your app. Therefore, you need to manually check for any changes to the API, rather than rely heavily on a provider that won’t monitor such changes.

如果随时实施任何这些更改,它们可能会破坏集成并降低您的应用程序。 因此,您需要手动检查API的任何更改,而不是严重依赖不会监视此类更改的提供程序。

Not Representing Upstream Data As Well-Defined Objects

不将上游数据表示为定义良好的对象

Representing data as well-defined objects lets developers avoid issues when designing APIs. It’s especially essential when working with Javascript, because the data can be used to create a class out of them, and even access and hydrate a system into a class. But many times, developers would skip this step.

将数据表示为定义明确的对象可让开发人员在设计API时避免出现问题。 在使用Javascript时,这尤其重要,因为可以使用数据从它们中创建一个类,甚至可以将系统访问并合并到一个类中。 但是很多时候,开发人员会跳过这一步。

Here are some questions to consider when looking at the data:

在查看数据时,有一些问题需要考虑:

  • What properties are being relayed? (Answer: all of them, regardless of what they are)

    正在中继哪些属性? (答案:所有这些,无论它们是什么)
  • What happens if one of the retrieved properties is of the wrong type?

    如果检索到的属性之一类型错误怎么办?
  • What is the property is missing, but it’s still vital for the consumer?

    缺少什么财产,但对消费者来说仍然至关重要?

You never want to blindly send attributes, since API has no control over what’s received by users. When a user requests data from an upstream service, and converts that into an object, it creates a Plain Old Javascript Object (or POJO), which can be both convenient and risky. And such risks should be unnecessary for your app, because that can give your users the impression that you’re setting them up for a bad experience.

您永远都不想盲目发送属性,因为API无法控制用户收到的内容。 当用户从上游服务请求数据并将其转换为对象时,它将创建一个普通的旧Javascript对象(或POJO),这既方便又危险。 而且对于您的应用程序来说,这种风险应该是不必要的,因为这会使您的用户感到您为不良体验进行了设置。

Instead of letting POJOs get to your users first, represent those objects as a Domain Object (or DO). DOs make sure that app developers apply some structure to the objects that are retrieved. Such objects can also be used to make sure that properties exist and are of the right type; or else, the API can fail the request.

不要让POJO首先到达您的用户,而是将这些对象表示为域对象(或DO)。 DO确保应用程序开发人员将某种结构应用于所检索的对象。 这些对象也可以用来确保属性存在并且类型正确。 否则,API可能会使请求失败。

In addition, the same DOs should be used throughout your API responses. By using the same Domain Object:

此外,在您的API响应中应使用相同的DO。 通过使用相同的域对象:

  • Users can consistently deserialize data into their own internal representation, when they use your app.

    用户在使用您的应用程序时可以将数据反序列化为自己的内部表示形式。
  • Developers can efficiently take care of any bugs inside the app.

    开发人员可以有效地处理应用程序内部的所有错误。
  • Developers can provide a more consistent API in their app.

    开发人员可以在其应用程序中提供更一致的API。

Not Using Forward Compatible Attribute Naming

不使用前向兼容属性命名

“Always make sure that you’re naming attributes of objects in your API responses that are forward compatible with any updates that you plan on making in the future,” says Noah Gerard, a tech writer at Boomessays and Essay Help. “Don’t ever change the type or remove a field. Only add new fields to an object when necessary. Let your clients decide on whether or not to acknowledge a field.”

BoomessaysEssay Help的技术作家Noah Gerard表示:“始终确保在API响应中命名与将来计划进行的任何更新都向前兼容的对象属性。” “永远不要更改类型或删除字段。 仅在必要时将新字段添加到对象。 让您的客户决定是否确认一个字段。”

Conclusion

结论

It’s important to choose the right tools and techniques, when dealing with API integrations. Choosing the right development tools and coding techniques can help you avoid making these common API mistakes, and prevent errors and reduce the amount of time you would’ve spent debugging integrations.

在处理API集成时,选择正确的工具和技术很重要。 选择正确的开发工具和编码技术可以帮助您避免犯这些常见的API错误,并防止错误并减少调试集成所需的时间。

Beatrix Potter writes and edits for Academic Writing Service and UK Writings. She is also a manager and editor at Essayroo Reviews. As a professional writer, she specializes in API Integration and digital trends.

Beatrix Potter为 学术写作服务 英国著作 撰写和编辑 她还是 Essayroo Reviews 的经理和编辑 作为一名专业作家,她专门研究API集成和数字趋势。

使用Bit共享和管理可重用JS组件 (Share & Manage Reusable JS Components with Bit)

Use Bit (Github) to share, document, and manage reusable components from different projects. It’s a great way to increase code reuse, speed up development, and build apps that scale.

使用Bit ( Github )共享,记录和管理来自不同项目的可重用组件。 这是增加代码重用,加速开发并构建可扩展应用程序的好方法。

Bit supports NodeJS, TypeScript, React, Vue Angular, and more.

Bit支持NodeJS,TypeScript,React,Vue Angular等。

Image for post
Example: exploring shared React components on Bit.dev
示例:在 Bit.dev上浏览共享的React组件

相关故事 (Related Stories)

翻译自: https://blog.bitsrc.io/avoid-these-5-common-api-integration-mistakes-ed5de3dd30bb

vue 设置组件不重用

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值