Fluxible中的“脱水"和“补水"代表什么? [英] What does « dehydrate » and « rehydrate » stand for in Fluxible?

查看:121
本文介绍了Fluxible中的“脱水"和“补水"代表什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个最小的应用程序,该应用程序可与易变性一起使用.几乎所有事情似乎都清楚了,但只有一件事:脱水和复水状态的概念.

I'm working on a minimal app which work with fluxible. Pretty much everything seems clear but one thing : the concept of dehydrate and rehydrated state.

我知道这是在客户端和服务器之间同步存储所需要的,但是我不知道为什么.这行对我来说还不清楚:

I've understood that it's what's needed to sync the store between the client and the server, but I don't know why. This line is very unclear to me :

 var exposed = 'window.App=' + serialize(app.dehydrate(context)) + ';';

在server.js中( https://github.com/yahoo/fluxible/tree/master/examples/react-router )

In server.js (https://github.com/yahoo/fluxible/tree/master/examples/react-router)

如果您能用更简单的词"来告诉我,我将不胜感激.

I would really appreciate if you could tell me in « simpler word » what it means.

推荐答案

在Fluxible上下文中,使应用程序脱水意味着将其状态提取为对象.为应用程序补水是使用同一对象在应用程序中重新注入状态.代表应用程序状态的对象应该可序列化,以便通过网络发送它.

In the context of Fluxible, dehydrating your application means extracting its state into an object. Rehydrating your app is using that same object to reinject state in your application. The object representing the state of your application should be serializable in order to send it over the network.

说我想在服务器上预渲染我的应用程序,将html提供给客户端,然后在客户端上重新渲染我的应用程序.如果我的应用仅包含静态数据,这将是微不足道的.但是,我的应用程序是有状态的:它会在初始渲染之前从我的API中检索数据并进行存储.通过提取我的应用程序在服务器上的状态,将其与HTML一起发送,然后将其重新注入客户端,可以避免对我的API发出两个请求.

Say I want to pre-render my app on the server, serve the html to the client, then re-render my app on the client. This would be trivial if my app only consisted of static data. However, my app is stateful: it retrieves data from my API before the initial render and stores it. By extracting the state of my app on the server, sending it along with the HTML, then reinjecting it on the client, I avoid making two requests to my API.

这篇关于Fluxible中的“脱水"和“补水"代表什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆