What does « dehydrate » and « rehydrate » stand for in Fluxible?

后端 未结 3 1147
故里飘歌
故里飘歌 2020-12-23 02:22

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 under

3条回答
  •  旧时难觅i
    2020-12-23 02:46

    Dehydrate is another word for serialize and Rehydrate means deserialize.

    Inflating == (re)hydrating == deserialization

    So the line of code serializes a state of router and assign the object to window.app which is accessible from client

    Update

    Example of how can serialisation be used:

    Assume we have a user object and want to keep a reference of currently logged in user between requests. We can serialize the user by simply taking its id and save it into session. That would be serialisation or dehydration of user object. To hydrate or deserialize we simply take the id from session, find our user in DB and fill in the user object again. The purpose here is to keep memory footprint as low as possible.

    In one of the examples of fluxible the dehydrate function simply returns current state name and the hydrate function takes the state name as an argument and set it as current state. I think that the full states objects are available on the client as well as the server. So since you don't need to send the entire state you only send state's name. The function to dehydrate is as simple as

    State.dehydrate = function(){
        return this.currentStateName;
    }
    

提交回复
热议问题