fix(core): invoke structured Signal listeners with runtime args before bound args#2987
fix(core): invoke structured Signal listeners with runtime args before bound args#2987cptbtptpbcptdtptp wants to merge 2 commits into
Conversation
…e bound args Previously `Signal._addListener` applied bound arguments first and runtime signal args last, producing `method(...boundArgs, ...signalArgs)`. This made the event object's position shift with the number of bound arguments and diverged from the DOM / Cocos `(event, customEventData)` convention. Flip the order so the listener method receives runtime args first and bound args last: `method(...signalArgs, ...boundArgs)`. The event object now always sits at index 0, making migrated Cocos scripts with `(event, customData)` signatures work without rewrites. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Add three test cases verifying that runtime signal args are passed before bound args: - "runtime args precede bound args" — full ordering with two of each. - "event object stays at index 0 regardless of bound args count" — position invariant of the conventional event argument. - "once: runtime + bound args order preserved" — same guarantee for once-style listeners. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (2)
WalkthroughSignal's structured binding listener changes argument order: runtime signal arguments now precede pre-resolved bound arguments when invoking target methods. Implementation, documentation, and test coverage are updated to reflect and validate this new invocation contract. ChangesSignal Argument Ordering for Structured Binding
Estimated code review effort🎯 2 (Simple) | ⏱️ ~8 minutes Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Tip 💬 Introducing Slack Agent: The best way for teams to turn conversations into code.Slack Agent is built on CodeRabbit's deep understanding of your code, so your team can collaborate across the entire SDLC without losing context.
Built for teams:
One agent for your entire SDLC. Right inside Slack. Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
GuoLei1990
left a comment
There was a problem hiding this comment.
总结
将 Signal 结构化绑定监听器的调用顺序从 method(...boundArgs, ...signalArgs) 修正为 method(...signalArgs, ...boundArgs),确保 event 对象始终在 index 0,与 DOM addEventListener / Cocos (event, customData) 约定对齐。
一行改动,三个新测试覆盖 arg ordering、event at index 0 不变量、once() 行为一致性。
无新问题,LGTM。
GuoLei1990
left a comment
There was a problem hiding this comment.
总结
将 Signal 结构化绑定监听器的调用顺序从 method(...boundArgs, ...signalArgs) 修正为 method(...signalArgs, ...boundArgs),使事件对象始终在参数列表第 0 位,与 DOM/Cocos 约定对齐。测试覆盖了顺序验证、事件对象位置不变性、once() 对等性。
修复方向正确,实现最小化。无新问题,可以合并。
GuoLei1990
left a comment
There was a problem hiding this comment.
总结
将 structured binding 的参数顺序从 (...args, ...signalArgs) 改为 (...signalArgs, ...args),与 DOM/Cocos (event, customData) 惯例对齐。修复正确,3 个新测试验证了参数顺序不变量。
问题
[P2] Signal.ts:175 — 更改前代码把 bound args 放前面,这意味着已有用 structured binding 并依赖旧顺序的代码(method(boundArg, event))会 silently break。PR 描述里没有 migration guide。建议在 CHANGELOG 或 Breaking Changes 里明确标注旧语义。
无阻塞问题,LGTM。
GuoLei1990
left a comment
There was a problem hiding this comment.
总结
逻辑修复正确,与 DOM addEventListener 和 Cocos EventTarget 的 (event, customData) 惯例对齐,测试覆盖完整(arg ordering + event index 0 invariant + once parity)。
问题
[P1] Breaking change 需在 CHANGELOG 中标注
使用 structured binding 且传了 bound args 的现有代码(signal.on(component, 'handler', boundArg1)),升级后 handler 收到的参数顺序从 (boundArg1, ...signalArgs) 变为 (...signalArgs, boundArg1)。dev/2.0 允许 breaking changes,但需在 changelog 或 PR 描述中明确标注:旧顺序 (bound, ...runtime) → 新顺序 (...runtime, bound),以便用户迁移。
Summary
method(...boundArgs, ...signalArgs)tomethod(...signalArgs, ...boundArgs), so the event object always sits at index 0.(event, customData)convention — migrated Cocos scripts work without rewriting parameter order.Background
Cherry-picked from
b16d8b5d7on fix/shaderlab.Test plan
Signal.test.tscases: arg ordering, event index 0 invariant,once()parity🤖 Generated with Claude Code
Summary by CodeRabbit
Bug Fixes
Tests