You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

WebStorm如何为createSelector编写支持多参数的Live Template

WebStorm createSelector 多参数Live Template解决方案

最终配置

模板文本

export const $selectorName$ = createSelector($dependencies$, ($params$) => 
  $END$
)

变量配置

打开Live Template的变量编辑面板,按以下规则配置:

  • selectorName:无特殊表达式,按需输入选择器名称即可
  • dependencies:无特殊表达式,输入多个getter依赖,用逗号分隔即可
  • params:表达式填以下Groovy脚本,同时勾选对应「Skip if defined」选项,避免输入完依赖后还要手动跳转参数位置
    groovyScript("return _1.split(',').collect { it.trim().replaceFirst('get', '').uncapitalize() }.join(', ')", dependencies)
    

效果验证

输入依赖getThis, getThat, getSomethingElse时,箭头函数参数会自动生成this, that, somethingElse,单参数场景也能正常兼容。

内容的提问来源于stack exchange,提问作者Jonathan Tuzman

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.09.29 00:24:04