reactjs – React的“scryRenderedDOMComponentsWithClass”方法名称来自哪里?

前端之家收集整理的这篇文章主要介绍了reactjs – React的“scryRenderedDOMComponentsWithClass”方法名称来自哪里?前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
在测试一个React组件时,我正在阅读文档,并发现scryRenderedDOMComponentsWithClass。我无法理解这个组件的功能,因为它是不可公开的,所以我不明白它是如何命名映射到一个心理模型,它在做什么。 (有一些相关的名称,如scryRenderedDOMComponentsWithTag。)

这个方法名称的scry部分是什么引用的?害怕?疾走?这个名字试图说明什么概念?

简短答案

在这种情况下,“Scry”意味着“找到所有”。见this comment on ReactTestUtils.scryRenderedComponentsWithClass.这是一个单词,而不是缩写,它的发音如“cry”,但在开头有一个“s”。

更长(和nerdier)答案

在同一个文件的其他地方,你会看到a reference to DOM.scry

/**
 * Todo: Support the entire DOM.scry query Syntax. For now,these simple
 * utilities will suffice for testing purposes.
 * @lends ReactTestUtils
 */

zpao在a comment on a GitHub issue年解释说:

That’s a reference to an internal Facebook module. It’s basically querySelectorAll with fallback behavior for handling old browsers and special cases. It is pretty unremarkable and doesn’t actually translate super well here (except maybe a scryRenderedDOMComponentsWithQSA or something,but meh). We’re working on improving the testing in other ways so I don’t think there’s anything we really want to do with this right now.

jimfb在another GitHub issue进一步说明,该名称是对“地下城与地下城”的引用。龙:

Back in the day,we had a bunch of D&D fans on the team.

For reference:
07004
07005
07006

Historically,we’ve used scry to indicate a helper that finds a set of results. As the framework matures,we should start choosing function names based on what the functions actually do instead of fantasy words that have very little meaning to the typical developer.

虽然我同意这个词在很大程度上没有意义,但值得注意的是“scry” is a real English word

scry
[skrahy]

verb (used without object),scried,scrying.

  1. to use divination to discover hidden knowledge or future events,especially by means of a crystal ball.

有趣的是,根据the data from Google’s Ngram Viewer年,似乎这个词在19世纪初被普遍使用,直到20世纪80年代才被忽略,可能在D&D得到普及之后:

Google Ngram Viewer: "scry" from 1700 to 2008

所以我不能说我反对把jimfb称之为“幻想词”,特别是考虑到我听到这种想象的想象。

猜你在找的React相关文章