feat(loader): support $class refs and numeric SpecularMode in v2 scene#2994
Conversation
|
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 (1)
🚧 Files skipped from review as they are similar to previous changes (1)
WalkthroughAdds a ChangesClass reference resolution and schema updates
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 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)
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 |
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## dev/2.0 #2994 +/- ##
===========================================
- Coverage 78.19% 78.10% -0.10%
===========================================
Files 906 900 -6
Lines 99892 99255 -637
Branches 10194 10198 +4
===========================================
- Hits 78112 77521 -591
+ Misses 21610 21563 -47
- Partials 170 171 +1
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Add negative coverage for the shared _getRegisteredClass validator introduced alongside the $class sentinel: - $class: empty string, non-string, unregistered class name - $type: non-string (string-but-unregistered already covered) Also adds a positive parseProps case for $class so the value-level resolution path (not just call args) is covered.
Both v2 sentinel branches duplicated the same try/catch + Promise.reject template to bridge _getRegisteredClass's synchronous throw into the _resolveValue promise chain. Extract _resolveRegisteredClass as the sync-to-async adapter: - _getRegisteredClass keeps its core responsibility (lookup + validation), returning a class synchronously or throwing on invalid input. - _resolveRegisteredClass adapts that throw into Promise.reject so call sites can fold directly into the resolver chain. The naming split (get vs resolve) mirrors the sync vs async semantic boundary. Behavior is unchanged — all existing $type/$class negative tests continue to assert the same error messages.
GuoLei1990
left a comment
There was a problem hiding this comment.
总结
本轮 commit 213f387 完整实现了 _resolveRegisteredClass 抽取——_getRegisteredClass 保持同步 throw 签名,_resolveRegisteredClass 作为 sync-to-async 适配层,两处调用点均已简化。上轮唯一存活的 P2 已关闭,无新问题。
代码已可合并。
Summary
针对 v2 scene 格式的两处 loader 扩展,集中在
packages/loader。$classvalue sentinel(ReflectionParser)ReflectionParser._resolveValue新增{ $class: "ClassName" }解析分支,通过Loader.getClass拿到已注册的构造函数本身(不实例化),用于 factory 风格的方法调用,例如:{ "method": "addEffect", "args": [{ "$class": "BloomEffect" }] }$type的类查找逻辑抽成_getRegisteredClass(value, sentinel),统一加上「必须是非空字符串」和「类必须已注册」两层校验,$type与$class共用同一份错误信息和兜底CommonSchema.ts新增ClassRef接口与ComponentRef等其他 ref 形态对齐数值化
SpecularMode(SceneSchema)SpecularMode枚举从字符串"Sky"/"Custom"改为数字0/1,与 v2 scene 中其他枚举(FogMode、ShadowCascadesMode等)的数值化约定保持一致,序列化时体积更小、解析时无字符串比较Test plan
tests/src/loader/SceneFormatV2.test.ts:新增$class解析用例addEffect({ $class: "BloomEffect" })走parseCalls,断言生成的 effect 是BloomEffect实例且result.props正确写回SceneParser跑端到端,确认 component calls 中的$class参数能落到实际组件上tests/src/loader/SceneFormatV2.test.ts:新增SpecularMode数值断言(Sky === 0、Custom === 1)🤖 Generated with Claude Code
Summary by CodeRabbit
New Features
$classproperty for direct component/effect instantiation.Schema Updates
Tests
$classresolution, error cases, and scene parsing with effect instances.