当前位置:网站首页>利用 VSCode 的代码模板提高 MobX 的编码效率
利用 VSCode 的代码模板提高 MobX 的编码效率
2022-06-11 12:53:00 【InfoQ】
前言
MobXMobXMobXUser SnippetsVSCode 的模板代码
forStatelessWidgetStatefulWidgetjsonStatefulWidgetAwesome Flutter Snippets statefulWname
"Stateful Widget": {
"prefix": "statefulW",
"body": [
"class ${1:name} extends StatefulWidget {",
" ${1:name}({Key? key}) : super(key: key);\n",
" @override",
" _${1:WidgetName}State createState() => _${1:WidgetName}State();",
"}\n",
"class _${1:index}State extends State<${1:index}> {",
" @override",
" Widget build(BuildContext context) {",
" return Container(",
" child: ${2:null},",
" );",
" }",
"}"
],
"description": "Create a Stateful widget"
},
${1:name}1name${1:xxx}${2:null}$0${2/./\u$0/}
自定义MobX 的状态代码模板
import 'package:mobx/mobx.dart';
part 'counter.g.dart';
class Counter = CounterBase with _$Counter;
abstract class CounterBase with Store {
@observable
int value = 0;
@action
void increment() {
value++;
}
}
- 导入
mobx插件:这个可以固定语句即可。
- 声明part:这里需要引用文件名,VSCode 提供了
TM_FILENAME和TM_FILENAME_BASE变量,其中TM_FILENAME是完整的文件名,TM_FILENAME_BASE不带后缀。这里我们可以使用不带后缀的文件名变量,然后加上.g.dart即可。
Observable状态类定义:这里我们可以使用变量来替换,然后光标定位到这个类名变量处,方便批量修改,即使用${1:name}$0形式。
@observable状态属性(包括初始值)和@action动作方法。这里我们使用其他变量即可。接下来就是依葫芦画瓢了,整个过程如下动图所示。
- 菜单入口:Code->Preferences->User Snippets;
- New Snippets:新建一个模板代码,输入名称后回车即可创建;
- 输入模板 json 串:支持一个模板中放置多个模板代码块,使用不同的键区分即可,然后保存。
- 在代码编辑窗口输入 json 串中的 prefix 字段指定的代码快捷前缀,选择或回车接口插入模板代码。
- 修改模板代码中的变量即可完成最终代码。

{
"Build Mobx Observables" : {
"prefix": "build mobx",
"scope": "dart",
"body": [
"import 'package:mobx/mobx.dart';\n",
"part '${TM_FILENAME_BASE}.g.dart';\n",
"class ${1:name}$0 = $1Base with _$$1;\n",
"abstract class $1Base with Store {",
" @observable",
" ${2:type} ${3:property} = ${4:initial};\n",
" @action",
" void ${5:actionname}() {\n",
" }",
"}",
]
}
}
总结

边栏推荐
- pip2pi和pypiserver及Apache在pip本地源配置中的应用实践
- On the continuing Life of Distributed Locks - - Distributed Locks Based on redis
- 关于uni-app 配置 APP 不显示顶部标题栏设置
- Another way to achieve family reunion, 2022 flagship projection nut j10s is planted with grass
- The end of an era! After ten years, Wu Enda's classic machine learning course closed its registration this month and launched a new course
- [background interaction] select to bind the data transferred in the background
- What scenarios can the member management system of the multi guest swimming pool achieve?
- [interface] view the interface path and check the interface
- 不谈赛道,不聊风口,开源数据库巨头Cassandra如何在国内讲好“新故事” | C位面对面
- tf.data(二) —— 并行化 tf.data.Dataset 生成器
猜你喜欢

Netstat command details

马斯克称自己不喜欢做CEO,更想做技术和设计;吴恩达的《机器学习》课程即将关闭注册|极客头条...

How can non-standard automation equipment manufacturing enterprises achieve rapid and accurate quotation with the help of ERP system?

Stone technology: R & D strength and excellent quality help upgrade the sweeping robot industry

微软再曝“丑闻”:在办公室看 VR 黄片,“HoloLens 之父”即将离职!

Seckill multi-level cache ----- product details page

Log management system, summary in multiple ways

Why are the current membership warehouse stores bursting out collectively?

Ways to double the summer performance of natatoriums

4K投影儀哪款性價比最高,當貝X3 Pro高亮128G存儲618值得看
随机推荐
不谈赛道,不聊风口,开源数据库巨头Cassandra如何在国内讲好“新故事” | C位面对面
DB2数据库重建及表数据迁移探讨研究
[background interaction] select to bind the data transferred in the background
QQ pulls up Alipay H5 payment function
How about Lenovo Xiaoxin 520? Which is more worth buying than dangbei D3x?
模态框关闭后清空模态框里选择的数据
Audio adaptation of openharmony Standard System Porting
Mctalk's entrepreneurial voice - erudition and discernment: be interested in socializing, and provide a "small and beautiful" space for old friends before and after retirement
Dbutil auxiliary class, manual commit transaction, metadata
PKI/TLS瑞士军刀之cfssl
场馆坪效这么低?关键在这两方面
2022 年,捕捉这 12 个数据和分析趋势!
Which 4K projector is the most cost-effective? When the Bay X3 Pro highlights the 128G storage 618, it is worth seeing
@Controller和RequestMapping如何解析的
Which brand of bone conduction Bluetooth headset is good? Five most popular bone conduction Bluetooth headsets
字节真的是宇宙尽头吗?
PADS使用之繪制原理圖
Add environment path
苹果将造搜索引擎?
【bug解决】上传图片后,取消这次上传 再次执行上传,上次的图片还存在