For an optimal user and developer experience, storing state in local storage is often a must.

In this lesson you will learn:

  • Using onSnapshot to get notified about new snapshots
  • Storing snapshots in local storage
  • Restore a state tree from local storage
  • Verifying whether a snapshot conforms to a model using Model.is(...)
let initialState = {
items: [
{
name: "LEGO Mindstorms EV3",
price: 349.95,
image: "https://images-na.ssl-images-amazon.com/images/I/71CpQw%2BufNL._SL1000_.jpg"
},
{
name: "Miracles - C.S. Lewis",
price: 12.91,
image:
"https://images-na.ssl-images-amazon.com/images/I/51a7xaMpneL._SX329_BO1,204,203,200_.jpg"
}
]
} if (localStorage.getItem("wishlistapp")) {
const json = JSON.parse(localStorage.getItem("wishlistapp"))
if (WishList.is(json)) initialState = json // check whether the structure is changed or not
} const wishList = WishList.create(initialState)

// if the snapshot changed, add to the localstorage
onSnapshot(wishList, snapshot => {
localStorage.setItem("wishlistapp", JSON.stringify(snapshot))
})

[MST] Store Store in Local Storage的更多相关文章

  1. html5本地存储 local storage

    HTML5 web storage, a better local storage than cookies. With HTML5, web pages can store data locally ...

  2. HTML5本地存储(Local Storage) 的前世今生

    长久以来本地存储能力一直是桌面应用区别于Web应用的一个主要优势.对于桌面应用(或者原生应用),操作系统一般都提供了一个抽象层用来帮助应用程序保存其本地数据 例如(用户配置信息或者运行时状态等). 常 ...

  3. 每日技术总结:promise,express route,评分,local storage商品浏览历史,

    最近正在用Vue做一个电商项目.利用工作前后空隙时间. 1.promise的使用 点这里 如何在实际项目中使用Promise 2. Express Route 前后端传参的两种方法 (1)req.pa ...

  4. Ionic2学习笔记(8):Local Storage& SQLite

    作者:Grey 原文地址: http://www.cnblogs.com/greyzeng/p/5557947.html              Ionic2可以有两种方式来存储数据,Local S ...

  5. Web持久化存储Web SQL、Local Storage、Cookies(常用)

    在浏览器客户端记录一些信息,有三种常用的Web数据持久化存储的方式,分别是Web SQL.Local Storage.Cookies. Web SQL 作为html5本地数据库,可通过一套API来操纵 ...

  6. cookie ,session Storage, local storage

    先来定义: cookie:是网站为了标识用户身份存储在本地终端的数据,其数据始终在APP请求中存在,会在服务器和浏览器中来回传递 数据大小不超过4k, 可以设置有效期,过了有效期自动删除 sessio ...

  7. Session,Cookie 和local storage的区别

    以前从没有听说过local storage, 在网上查了一些资料,得到如下结论 从存储位置看,分为服务器端存储和客户端存储两种 服务器端: session 浏览器端: cookie, localSto ...

  8. 关于local storage及session storage 应用问题

    H5- storage 可以在不同页面内进行数据传递数据信息,保证了数据传输不许后台交互即可在前端部分自我实现,以下为local storage 应用个人简析: * localStorage * se ...

  9. 关于local storage 和 session storage以及cookie 区别简析

    session storage 和local storage 都是存储在客户端的浏览器内: 一:关于COOKIE 的缺陷 * Cookie的问题 * 数据存储都是以明文(未加密)方式进行存储 * 安全 ...

随机推荐

  1. ASP.NET-未解决的问题

    001.((FormsIdentity)User.Identity).Ticket.UserData 用ASP.NET后台格式化成json数据后传回去的数据有&quot这样的符号 002.HT ...

  2. POJ——T1679 The Unique MST

    http://poj.org/problem?id=1679 Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 30120   ...

  3. 复习昨天的,继续过Hard题目

      # Title Editorial Acceptance Difficulty Frequency   . 65 Valid Number     12.6% Hard    . 126 Word ...

  4. Struts(19)Struts集成

    Struts2 MVC架构 模型视图控制器(Model View Controller)或MVC,MVC是俗称.是一种软件设计模式,用于开发Web应用程序.模型 - 视图 - 控制器模式是由下面三个部 ...

  5. POJ-1785-Binary Search Heap Construction(笛卡尔树)

    Description Read the statement of problem G for the definitions concerning trees. In the following w ...

  6. jQuery中focusin()和focus()、find()和children()的差别

    jQuery中focus()和focusin().focus()和children()的差别 focus()和focusin() focus()和focusin()的差别在于focusin()支持事件 ...

  7. pip安装selenium时提示Unknown or unsupported command 'install'

    安装流程: 1.安装Python34 2.安装pip 下载setuptoos并安装,然后输入:easy_install pip 然后 配置path:C:\Python34\Scripts 3安装sel ...

  8. swift算法手记-7

    @IBAction func compute(sender: AnyObject) { // 19*x^7-31*x^5+16*x^2+7*x-90=0 // newton迭代法求一元方程的解,最大求 ...

  9. vuex3

    以下是一个表示“单向数据流”理念的极简示意: 但是,当我们的应用遇到多个组件共享状态时,单向数据流的简洁性很容易被破坏: 多个视图依赖于同一状态. 来自不同视图的行为需要变更同一状态. 这就是 Vue ...

  10. Mysql实战45讲 05讲深入浅出索引(下)极客时间 读书笔记

    极客时间 Mysql实战45讲 04讲深入浅出索引(下)极客时间 笔记体会: 回表:回到主键索引树搜索的过程,称为回表覆盖索引:某索引已经覆盖了查询需求,称为覆盖索引,例如:select ID fro ...