[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
题目 这个题的输入首先就是一棵树,我们考虑一下点分 我们对于每一个分治重心考虑一下跨过这个分治重心的连边情况 就是把当前分治区域内所有的点向距离分治重心最近的点连边 考虑一下这个算法的正确性,如果我们 ...
随机推荐
- UDP Linux编程(客户端&服务器端)
服务器端 服务器不用绑定地址,他只需要进行绑定相应的监听端口即可. #include <sys/types.h> #include <sys/socket.h> #includ ...
- laydate 监听日期切换
```` //日期范围 laydate.render({ elem: '#Time', range: "至", max: gitData() ,done: function(val ...
- ajax简单操作,验证用户名是否可以
分别使用get,post方法进行提交. 如果输入用户名为admin时,鼠标失去焦点,显示不可以. <!DOCTYPE html> <html lang="en"& ...
- Yocto tips (19): Yocto SDK Toolchian的使用
在使用之前须要先source env,导入各种环境变量(注意将路径变更成你自己的): source ../qt5_sdk/environment-setup-cortexa9hf-vfp-neon-p ...
- Android实现天气预报温度/气温折线趋势图
Android实现天气预报温度/气温折线趋势图 天气预报的APP应用中,难免会遇到绘制天气温度/气温,等关于数据趋势的折线或者曲线图,这类关于气温/温度的折线图,通常会有两条线.一条是高温线,一 ...
- GIS+=地理信息+容器技术(2)——Dockers技术介绍
-------------------------------------------------------------------------------------- Blog: http ...
- 使用Powershell 的获取别的机器WMI类失败解决方法!
有些时候须要连接多台机器去获取他们的类,可是有些时候我们发现计算机无法连接,这个时候怎么办呢? 请改动组策略中下面配置: 能够使用Gpmc.msc 进行以后.本地计算机策略--计算机配置--管理模板- ...
- web语义化理解
含义: Web语义化是指使用语义恰当的标签,使页面有良好的结构,页面元素有含义,能够让人和搜索引擎都容易理解. 为什么要web语义化?如今互联网都到了web2.0的时代了,HTML语言在不断的进化并发 ...
- HTML&CSS——网站注册页面
1.表单标签 所有需要提交到服务器端的表单项必须使用<form></form>括起来! form 标签属性: action,整个表单提交的位置(可以是一个页面,也可以是一个后 ...
- atom安装插件失败 latex
用atom写latex 链接 http://www.cnblogs.com/schaepher/p/5934184.html 但在gui下安装插件失败 按照以下步骤解决了 安装gitbash cd . ...