[MST] Store Store in Local Storage
For an optimal user and developer experience, storing state in local storage is often a must.
In this lesson you will learn:
- Using
onSnapshotto 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的更多相关文章
- html5本地存储 local storage
HTML5 web storage, a better local storage than cookies. With HTML5, web pages can store data locally ...
- HTML5本地存储(Local Storage) 的前世今生
长久以来本地存储能力一直是桌面应用区别于Web应用的一个主要优势.对于桌面应用(或者原生应用),操作系统一般都提供了一个抽象层用来帮助应用程序保存其本地数据 例如(用户配置信息或者运行时状态等). 常 ...
- 每日技术总结:promise,express route,评分,local storage商品浏览历史,
最近正在用Vue做一个电商项目.利用工作前后空隙时间. 1.promise的使用 点这里 如何在实际项目中使用Promise 2. Express Route 前后端传参的两种方法 (1)req.pa ...
- Ionic2学习笔记(8):Local Storage& SQLite
作者:Grey 原文地址: http://www.cnblogs.com/greyzeng/p/5557947.html Ionic2可以有两种方式来存储数据,Local S ...
- Web持久化存储Web SQL、Local Storage、Cookies(常用)
在浏览器客户端记录一些信息,有三种常用的Web数据持久化存储的方式,分别是Web SQL.Local Storage.Cookies. Web SQL 作为html5本地数据库,可通过一套API来操纵 ...
- cookie ,session Storage, local storage
先来定义: cookie:是网站为了标识用户身份存储在本地终端的数据,其数据始终在APP请求中存在,会在服务器和浏览器中来回传递 数据大小不超过4k, 可以设置有效期,过了有效期自动删除 sessio ...
- Session,Cookie 和local storage的区别
以前从没有听说过local storage, 在网上查了一些资料,得到如下结论 从存储位置看,分为服务器端存储和客户端存储两种 服务器端: session 浏览器端: cookie, localSto ...
- 关于local storage及session storage 应用问题
H5- storage 可以在不同页面内进行数据传递数据信息,保证了数据传输不许后台交互即可在前端部分自我实现,以下为local storage 应用个人简析: * localStorage * se ...
- 关于local storage 和 session storage以及cookie 区别简析
session storage 和local storage 都是存储在客户端的浏览器内: 一:关于COOKIE 的缺陷 * Cookie的问题 * 数据存储都是以明文(未加密)方式进行存储 * 安全 ...
随机推荐
- Swoole WebSoctet 使用 zlib 压缩之 PHP 与 pako.js
一些理论知识 先说一下deflate算法吧,deflate是zip压缩文件的默认算法, 其实deflate现在不光用在zip文件中, 在7z, xz等其他的压缩文件中都用, 实际上deflate只是一 ...
- Unity 常用常找的东西存放
本文章由cartzhang编写,转载请注明出处. 所有权利保留. 文章链接:http://blog.csdn.net/cartzhang/article/details/50483316 作者:car ...
- 20130910.Windows上安装和配置MongoDB
官方文档:http://docs.mongodb.org/manual/tutorial/ 1.下载软件 http://www.mongodb.org/downloads 2.解压 解压后进入bin目 ...
- Set&Map区别Array
Set&Map区别Array 在Set内部,两个NaN是相等.两个对象总是不相等的.可以用length来检测 四个操作方法: add(value):添加某个值,返回Set结构本身. delet ...
- JavaString库
String库 .length() 字符串的长度,一个字符串为空(空字符串对象)和null(不指向任何对象)是两个概念,中文字符和英文字符是一样的计数(一个中文是一个字符,一个英文字母是一个字符) . ...
- 一个build.xml实例
<?xml version="1.0"?> <project name="ssh" basedir="." default ...
- 揭秘Product Hunt怎样运用邮件崛起
Product Hunt正被硅谷热议,而大家谈论Product Hunt时,经常涉及邮件营销. Product Hunt由Ryan Hoover 在2013年11月创立.鼓舞人们发现和分享新产品的站点 ...
- m_Orchestrate learning system---十六、如何快速在一堆字符图标中找到所需
m_Orchestrate learning system---十六.如何快速在一堆字符图标中找到所需 一.总结 一句话总结:find查找字符 比如说找teacher feedback 的图标,可以多 ...
- hexo博客谷歌百度收录踩坑日记
title: hexo博客谷歌百度收录踩坑日记 toc: false date: 2018-04-17 00:09:38 百度收录文件验证 无论怎么把渲染关掉或者render_skip都说我的格式错误 ...
- Java基础——protected访问修饰符探讨
Java基础——protected访问修饰符探讨 根据官方说法:(如图) protected修饰符是可以修饰其他包中的子孙类的,但是我做了个实验,结果发现了一个有趣的现象! 具体请往下看: packa ...