[MST] Describe Your Application Domain Using mobx-state-tree(MST) Models
In this lesson, we introduce the running example of this course, a wishlist app. We will take a look at the core of mobx-state-tree (MST), models. Models describe the shape of your state and perform type validation.
You will learn:
- Defining models using types.Model
- Instantiating models from JSON using Model.create
- Primitive types: types.string & types.number
- Type inference for primitive types
- types.array
- types.optional
- Composing models into a model tree
- Testing models using jest
To create a model:
import { types } from "mobx-state-tree"
export const WishListItem = types.model({
name: types.string,
price: types.number,
image: ""
})
export const WishList = types.model({
items: types.optional(types.array(WishListItem), [])
})
'types' is similar to React PropTypes.
Once model is created, then we can write tests to verify:
import { WishList, WishListItem } from "./WishList"
it("can create a instance of a model", () => {
const item = WishListItem.create({
name: "Chronicles of Narnia Box Set - C.S. Lewis",
price: 28.73
})
expect(item.price).toBe(28.73)
expect(item.image).toBe("")
})
it("can create a wishlist", () => {
const list = WishList.create({
items: [
{
name: "Chronicles of Narnia Box Set - C.S. Lewis",
price: 28.73
}
]
})
expect(list.items.length).toBe()
expect(list.items[].price).toBe(28.73)
})
[MST] Describe Your Application Domain Using mobx-state-tree(MST) Models的更多相关文章
- [MST] Create an Entry Form to Add Models to the State Tree
It is time to add new entries to the wishlist. We will achieve this by reusing forms and models we'v ...
- 应用程序域(Application Domain)
应用程序域为隔离正在运行的应用程序提供了一种灵活而安全的方法. 应用程序域通常由运行时宿主创建和操作. 有时,您可能希望应用程序以编程方式与应用程序域交互,例如想在不停止应用程序运行的情况下卸载某个组 ...
- 应用程序池和应用程序域的区别(Difference between application pool and application domain)
来自StackOverFlow: http://stackoverflow.com/questions/8486335/difference-between-an-application-domai ...
- 【AtCoder3611】Tree MST(点分治,最小生成树)
[AtCoder3611]Tree MST(点分治,最小生成树) 题面 AtCoder 洛谷 给定一棵\(n\)个节点的树,现有有一张完全图,两点\(x,y\)之间的边长为\(w[x]+w[y]+di ...
- BZOJ 1977: [BeiJing2010组队]次小生成树 Tree( MST + 树链剖分 + RMQ )
做一次MST, 枚举不在最小生成树上的每一条边(u,v), 然后加上这条边, 删掉(u,v)上的最大边(或严格次大边), 更新答案. 树链剖分然后ST维护最大值和严格次大值..倍增也是可以的... - ...
- 题解-AtCoder Code-Festival2017 Final-J Tree MST
Problem \(\mathrm{Code~Festival~2017~Final~J}\) 题意概要:一棵 \(n\) 个节点有点权边权的树.构建一张完全图,对于任意一对点 \((x,y)\),连 ...
- 最小生成树 (Minimum Spanning Tree,MST) --- Prim算法
本文链接:http://www.cnblogs.com/Ash-ly/p/5409904.html 普瑞姆(Prim)算法: 假设N = (V, {E})是连通网,TE是N上最小生成树边的集合,U是是 ...
- 最小生成树 (Minimum Spanning Tree,MST) --- Kruskal算法
本文链接:http://www.cnblogs.com/Ash-ly/p/5409265.html 引导问题: 假设要在N个城市之间建立通信联络网,则连通N个城市只需要N - 1条线路.这时,自然会考 ...
- 【AT3611】Tree MST
题目 这个题的输入首先就是一棵树,我们考虑一下点分 我们对于每一个分治重心考虑一下跨过这个分治重心的连边情况 就是把当前分治区域内所有的点向距离分治重心最近的点连边 考虑一下这个算法的正确性,如果我们 ...
随机推荐
- Vue -- 只弹一次的弹框
核心代码是 getCookie()部分,控制弹框的显示隐藏则在 created()中. <template> <div v-if="isShow"> < ...
- Unity的Json解析<二>–写Json文件
本文章由cartzhang编写,转载请注明出处. 所有权利保留. 文章链接:http://blog.csdn.net/cartzhang/article/details/50378805 作者:car ...
- SpringBoot下支付宝接口的使用
SpringBoot下支付宝接口的使用 前期准备: 参考之前写过的 支付宝接口引入servlet版本 Jar包引入: <!-- 支付宝 --> <dependency> < ...
- hive初体验
--创建表 create table t_order(id int,name string,phone string) row format delimited fields terminated b ...
- mybatis 按照条件查询
mybatis 按照条件查询 @Autowired private StudentMapper studentMapper; @Override public Map getStudentList(i ...
- 第十一章 Servlet MVC模式
内包含案例,基于jsp+servlet的:MVC模式计算器:MVC模式登陆 第十一章 Servlet MVC模式 模型-视图-控制器(model-view-controller),简称MVC.MVC是 ...
- Jquery-操作select下拉菜单
jQuery获取Select选择的Text和Value: 1. var checkText=jQuery("#select_id").find("option:selec ...
- ASP.NET-前台view返回model集合
有时操作列表的时候想一次提交一个model集合,这样后台controller直接接受后就可以直接进行操作了,不用使用js,比较方便,也体现了MVC的Binding模式的优势,方法如下: 准备: 1.两 ...
- Apache shiro 笔记整理之编程式授权
下面内容是在看了涛哥的<跟我一起学shiro> 和 视频<一头扎入进shiro> 后整理出来备忘和方便自己和其它人学习. 个人主页:http://www.itit123.cn/ ...
- oracle刚開始学习的人经常使用操作100问
oracle刚開始学习的人经常使用操作100问 1. Oracle安装完毕后的初始口令? internal/oracle sys/change_on_install system/manager ...