gpt4 book ai didi

reactjs - React的 `scryRenderedDOMComponentsWithClass`方法名从何而来?

转载 作者:行者123 更新时间:2023-12-03 12:59:43 24 4
gpt4 key购买 nike

在测试 React 组件时,我阅读了文档并发现了 scryRenderedDOMComponentsWithClass。我无法理解这个组件的功能,因为它无法发音,所以我不明白它是如何命名映射到它正在做什么的心理模型的。 (有许多相关名称,例如 scryRenderedDOMComponentsWithTag。)

此方法名称的 scry 部分指的是什么?可怕的?疾走?这个名字想说明什么概念?

最佳答案

简短回答

在这种情况下,“Scry”仅意味着“找到全部”。请参阅this comment on ReactTestUtils.scryRenderedComponentsWithClass 。它是一个单词,而不是缩写,它的发音类似于“cry”,但开头有一个“s”。

更长(而且更 Nerd )的答案

在同一文件的其他位置,您将看到 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:
http://www.dandwiki.com/wiki/SRD:Scrying
http://www.dandwiki.com/wiki/SRD3e:Scry_Skill
https://en.wikipedia.org/wiki/Scrying

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 称其为“幻想词”,特别是考虑到当我听到它时我的想象力会浮现出那种图像。

关于reactjs - React的 `scryRenderedDOMComponentsWithClass`方法名从何而来?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33742899/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com