This diff refactors getDefaultTextMessageRules function in rules.react.js on web and native. Rather than storing defaultTextMessageRules in a variable, _memoize can be used.
Depends on D8873.
Differential D8871
[web][native] Refactor getDefaultTextMessageRules • patryk on Aug 19 2023, 3:38 AM. Authored by Tags None Referenced Files
Details
Diff Detail
Event TimelineComment Actions What's the point of this change? I'm not sure that this code is better than the original... it requires understanding _memoize, and the original code seemed clear enough. _memoize makes sense to use when we need to memoize multiple different calculations. In this case, we only need to cache one thing at a time, so I'm not sure it's useful. I could see an argument that we already need to understand _memoize to understand this file. But my intuition is that this diff doesn't really result in any meaningful improvements. Curious for other reviewers' takes. Comment Actions My primary motivation for this diff was to align with the rules.react.js style. We use _memoize for almost all variables/functions defined in this file. I felt that storing getDefaultTextMessageRules in a variable, instead of following this file convention, was making this piece of code somewhat outdated. While using _memoize might not lead to significant improvements, it does, in my opinion, present a better aesthetic. However, I'm open to other reviewers' perspectives and suggestions. Comment Actions Although this change on its own doesn't have important disadvantages, the following diff D8846 makes it worse. The consequence is that we're wasting memory because _memoize remembers the result of each computation, while we only care about the most recent one. So it's better to reintroduce the previous approach. Comment Actions Since _memoize can use too much memory, I'm abandoning this diff and leaving the previous approach. |