{"expireTime":9007200821600205000,"key":"gatsby-plugin-mdx-entire-payload-28b4234a1dbe67e5a594411f8360cccb-","val":{"mdast":{"type":"root","children":[{"type":"paragraph","children":[{"type":"text","value":"A Message bundles up all of the information surrounding a request and response from the api.\nIt holds all the information that you would need to both make requests and render their responses\nwhen they come back. ","position":{"start":{"line":2,"column":1,"offset":1},"end":{"line":4,"column":22,"offset":213},"indent":[1,1]}},{"type":"emphasis","children":[{"type":"text","value":"Most often you shouldn't need to worry about creating messages. They are constructed for you\nby the RequestHock.","position":{"start":{"line":4,"column":23,"offset":214},"end":{"line":5,"column":20,"offset":326},"indent":[1]}}],"position":{"start":{"line":4,"column":22,"offset":213},"end":{"line":5,"column":21,"offset":327},"indent":[1]}}],"position":{"start":{"line":2,"column":1,"offset":1},"end":{"line":5,"column":21,"offset":327},"indent":[1,1,1]}},{"type":"paragraph","children":[{"type":"emphasis","children":[{"type":"text","value":"Tip: Messages only change when Enty does so are safe to compare with ===. This is great for render\nperformance.","position":{"start":{"line":7,"column":2,"offset":330},"end":{"line":8,"column":13,"offset":441},"indent":[1]}}],"position":{"start":{"line":7,"column":1,"offset":329},"end":{"line":8,"column":14,"offset":442},"indent":[1]}}],"position":{"start":{"line":7,"column":1,"offset":329},"end":{"line":8,"column":14,"offset":442},"indent":[1]}},{"type":"code","lang":"js","meta":null,"value":"class Message<RequestState> {\n    response: mixed;\n    requestState: RequestState;\n    requestError: mixed;\n    onRequest(payload: mixed) => Promise<mixed>;\n    get(key: string, notFoundValue?: mixed) => mixed;\n    getIn(keyPath: Array<string>, notFoundValue?: mixed) => mixed;\n    updateRequestState(updater: RequestState => RequestState) => Message;\n    toEmpty(): Message<Empty>;\n    toFetching(): Message<Fetching>;\n    toRefetching(response: mixed): Message<Refetching>;\n    toSuccess(response: mixed): Message<Success>;\n    toError(requestError: mixed): Message<Error>;\n}","position":{"start":{"line":12,"column":1,"offset":446},"end":{"line":27,"column":4,"offset":1033},"indent":[1,1,1,1,1,1,1,1,1,1,1,1,1,1,1]}},{"type":"heading","depth":2,"children":[{"type":"text","value":"Properties","position":{"start":{"line":29,"column":4,"offset":1038},"end":{"line":29,"column":14,"offset":1048},"indent":[]}}],"position":{"start":{"line":29,"column":1,"offset":1035},"end":{"line":29,"column":14,"offset":1048},"indent":[]}},{"type":"heading","depth":3,"children":[{"type":"text","value":".response","position":{"start":{"line":31,"column":5,"offset":1054},"end":{"line":31,"column":14,"offset":1063},"indent":[]}}],"position":{"start":{"line":31,"column":1,"offset":1050},"end":{"line":31,"column":14,"offset":1063},"indent":[]}},{"type":"paragraph","children":[{"type":"strong","children":[{"type":"text","value":"type:","position":{"start":{"line":32,"column":3,"offset":1066},"end":{"line":32,"column":8,"offset":1071},"indent":[]}}],"position":{"start":{"line":32,"column":1,"offset":1064},"end":{"line":32,"column":10,"offset":1073},"indent":[]}},{"type":"text","value":" ","position":{"start":{"line":32,"column":10,"offset":1073},"end":{"line":32,"column":11,"offset":1074},"indent":[]}},{"type":"inlineCode","value":"mixed","position":{"start":{"line":32,"column":11,"offset":1074},"end":{"line":32,"column":18,"offset":1081},"indent":[]}},{"type":"text","value":"  ","position":{"start":{"line":32,"column":18,"offset":1081},"end":{"line":32,"column":20,"offset":1083},"indent":[]}}],"position":{"start":{"line":32,"column":1,"offset":1064},"end":{"line":32,"column":20,"offset":1083},"indent":[]}},{"type":"paragraph","children":[{"type":"text","value":"Once a request has returned the data can be found in response. ","position":{"start":{"line":34,"column":1,"offset":1085},"end":{"line":34,"column":64,"offset":1148},"indent":[]}},{"type":"emphasis","children":[{"type":"text","value":"Note: you can also use\n","position":{"start":{"line":34,"column":65,"offset":1149},"end":{"line":35,"column":1,"offset":1172},"indent":[1]}},{"type":"link","title":null,"url":"#get","children":[{"type":"text","value":"get()","position":{"start":{"line":35,"column":2,"offset":1173},"end":{"line":35,"column":7,"offset":1178},"indent":[]}}],"position":{"start":{"line":35,"column":1,"offset":1172},"end":{"line":35,"column":14,"offset":1185},"indent":[]}},{"type":"text","value":" and ","position":{"start":{"line":35,"column":14,"offset":1185},"end":{"line":35,"column":19,"offset":1190},"indent":[]}},{"type":"link","title":null,"url":"#getin","children":[{"type":"text","value":"getIn()","position":{"start":{"line":35,"column":20,"offset":1191},"end":{"line":35,"column":27,"offset":1198},"indent":[]}}],"position":{"start":{"line":35,"column":19,"offset":1190},"end":{"line":35,"column":36,"offset":1207},"indent":[]}},{"type":"text","value":" for easy access to the response object.","position":{"start":{"line":35,"column":36,"offset":1207},"end":{"line":35,"column":76,"offset":1247},"indent":[]}}],"position":{"start":{"line":34,"column":64,"offset":1148},"end":{"line":35,"column":77,"offset":1248},"indent":[1]}}],"position":{"start":{"line":34,"column":1,"offset":1085},"end":{"line":35,"column":77,"offset":1248},"indent":[1]}},{"type":"heading","depth":3,"children":[{"type":"text","value":".requestState","position":{"start":{"line":37,"column":5,"offset":1254},"end":{"line":37,"column":18,"offset":1267},"indent":[]}}],"position":{"start":{"line":37,"column":1,"offset":1250},"end":{"line":37,"column":18,"offset":1267},"indent":[]}},{"type":"paragraph","children":[{"type":"strong","children":[{"type":"text","value":"type:","position":{"start":{"line":38,"column":3,"offset":1270},"end":{"line":38,"column":8,"offset":1275},"indent":[]}}],"position":{"start":{"line":38,"column":1,"offset":1268},"end":{"line":38,"column":10,"offset":1277},"indent":[]}},{"type":"text","value":" ","position":{"start":{"line":38,"column":10,"offset":1277},"end":{"line":38,"column":11,"offset":1278},"indent":[]}},{"type":"linkReference","identifier":"requeststate","label":"RequestState","referenceType":"shortcut","children":[{"type":"text","value":"RequestState","position":{"start":{"line":38,"column":12,"offset":1279},"end":{"line":38,"column":24,"offset":1291},"indent":[]}}],"position":{"start":{"line":38,"column":11,"offset":1278},"end":{"line":38,"column":25,"offset":1292},"indent":[]}}],"position":{"start":{"line":38,"column":1,"offset":1268},"end":{"line":38,"column":25,"offset":1292},"indent":[]}},{"type":"paragraph","children":[{"type":"text","value":"Holds a variant that represents the current state of the request. By using a variant\nEnty lets you declaratively represent how your component should render under each state of the \nrequest. ","position":{"start":{"line":40,"column":1,"offset":1294},"end":{"line":42,"column":10,"offset":1484},"indent":[1,1]}},{"type":"emphasis","children":[{"type":"text","value":"See ","position":{"start":{"line":42,"column":11,"offset":1485},"end":{"line":42,"column":15,"offset":1489},"indent":[]}},{"type":"linkReference","identifier":"requeststate","label":"RequestState","referenceType":"shortcut","children":[{"type":"text","value":"RequestState","position":{"start":{"line":42,"column":16,"offset":1490},"end":{"line":42,"column":28,"offset":1502},"indent":[]}}],"position":{"start":{"line":42,"column":15,"offset":1489},"end":{"line":42,"column":29,"offset":1503},"indent":[]}},{"type":"text","value":" for more details on variants.","position":{"start":{"line":42,"column":29,"offset":1503},"end":{"line":42,"column":59,"offset":1533},"indent":[]}}],"position":{"start":{"line":42,"column":10,"offset":1484},"end":{"line":42,"column":60,"offset":1534},"indent":[]}}],"position":{"start":{"line":40,"column":1,"offset":1294},"end":{"line":42,"column":60,"offset":1534},"indent":[1,1]}},{"type":"code","lang":"jsx","meta":null,"value":"function UserAvatar(props) {\n    const {userMessage} = props;\n    return userMessage.requestState\n        .fetchingMap(() => <Loader/>)\n        .refetchingMap(() => <Loader/>)\n        .successMap(() => <img src={userMessage.get('avatar')} />)\n        .errorMap(() => <span>user not found :(</span>)\n        .value();\n}","position":{"start":{"line":44,"column":1,"offset":1536},"end":{"line":54,"column":4,"offset":1865},"indent":[1,1,1,1,1,1,1,1,1,1]}},{"type":"heading","depth":3,"children":[{"type":"text","value":".requestError","position":{"start":{"line":56,"column":5,"offset":1871},"end":{"line":56,"column":18,"offset":1884},"indent":[]}}],"position":{"start":{"line":56,"column":1,"offset":1867},"end":{"line":56,"column":18,"offset":1884},"indent":[]}},{"type":"paragraph","children":[{"type":"strong","children":[{"type":"text","value":"type:","position":{"start":{"line":57,"column":3,"offset":1887},"end":{"line":57,"column":8,"offset":1892},"indent":[]}}],"position":{"start":{"line":57,"column":1,"offset":1885},"end":{"line":57,"column":10,"offset":1894},"indent":[]}},{"type":"text","value":" ","position":{"start":{"line":57,"column":10,"offset":1894},"end":{"line":57,"column":11,"offset":1895},"indent":[]}},{"type":"inlineCode","value":"mixed","position":{"start":{"line":57,"column":11,"offset":1895},"end":{"line":57,"column":18,"offset":1902},"indent":[]}},{"type":"text","value":"  ","position":{"start":{"line":57,"column":18,"offset":1902},"end":{"line":57,"column":20,"offset":1904},"indent":[]}}],"position":{"start":{"line":57,"column":1,"offset":1885},"end":{"line":57,"column":20,"offset":1904},"indent":[]}},{"type":"paragraph","children":[{"type":"text","value":"If the request promise rejects Enty will rerender the view with the caught error in \n","position":{"start":{"line":59,"column":1,"offset":1906},"end":{"line":60,"column":1,"offset":1991},"indent":[1]}},{"type":"inlineCode","value":"requestError","position":{"start":{"line":60,"column":1,"offset":1991},"end":{"line":60,"column":15,"offset":2005},"indent":[]}},{"type":"text","value":". ","position":{"start":{"line":60,"column":15,"offset":2005},"end":{"line":60,"column":17,"offset":2007},"indent":[]}},{"type":"emphasis","children":[{"type":"text","value":"The requestState will also be in an error state.","position":{"start":{"line":60,"column":18,"offset":2008},"end":{"line":60,"column":66,"offset":2056},"indent":[]}}],"position":{"start":{"line":60,"column":17,"offset":2007},"end":{"line":60,"column":67,"offset":2057},"indent":[]}}],"position":{"start":{"line":59,"column":1,"offset":1906},"end":{"line":60,"column":67,"offset":2057},"indent":[1]}},{"type":"code","lang":"jsx","meta":null,"value":"function UserAvatar(props) {\n    const {userMessage} = props;\n    return userMessage.requestState\n        .successMap(() => <img src={userMessage.get('avatar')} />)\n        .errorMap(() => <span>{userMessage.requestError.message}</span>)\n        .value();\n}","position":{"start":{"line":62,"column":1,"offset":2059},"end":{"line":70,"column":4,"offset":2327},"indent":[1,1,1,1,1,1,1,1]}},{"type":"heading","depth":2,"children":[{"type":"text","value":"Methods","position":{"start":{"line":73,"column":4,"offset":2333},"end":{"line":73,"column":11,"offset":2340},"indent":[]}}],"position":{"start":{"line":73,"column":1,"offset":2330},"end":{"line":73,"column":11,"offset":2340},"indent":[]}},{"type":"heading","depth":3,"children":[{"type":"text","value":".onRequest()","position":{"start":{"line":75,"column":5,"offset":2346},"end":{"line":75,"column":17,"offset":2358},"indent":[]}}],"position":{"start":{"line":75,"column":1,"offset":2342},"end":{"line":75,"column":17,"offset":2358},"indent":[]}},{"type":"paragraph","children":[{"type":"strong","children":[{"type":"text","value":"type:","position":{"start":{"line":76,"column":3,"offset":2361},"end":{"line":76,"column":8,"offset":2366},"indent":[]}}],"position":{"start":{"line":76,"column":1,"offset":2359},"end":{"line":76,"column":10,"offset":2368},"indent":[]}},{"type":"text","value":" ","position":{"start":{"line":76,"column":10,"offset":2368},"end":{"line":76,"column":11,"offset":2369},"indent":[]}},{"type":"inlineCode","value":"(payload) => Promise<mixed>","position":{"start":{"line":76,"column":11,"offset":2369},"end":{"line":76,"column":40,"offset":2398},"indent":[]}},{"type":"text","value":"  ","position":{"start":{"line":76,"column":40,"offset":2398},"end":{"line":76,"column":42,"offset":2400},"indent":[]}}],"position":{"start":{"line":76,"column":1,"offset":2359},"end":{"line":76,"column":42,"offset":2400},"indent":[]}},{"type":"paragraph","children":[{"type":"text","value":"A promise returning function that will dispatch the corresponding api function. ","position":{"start":{"line":78,"column":1,"offset":2402},"end":{"line":78,"column":81,"offset":2482},"indent":[]}},{"type":"emphasis","children":[{"type":"text","value":"This is most often \nused to trigger user initiated requests like save or remove.","position":{"start":{"line":78,"column":82,"offset":2483},"end":{"line":79,"column":61,"offset":2563},"indent":[1]}}],"position":{"start":{"line":78,"column":81,"offset":2482},"end":{"line":79,"column":62,"offset":2564},"indent":[1]}}],"position":{"start":{"line":78,"column":1,"offset":2402},"end":{"line":79,"column":62,"offset":2564},"indent":[1]}},{"type":"paragraph","children":[{"type":"emphasis","children":[{"type":"text","value":"Note: The payload given to onRquest is not passed through ","position":{"start":{"line":81,"column":2,"offset":2567},"end":{"line":81,"column":60,"offset":2625},"indent":[]}},{"type":"inlineCode","value":"config.payloadCreator","position":{"start":{"line":81,"column":60,"offset":2625},"end":{"line":81,"column":83,"offset":2648},"indent":[]}}],"position":{"start":{"line":81,"column":1,"offset":2566},"end":{"line":81,"column":84,"offset":2649},"indent":[]}}],"position":{"start":{"line":81,"column":1,"offset":2566},"end":{"line":81,"column":84,"offset":2649},"indent":[]}},{"type":"code","lang":"jsx","meta":null,"value":"function Button({message}) {\n    return <button onClick={() => message.onRequest()}>Save</button>;\n}\n\nconst SaveUserButton = SaveUserHoc({name: 'message'})(Button);","position":{"start":{"line":83,"column":1,"offset":2651},"end":{"line":89,"column":4,"offset":2826},"indent":[1,1,1,1,1,1]}},{"type":"heading","depth":3,"children":[{"type":"text","value":".get()","position":{"start":{"line":92,"column":5,"offset":2833},"end":{"line":92,"column":11,"offset":2839},"indent":[]}}],"position":{"start":{"line":92,"column":1,"offset":2829},"end":{"line":92,"column":11,"offset":2839},"indent":[]}},{"type":"paragraph","children":[{"type":"strong","children":[{"type":"text","value":"type:","position":{"start":{"line":93,"column":3,"offset":2842},"end":{"line":93,"column":8,"offset":2847},"indent":[]}}],"position":{"start":{"line":93,"column":1,"offset":2840},"end":{"line":93,"column":10,"offset":2849},"indent":[]}},{"type":"text","value":" ","position":{"start":{"line":93,"column":10,"offset":2849},"end":{"line":93,"column":11,"offset":2850},"indent":[]}},{"type":"inlineCode","value":"(key: string, notFoundValue?: mixed) => mixed","position":{"start":{"line":93,"column":11,"offset":2850},"end":{"line":93,"column":58,"offset":2897},"indent":[]}},{"type":"text","value":"  ","position":{"start":{"line":93,"column":58,"offset":2897},"end":{"line":93,"column":60,"offset":2899},"indent":[]}}],"position":{"start":{"line":93,"column":1,"offset":2840},"end":{"line":93,"column":60,"offset":2899},"indent":[]}},{"type":"paragraph","children":[{"type":"text","value":"Returns the value from ","position":{"start":{"line":95,"column":1,"offset":2901},"end":{"line":95,"column":24,"offset":2924},"indent":[]}},{"type":"inlineCode","value":"message.response.${key}","position":{"start":{"line":95,"column":24,"offset":2924},"end":{"line":95,"column":49,"offset":2949},"indent":[]}},{"type":"text","value":". If nothing is found it will return ","position":{"start":{"line":95,"column":49,"offset":2949},"end":{"line":95,"column":86,"offset":2986},"indent":[]}},{"type":"inlineCode","value":"defaultValue","position":{"start":{"line":95,"column":86,"offset":2986},"end":{"line":95,"column":100,"offset":3000},"indent":[]}},{"type":"text","value":"\nif provided.","position":{"start":{"line":95,"column":100,"offset":3000},"end":{"line":96,"column":13,"offset":3013},"indent":[1]}}],"position":{"start":{"line":95,"column":1,"offset":2901},"end":{"line":96,"column":13,"offset":3013},"indent":[1]}},{"type":"code","lang":"js","meta":null,"value":"const score = message.get('score', 0);","position":{"start":{"line":98,"column":1,"offset":3015},"end":{"line":100,"column":4,"offset":3063},"indent":[1,1]}},{"type":"heading","depth":3,"children":[{"type":"text","value":".getIn()","position":{"start":{"line":102,"column":5,"offset":3069},"end":{"line":102,"column":13,"offset":3077},"indent":[]}}],"position":{"start":{"line":102,"column":1,"offset":3065},"end":{"line":102,"column":13,"offset":3077},"indent":[]}},{"type":"paragraph","children":[{"type":"strong","children":[{"type":"text","value":"type:","position":{"start":{"line":103,"column":3,"offset":3080},"end":{"line":103,"column":8,"offset":3085},"indent":[]}}],"position":{"start":{"line":103,"column":1,"offset":3078},"end":{"line":103,"column":10,"offset":3087},"indent":[]}},{"type":"text","value":" ","position":{"start":{"line":103,"column":10,"offset":3087},"end":{"line":103,"column":11,"offset":3088},"indent":[]}},{"type":"inlineCode","value":"(keyPath: Array<string>, notFoundValue?: mixed) => mixed","position":{"start":{"line":103,"column":11,"offset":3088},"end":{"line":103,"column":69,"offset":3146},"indent":[]}},{"type":"text","value":"  ","position":{"start":{"line":103,"column":69,"offset":3146},"end":{"line":103,"column":71,"offset":3148},"indent":[]}}],"position":{"start":{"line":103,"column":1,"offset":3078},"end":{"line":103,"column":71,"offset":3148},"indent":[]}},{"type":"paragraph","children":[{"type":"text","value":"Returns the value at the provided key pathm or defaultValue if nothing is found.","position":{"start":{"line":105,"column":1,"offset":3150},"end":{"line":105,"column":81,"offset":3230},"indent":[]}}],"position":{"start":{"line":105,"column":1,"offset":3150},"end":{"line":105,"column":81,"offset":3230},"indent":[]}},{"type":"code","lang":"js","meta":null,"value":"const name = message.getIn(['user', 'name'], '-');","position":{"start":{"line":107,"column":1,"offset":3232},"end":{"line":109,"column":4,"offset":3292},"indent":[1,1]}},{"type":"heading","depth":3,"children":[{"type":"text","value":".updateRequestState()","position":{"start":{"line":112,"column":5,"offset":3299},"end":{"line":112,"column":26,"offset":3320},"indent":[]}}],"position":{"start":{"line":112,"column":1,"offset":3295},"end":{"line":112,"column":26,"offset":3320},"indent":[]}},{"type":"paragraph","children":[{"type":"strong","children":[{"type":"text","value":"type:","position":{"start":{"line":113,"column":3,"offset":3323},"end":{"line":113,"column":8,"offset":3328},"indent":[]}}],"position":{"start":{"line":113,"column":1,"offset":3321},"end":{"line":113,"column":10,"offset":3330},"indent":[]}},{"type":"text","value":" ","position":{"start":{"line":113,"column":10,"offset":3330},"end":{"line":113,"column":11,"offset":3331},"indent":[]}},{"type":"inlineCode","value":"(updater: RequestState => RequestState) => Message","position":{"start":{"line":113,"column":11,"offset":3331},"end":{"line":113,"column":63,"offset":3383},"indent":[]}},{"type":"text","value":"  ","position":{"start":{"line":113,"column":63,"offset":3383},"end":{"line":113,"column":65,"offset":3385},"indent":[]}}],"position":{"start":{"line":113,"column":1,"offset":3321},"end":{"line":113,"column":65,"offset":3385},"indent":[]}},{"type":"paragraph","children":[{"type":"text","value":"Update the requestState via a function. Allows the user to change a request state and pass the \nmessage on. ","position":{"start":{"line":115,"column":1,"offset":3387},"end":{"line":116,"column":13,"offset":3495},"indent":[1]}},{"type":"emphasis","children":[{"type":"text","value":"Can be used to force the rendering of a specific branch.","position":{"start":{"line":116,"column":14,"offset":3496},"end":{"line":116,"column":70,"offset":3552},"indent":[]}}],"position":{"start":{"line":116,"column":13,"offset":3495},"end":{"line":116,"column":71,"offset":3553},"indent":[]}}],"position":{"start":{"line":115,"column":1,"offset":3387},"end":{"line":116,"column":71,"offset":3553},"indent":[1]}},{"type":"code","lang":"js","meta":null,"value":"message.updateRequestState(requestState => requestState.toError());","position":{"start":{"line":118,"column":1,"offset":3555},"end":{"line":120,"column":4,"offset":3632},"indent":[1,1]}},{"type":"heading","depth":3,"children":[{"type":"text","value":".toEmpty()","position":{"start":{"line":122,"column":5,"offset":3638},"end":{"line":122,"column":15,"offset":3648},"indent":[]}}],"position":{"start":{"line":122,"column":1,"offset":3634},"end":{"line":122,"column":15,"offset":3648},"indent":[]}},{"type":"paragraph","children":[{"type":"strong","children":[{"type":"text","value":"type:","position":{"start":{"line":123,"column":3,"offset":3651},"end":{"line":123,"column":8,"offset":3656},"indent":[]}}],"position":{"start":{"line":123,"column":1,"offset":3649},"end":{"line":123,"column":10,"offset":3658},"indent":[]}},{"type":"text","value":" ","position":{"start":{"line":123,"column":10,"offset":3658},"end":{"line":123,"column":11,"offset":3659},"indent":[]}},{"type":"inlineCode","value":"() => Message<Empty>;","position":{"start":{"line":123,"column":11,"offset":3659},"end":{"line":123,"column":34,"offset":3682},"indent":[]}}],"position":{"start":{"line":123,"column":1,"offset":3649},"end":{"line":123,"column":34,"offset":3682},"indent":[]}},{"type":"paragraph","children":[{"type":"text","value":"Cast the current message to a new Message with an empty requestState.","position":{"start":{"line":125,"column":1,"offset":3684},"end":{"line":125,"column":70,"offset":3753},"indent":[]}}],"position":{"start":{"line":125,"column":1,"offset":3684},"end":{"line":125,"column":70,"offset":3753},"indent":[]}},{"type":"heading","depth":3,"children":[{"type":"text","value":".toFetching()","position":{"start":{"line":128,"column":5,"offset":3760},"end":{"line":128,"column":18,"offset":3773},"indent":[]}}],"position":{"start":{"line":128,"column":1,"offset":3756},"end":{"line":128,"column":18,"offset":3773},"indent":[]}},{"type":"paragraph","children":[{"type":"strong","children":[{"type":"text","value":"type:","position":{"start":{"line":129,"column":3,"offset":3776},"end":{"line":129,"column":8,"offset":3781},"indent":[]}}],"position":{"start":{"line":129,"column":1,"offset":3774},"end":{"line":129,"column":10,"offset":3783},"indent":[]}},{"type":"text","value":" ","position":{"start":{"line":129,"column":10,"offset":3783},"end":{"line":129,"column":11,"offset":3784},"indent":[]}},{"type":"inlineCode","value":"() => Message<Fetching>;","position":{"start":{"line":129,"column":11,"offset":3784},"end":{"line":129,"column":37,"offset":3810},"indent":[]}}],"position":{"start":{"line":129,"column":1,"offset":3774},"end":{"line":129,"column":37,"offset":3810},"indent":[]}},{"type":"paragraph","children":[{"type":"text","value":"Cast the current message to a new Message with a fetching requestState.","position":{"start":{"line":131,"column":1,"offset":3812},"end":{"line":131,"column":72,"offset":3883},"indent":[]}}],"position":{"start":{"line":131,"column":1,"offset":3812},"end":{"line":131,"column":72,"offset":3883},"indent":[]}},{"type":"heading","depth":3,"children":[{"type":"text","value":".toRefetching()","position":{"start":{"line":134,"column":5,"offset":3890},"end":{"line":134,"column":20,"offset":3905},"indent":[]}}],"position":{"start":{"line":134,"column":1,"offset":3886},"end":{"line":134,"column":20,"offset":3905},"indent":[]}},{"type":"paragraph","children":[{"type":"strong","children":[{"type":"text","value":"type:","position":{"start":{"line":135,"column":3,"offset":3908},"end":{"line":135,"column":8,"offset":3913},"indent":[]}}],"position":{"start":{"line":135,"column":1,"offset":3906},"end":{"line":135,"column":10,"offset":3915},"indent":[]}},{"type":"text","value":" ","position":{"start":{"line":135,"column":10,"offset":3915},"end":{"line":135,"column":11,"offset":3916},"indent":[]}},{"type":"inlineCode","value":"(response: mixed) => Message<Refetching>;","position":{"start":{"line":135,"column":11,"offset":3916},"end":{"line":135,"column":54,"offset":3959},"indent":[]}}],"position":{"start":{"line":135,"column":1,"offset":3906},"end":{"line":135,"column":54,"offset":3959},"indent":[]}},{"type":"paragraph","children":[{"type":"text","value":"Cast the current message to a new Message with a refetching requestState.","position":{"start":{"line":137,"column":1,"offset":3961},"end":{"line":137,"column":74,"offset":4034},"indent":[]}}],"position":{"start":{"line":137,"column":1,"offset":3961},"end":{"line":137,"column":74,"offset":4034},"indent":[]}},{"type":"heading","depth":3,"children":[{"type":"text","value":".toSuccess()","position":{"start":{"line":140,"column":5,"offset":4041},"end":{"line":140,"column":17,"offset":4053},"indent":[]}}],"position":{"start":{"line":140,"column":1,"offset":4037},"end":{"line":140,"column":17,"offset":4053},"indent":[]}},{"type":"paragraph","children":[{"type":"strong","children":[{"type":"text","value":"type:","position":{"start":{"line":141,"column":3,"offset":4056},"end":{"line":141,"column":8,"offset":4061},"indent":[]}}],"position":{"start":{"line":141,"column":1,"offset":4054},"end":{"line":141,"column":10,"offset":4063},"indent":[]}},{"type":"text","value":" ","position":{"start":{"line":141,"column":10,"offset":4063},"end":{"line":141,"column":11,"offset":4064},"indent":[]}},{"type":"inlineCode","value":"(response: mixed) => Message<Success>;","position":{"start":{"line":141,"column":11,"offset":4064},"end":{"line":141,"column":51,"offset":4104},"indent":[]}}],"position":{"start":{"line":141,"column":1,"offset":4054},"end":{"line":141,"column":51,"offset":4104},"indent":[]}},{"type":"paragraph","children":[{"type":"text","value":"Cast the current message to a new Message with a success requestState.","position":{"start":{"line":143,"column":1,"offset":4106},"end":{"line":143,"column":71,"offset":4176},"indent":[]}}],"position":{"start":{"line":143,"column":1,"offset":4106},"end":{"line":143,"column":71,"offset":4176},"indent":[]}},{"type":"heading","depth":3,"children":[{"type":"text","value":".toError()","position":{"start":{"line":146,"column":5,"offset":4183},"end":{"line":146,"column":15,"offset":4193},"indent":[]}}],"position":{"start":{"line":146,"column":1,"offset":4179},"end":{"line":146,"column":15,"offset":4193},"indent":[]}},{"type":"paragraph","children":[{"type":"strong","children":[{"type":"text","value":"type:","position":{"start":{"line":147,"column":3,"offset":4196},"end":{"line":147,"column":8,"offset":4201},"indent":[]}}],"position":{"start":{"line":147,"column":1,"offset":4194},"end":{"line":147,"column":10,"offset":4203},"indent":[]}},{"type":"text","value":" ","position":{"start":{"line":147,"column":10,"offset":4203},"end":{"line":147,"column":11,"offset":4204},"indent":[]}},{"type":"inlineCode","value":"(requestError: mixed) => Message<Error>;","position":{"start":{"line":147,"column":11,"offset":4204},"end":{"line":147,"column":53,"offset":4246},"indent":[]}}],"position":{"start":{"line":147,"column":1,"offset":4194},"end":{"line":147,"column":53,"offset":4246},"indent":[]}},{"type":"paragraph","children":[{"type":"text","value":"Cast the current message to a new Message with an error requestState.","position":{"start":{"line":149,"column":1,"offset":4248},"end":{"line":149,"column":70,"offset":4317},"indent":[]}}],"position":{"start":{"line":149,"column":1,"offset":4248},"end":{"line":149,"column":70,"offset":4317},"indent":[]}},{"type":"heading","depth":2,"children":[{"type":"text","value":"Static Unit Functions","position":{"start":{"line":154,"column":4,"offset":4325},"end":{"line":154,"column":25,"offset":4346},"indent":[]}}],"position":{"start":{"line":154,"column":1,"offset":4322},"end":{"line":154,"column":25,"offset":4346},"indent":[]}},{"type":"paragraph","children":[{"type":"text","value":"Enty provides a series of helper functions to let you construct messages\nin various request states. These are mostly used for providing default states.","position":{"start":{"line":155,"column":1,"offset":4347},"end":{"line":156,"column":79,"offset":4498},"indent":[1]}}],"position":{"start":{"line":155,"column":1,"offset":4347},"end":{"line":156,"column":79,"offset":4498},"indent":[1]}},{"type":"heading","depth":3,"children":[{"type":"text","value":"Message.empty()","position":{"start":{"line":158,"column":5,"offset":4504},"end":{"line":158,"column":20,"offset":4519},"indent":[]}}],"position":{"start":{"line":158,"column":1,"offset":4500},"end":{"line":158,"column":20,"offset":4519},"indent":[]}},{"type":"paragraph","children":[{"type":"strong","children":[{"type":"text","value":"type:","position":{"start":{"line":159,"column":3,"offset":4522},"end":{"line":159,"column":8,"offset":4527},"indent":[]}}],"position":{"start":{"line":159,"column":1,"offset":4520},"end":{"line":159,"column":10,"offset":4529},"indent":[]}},{"type":"text","value":" ","position":{"start":{"line":159,"column":10,"offset":4529},"end":{"line":159,"column":11,"offset":4530},"indent":[]}},{"type":"inlineCode","value":"(MessageProps = {}) => Message<EmptyState>","position":{"start":{"line":159,"column":11,"offset":4530},"end":{"line":159,"column":55,"offset":4574},"indent":[]}}],"position":{"start":{"line":159,"column":1,"offset":4520},"end":{"line":159,"column":55,"offset":4574},"indent":[]}},{"type":"paragraph","children":[{"type":"text","value":"Create a Message in an Empty state.","position":{"start":{"line":161,"column":1,"offset":4576},"end":{"line":161,"column":36,"offset":4611},"indent":[]}}],"position":{"start":{"line":161,"column":1,"offset":4576},"end":{"line":161,"column":36,"offset":4611},"indent":[]}},{"type":"heading","depth":3,"children":[{"type":"text","value":"Message.fetching()","position":{"start":{"line":163,"column":5,"offset":4617},"end":{"line":163,"column":23,"offset":4635},"indent":[]}}],"position":{"start":{"line":163,"column":1,"offset":4613},"end":{"line":163,"column":23,"offset":4635},"indent":[]}},{"type":"paragraph","children":[{"type":"strong","children":[{"type":"text","value":"type:","position":{"start":{"line":164,"column":3,"offset":4638},"end":{"line":164,"column":8,"offset":4643},"indent":[]}}],"position":{"start":{"line":164,"column":1,"offset":4636},"end":{"line":164,"column":10,"offset":4645},"indent":[]}},{"type":"text","value":" ","position":{"start":{"line":164,"column":10,"offset":4645},"end":{"line":164,"column":11,"offset":4646},"indent":[]}},{"type":"inlineCode","value":"(MessageProps = {}) => Message<FetchingState>","position":{"start":{"line":164,"column":11,"offset":4646},"end":{"line":164,"column":58,"offset":4693},"indent":[]}}],"position":{"start":{"line":164,"column":1,"offset":4636},"end":{"line":164,"column":58,"offset":4693},"indent":[]}},{"type":"paragraph","children":[{"type":"text","value":"Create a message in a Fetching state","position":{"start":{"line":166,"column":1,"offset":4695},"end":{"line":166,"column":37,"offset":4731},"indent":[]}}],"position":{"start":{"line":166,"column":1,"offset":4695},"end":{"line":166,"column":37,"offset":4731},"indent":[]}},{"type":"heading","depth":3,"children":[{"type":"text","value":"Message.refetching()","position":{"start":{"line":168,"column":5,"offset":4737},"end":{"line":168,"column":25,"offset":4757},"indent":[]}}],"position":{"start":{"line":168,"column":1,"offset":4733},"end":{"line":168,"column":25,"offset":4757},"indent":[]}},{"type":"paragraph","children":[{"type":"strong","children":[{"type":"text","value":"type:","position":{"start":{"line":169,"column":3,"offset":4760},"end":{"line":169,"column":8,"offset":4765},"indent":[]}}],"position":{"start":{"line":169,"column":1,"offset":4758},"end":{"line":169,"column":10,"offset":4767},"indent":[]}},{"type":"text","value":" ","position":{"start":{"line":169,"column":10,"offset":4767},"end":{"line":169,"column":11,"offset":4768},"indent":[]}},{"type":"inlineCode","value":"(response: mixed, rest?: MessageProps = {}) => Message<RefetchingState>","position":{"start":{"line":169,"column":11,"offset":4768},"end":{"line":169,"column":84,"offset":4841},"indent":[]}}],"position":{"start":{"line":169,"column":1,"offset":4758},"end":{"line":169,"column":84,"offset":4841},"indent":[]}},{"type":"paragraph","children":[{"type":"text","value":"Create a message in a Refetching state","position":{"start":{"line":171,"column":1,"offset":4843},"end":{"line":171,"column":39,"offset":4881},"indent":[]}}],"position":{"start":{"line":171,"column":1,"offset":4843},"end":{"line":171,"column":39,"offset":4881},"indent":[]}},{"type":"heading","depth":3,"children":[{"type":"text","value":"Message.success()","position":{"start":{"line":173,"column":5,"offset":4887},"end":{"line":173,"column":22,"offset":4904},"indent":[]}}],"position":{"start":{"line":173,"column":1,"offset":4883},"end":{"line":173,"column":22,"offset":4904},"indent":[]}},{"type":"paragraph","children":[{"type":"strong","children":[{"type":"text","value":"type:","position":{"start":{"line":174,"column":3,"offset":4907},"end":{"line":174,"column":8,"offset":4912},"indent":[]}}],"position":{"start":{"line":174,"column":1,"offset":4905},"end":{"line":174,"column":10,"offset":4914},"indent":[]}},{"type":"text","value":" ","position":{"start":{"line":174,"column":10,"offset":4914},"end":{"line":174,"column":11,"offset":4915},"indent":[]}},{"type":"inlineCode","value":"(response: mixed, rest?: MessageProps = {}) => Message<SuccessState>","position":{"start":{"line":174,"column":11,"offset":4915},"end":{"line":174,"column":81,"offset":4985},"indent":[]}}],"position":{"start":{"line":174,"column":1,"offset":4905},"end":{"line":174,"column":81,"offset":4985},"indent":[]}},{"type":"paragraph","children":[{"type":"text","value":"Create a message in a Success state","position":{"start":{"line":176,"column":1,"offset":4987},"end":{"line":176,"column":36,"offset":5022},"indent":[]}}],"position":{"start":{"line":176,"column":1,"offset":4987},"end":{"line":176,"column":36,"offset":5022},"indent":[]}},{"type":"heading","depth":3,"children":[{"type":"text","value":"Message.error()","position":{"start":{"line":179,"column":5,"offset":5029},"end":{"line":179,"column":20,"offset":5044},"indent":[]}}],"position":{"start":{"line":179,"column":1,"offset":5025},"end":{"line":179,"column":20,"offset":5044},"indent":[]}},{"type":"paragraph","children":[{"type":"strong","children":[{"type":"text","value":"type:","position":{"start":{"line":180,"column":3,"offset":5047},"end":{"line":180,"column":8,"offset":5052},"indent":[]}}],"position":{"start":{"line":180,"column":1,"offset":5045},"end":{"line":180,"column":10,"offset":5054},"indent":[]}},{"type":"text","value":" ","position":{"start":{"line":180,"column":10,"offset":5054},"end":{"line":180,"column":11,"offset":5055},"indent":[]}},{"type":"inlineCode","value":"(requestError: mixed, rest?: MessageProps = {}) => Message<ErrorState>","position":{"start":{"line":180,"column":11,"offset":5055},"end":{"line":180,"column":83,"offset":5127},"indent":[]}}],"position":{"start":{"line":180,"column":1,"offset":5045},"end":{"line":180,"column":83,"offset":5127},"indent":[]}},{"type":"paragraph","children":[{"type":"text","value":"Create a message in an Error state.","position":{"start":{"line":182,"column":1,"offset":5129},"end":{"line":182,"column":36,"offset":5164},"indent":[]}}],"position":{"start":{"line":182,"column":1,"offset":5129},"end":{"line":182,"column":36,"offset":5164},"indent":[]}},{"type":"definition","identifier":"requeststate","label":"RequestState","title":null,"url":"./RequestState","position":{"start":{"line":185,"column":1,"offset":5167},"end":{"line":185,"column":31,"offset":5197},"indent":[]}},{"type":"export","value":"export const _frontmatter = {\"id\":\"Message\",\"title\":\"Message\",\"group\":\"React Enty\"}","position":{"start":{"line":188,"column":1,"offset":5200},"end":{"line":188,"column":84,"offset":5283},"indent":[]}}],"position":{"start":{"line":1,"column":1,"offset":0},"end":{"line":188,"column":84,"offset":5283}}},"scopeImports":["import React from 'react'"],"scopeIdentifiers":["React"],"body":"function _extends() { _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }\n\nfunction _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }\n\nfunction _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }\n\n/* @jsx mdx */\nvar _frontmatter = {\n  \"id\": \"Message\",\n  \"title\": \"Message\",\n  \"group\": \"React Enty\"\n};\n\nvar makeShortcode = function makeShortcode(name) {\n  return function MDXDefaultShortcode(props) {\n    console.warn(\"Component \" + name + \" was not imported, exported, or provided by MDXProvider as global scope\");\n    return mdx(\"div\", props);\n  };\n};\n\nvar layoutProps = {\n  _frontmatter: _frontmatter\n};\nvar MDXLayout = \"wrapper\";\nreturn function MDXContent(_ref) {\n  var components = _ref.components,\n      props = _objectWithoutProperties(_ref, [\"components\"]);\n\n  return mdx(MDXLayout, _extends({}, layoutProps, props, {\n    components: components,\n    mdxType: \"MDXLayout\"\n  }), mdx(\"p\", null, \"A Message bundles up all of the information surrounding a request and response from the api.\\nIt holds all the information that you would need to both make requests and render their responses\\nwhen they come back. \", mdx(\"em\", {\n    parentName: \"p\"\n  }, \"Most often you shouldn't need to worry about creating messages. They are constructed for you\\nby the RequestHock.\")), mdx(\"p\", null, mdx(\"em\", {\n    parentName: \"p\"\n  }, \"Tip: Messages only change when Enty does so are safe to compare with ===. This is great for render\\nperformance.\")), mdx(\"pre\", null, mdx(\"code\", _extends({\n    parentName: \"pre\"\n  }, {\n    \"className\": \"language-js\"\n  }), \"class Message<RequestState> {\\n    response: mixed;\\n    requestState: RequestState;\\n    requestError: mixed;\\n    onRequest(payload: mixed) => Promise<mixed>;\\n    get(key: string, notFoundValue?: mixed) => mixed;\\n    getIn(keyPath: Array<string>, notFoundValue?: mixed) => mixed;\\n    updateRequestState(updater: RequestState => RequestState) => Message;\\n    toEmpty(): Message<Empty>;\\n    toFetching(): Message<Fetching>;\\n    toRefetching(response: mixed): Message<Refetching>;\\n    toSuccess(response: mixed): Message<Success>;\\n    toError(requestError: mixed): Message<Error>;\\n}\\n\")), mdx(\"h2\", null, \"Properties\"), mdx(\"h3\", null, \".response\"), mdx(\"p\", null, mdx(\"strong\", {\n    parentName: \"p\"\n  }, \"type:\"), \" \", mdx(\"inlineCode\", {\n    parentName: \"p\"\n  }, \"mixed\"), \"  \"), mdx(\"p\", null, \"Once a request has returned the data can be found in response. \", mdx(\"em\", {\n    parentName: \"p\"\n  }, \"Note: you can also use\\n\", mdx(\"a\", _extends({\n    parentName: \"em\"\n  }, {\n    \"href\": \"#get\"\n  }), \"get()\"), \" and \", mdx(\"a\", _extends({\n    parentName: \"em\"\n  }, {\n    \"href\": \"#getin\"\n  }), \"getIn()\"), \" for easy access to the response object.\")), mdx(\"h3\", null, \".requestState\"), mdx(\"p\", null, mdx(\"strong\", {\n    parentName: \"p\"\n  }, \"type:\"), \" \", mdx(\"a\", _extends({\n    parentName: \"p\"\n  }, {\n    \"href\": \"./RequestState\"\n  }), \"RequestState\")), mdx(\"p\", null, \"Holds a variant that represents the current state of the request. By using a variant\\nEnty lets you declaratively represent how your component should render under each state of the\\nrequest. \", mdx(\"em\", {\n    parentName: \"p\"\n  }, \"See \", mdx(\"a\", _extends({\n    parentName: \"em\"\n  }, {\n    \"href\": \"./RequestState\"\n  }), \"RequestState\"), \" for more details on variants.\")), mdx(\"pre\", null, mdx(\"code\", _extends({\n    parentName: \"pre\"\n  }, {\n    \"className\": \"language-jsx\"\n  }), \"function UserAvatar(props) {\\n    const {userMessage} = props;\\n    return userMessage.requestState\\n        .fetchingMap(() => <Loader/>)\\n        .refetchingMap(() => <Loader/>)\\n        .successMap(() => <img src={userMessage.get('avatar')} />)\\n        .errorMap(() => <span>user not found :(</span>)\\n        .value();\\n}\\n\")), mdx(\"h3\", null, \".requestError\"), mdx(\"p\", null, mdx(\"strong\", {\n    parentName: \"p\"\n  }, \"type:\"), \" \", mdx(\"inlineCode\", {\n    parentName: \"p\"\n  }, \"mixed\"), \"  \"), mdx(\"p\", null, \"If the request promise rejects Enty will rerender the view with the caught error in\\n\", mdx(\"inlineCode\", {\n    parentName: \"p\"\n  }, \"requestError\"), \". \", mdx(\"em\", {\n    parentName: \"p\"\n  }, \"The requestState will also be in an error state.\")), mdx(\"pre\", null, mdx(\"code\", _extends({\n    parentName: \"pre\"\n  }, {\n    \"className\": \"language-jsx\"\n  }), \"function UserAvatar(props) {\\n    const {userMessage} = props;\\n    return userMessage.requestState\\n        .successMap(() => <img src={userMessage.get('avatar')} />)\\n        .errorMap(() => <span>{userMessage.requestError.message}</span>)\\n        .value();\\n}\\n\")), mdx(\"h2\", null, \"Methods\"), mdx(\"h3\", null, \".onRequest()\"), mdx(\"p\", null, mdx(\"strong\", {\n    parentName: \"p\"\n  }, \"type:\"), \" \", mdx(\"inlineCode\", {\n    parentName: \"p\"\n  }, \"(payload) => Promise<mixed>\"), \"  \"), mdx(\"p\", null, \"A promise returning function that will dispatch the corresponding api function. \", mdx(\"em\", {\n    parentName: \"p\"\n  }, \"This is most often\\nused to trigger user initiated requests like save or remove.\")), mdx(\"p\", null, mdx(\"em\", {\n    parentName: \"p\"\n  }, \"Note: The payload given to onRquest is not passed through \", mdx(\"inlineCode\", {\n    parentName: \"em\"\n  }, \"config.payloadCreator\"))), mdx(\"pre\", null, mdx(\"code\", _extends({\n    parentName: \"pre\"\n  }, {\n    \"className\": \"language-jsx\"\n  }), \"function Button({message}) {\\n    return <button onClick={() => message.onRequest()}>Save</button>;\\n}\\n\\nconst SaveUserButton = SaveUserHoc({name: 'message'})(Button);\\n\")), mdx(\"h3\", null, \".get()\"), mdx(\"p\", null, mdx(\"strong\", {\n    parentName: \"p\"\n  }, \"type:\"), \" \", mdx(\"inlineCode\", {\n    parentName: \"p\"\n  }, \"(key: string, notFoundValue?: mixed) => mixed\"), \"  \"), mdx(\"p\", null, \"Returns the value from \", mdx(\"inlineCode\", {\n    parentName: \"p\"\n  }, \"message.response.${key}\"), \". If nothing is found it will return \", mdx(\"inlineCode\", {\n    parentName: \"p\"\n  }, \"defaultValue\"), \"\\nif provided.\"), mdx(\"pre\", null, mdx(\"code\", _extends({\n    parentName: \"pre\"\n  }, {\n    \"className\": \"language-js\"\n  }), \"const score = message.get('score', 0);\\n\")), mdx(\"h3\", null, \".getIn()\"), mdx(\"p\", null, mdx(\"strong\", {\n    parentName: \"p\"\n  }, \"type:\"), \" \", mdx(\"inlineCode\", {\n    parentName: \"p\"\n  }, \"(keyPath: Array<string>, notFoundValue?: mixed) => mixed\"), \"  \"), mdx(\"p\", null, \"Returns the value at the provided key pathm or defaultValue if nothing is found.\"), mdx(\"pre\", null, mdx(\"code\", _extends({\n    parentName: \"pre\"\n  }, {\n    \"className\": \"language-js\"\n  }), \"const name = message.getIn(['user', 'name'], '-');\\n\")), mdx(\"h3\", null, \".updateRequestState()\"), mdx(\"p\", null, mdx(\"strong\", {\n    parentName: \"p\"\n  }, \"type:\"), \" \", mdx(\"inlineCode\", {\n    parentName: \"p\"\n  }, \"(updater: RequestState => RequestState) => Message\"), \"  \"), mdx(\"p\", null, \"Update the requestState via a function. Allows the user to change a request state and pass the\\nmessage on. \", mdx(\"em\", {\n    parentName: \"p\"\n  }, \"Can be used to force the rendering of a specific branch.\")), mdx(\"pre\", null, mdx(\"code\", _extends({\n    parentName: \"pre\"\n  }, {\n    \"className\": \"language-js\"\n  }), \"message.updateRequestState(requestState => requestState.toError());\\n\")), mdx(\"h3\", null, \".toEmpty()\"), mdx(\"p\", null, mdx(\"strong\", {\n    parentName: \"p\"\n  }, \"type:\"), \" \", mdx(\"inlineCode\", {\n    parentName: \"p\"\n  }, \"() => Message<Empty>;\")), mdx(\"p\", null, \"Cast the current message to a new Message with an empty requestState.\"), mdx(\"h3\", null, \".toFetching()\"), mdx(\"p\", null, mdx(\"strong\", {\n    parentName: \"p\"\n  }, \"type:\"), \" \", mdx(\"inlineCode\", {\n    parentName: \"p\"\n  }, \"() => Message<Fetching>;\")), mdx(\"p\", null, \"Cast the current message to a new Message with a fetching requestState.\"), mdx(\"h3\", null, \".toRefetching()\"), mdx(\"p\", null, mdx(\"strong\", {\n    parentName: \"p\"\n  }, \"type:\"), \" \", mdx(\"inlineCode\", {\n    parentName: \"p\"\n  }, \"(response: mixed) => Message<Refetching>;\")), mdx(\"p\", null, \"Cast the current message to a new Message with a refetching requestState.\"), mdx(\"h3\", null, \".toSuccess()\"), mdx(\"p\", null, mdx(\"strong\", {\n    parentName: \"p\"\n  }, \"type:\"), \" \", mdx(\"inlineCode\", {\n    parentName: \"p\"\n  }, \"(response: mixed) => Message<Success>;\")), mdx(\"p\", null, \"Cast the current message to a new Message with a success requestState.\"), mdx(\"h3\", null, \".toError()\"), mdx(\"p\", null, mdx(\"strong\", {\n    parentName: \"p\"\n  }, \"type:\"), \" \", mdx(\"inlineCode\", {\n    parentName: \"p\"\n  }, \"(requestError: mixed) => Message<Error>;\")), mdx(\"p\", null, \"Cast the current message to a new Message with an error requestState.\"), mdx(\"h2\", null, \"Static Unit Functions\"), mdx(\"p\", null, \"Enty provides a series of helper functions to let you construct messages\\nin various request states. These are mostly used for providing default states.\"), mdx(\"h3\", null, \"Message.empty()\"), mdx(\"p\", null, mdx(\"strong\", {\n    parentName: \"p\"\n  }, \"type:\"), \" \", mdx(\"inlineCode\", {\n    parentName: \"p\"\n  }, \"(MessageProps = {}) => Message<EmptyState>\")), mdx(\"p\", null, \"Create a Message in an Empty state.\"), mdx(\"h3\", null, \"Message.fetching()\"), mdx(\"p\", null, mdx(\"strong\", {\n    parentName: \"p\"\n  }, \"type:\"), \" \", mdx(\"inlineCode\", {\n    parentName: \"p\"\n  }, \"(MessageProps = {}) => Message<FetchingState>\")), mdx(\"p\", null, \"Create a message in a Fetching state\"), mdx(\"h3\", null, \"Message.refetching()\"), mdx(\"p\", null, mdx(\"strong\", {\n    parentName: \"p\"\n  }, \"type:\"), \" \", mdx(\"inlineCode\", {\n    parentName: \"p\"\n  }, \"(response: mixed, rest?: MessageProps = {}) => Message<RefetchingState>\")), mdx(\"p\", null, \"Create a message in a Refetching state\"), mdx(\"h3\", null, \"Message.success()\"), mdx(\"p\", null, mdx(\"strong\", {\n    parentName: \"p\"\n  }, \"type:\"), \" \", mdx(\"inlineCode\", {\n    parentName: \"p\"\n  }, \"(response: mixed, rest?: MessageProps = {}) => Message<SuccessState>\")), mdx(\"p\", null, \"Create a message in a Success state\"), mdx(\"h3\", null, \"Message.error()\"), mdx(\"p\", null, mdx(\"strong\", {\n    parentName: \"p\"\n  }, \"type:\"), \" \", mdx(\"inlineCode\", {\n    parentName: \"p\"\n  }, \"(requestError: mixed, rest?: MessageProps = {}) => Message<ErrorState>\")), mdx(\"p\", null, \"Create a message in an Error state.\"));\n}\n;\nMDXContent.isMDXComponent = true;","rawMDXOutput":"/* @jsx mdx */\nimport { mdx } from '@mdx-js/react';\n/* @jsx mdx */\n\nexport const _frontmatter = {\n  \"id\": \"Message\",\n  \"title\": \"Message\",\n  \"group\": \"React Enty\"\n};\nconst makeShortcode = name => function MDXDefaultShortcode(props) {\n  console.warn(\"Component \" + name + \" was not imported, exported, or provided by MDXProvider as global scope\")\n  return <div {...props}/>\n};\n\nconst layoutProps = {\n  _frontmatter\n};\nconst MDXLayout = \"wrapper\"\nexport default function MDXContent({\n  components,\n  ...props\n}) {\n  return <MDXLayout {...layoutProps} {...props} components={components} mdxType=\"MDXLayout\">\n    <p>{`A Message bundles up all of the information surrounding a request and response from the api.\nIt holds all the information that you would need to both make requests and render their responses\nwhen they come back. `}<em parentName=\"p\">{`Most often you shouldn't need to worry about creating messages. They are constructed for you\nby the RequestHock.`}</em></p>\n    <p><em parentName=\"p\">{`Tip: Messages only change when Enty does so are safe to compare with ===. This is great for render\nperformance.`}</em></p>\n    <pre><code parentName=\"pre\" {...{\n        \"className\": \"language-js\"\n      }}>{`class Message<RequestState> {\n    response: mixed;\n    requestState: RequestState;\n    requestError: mixed;\n    onRequest(payload: mixed) => Promise<mixed>;\n    get(key: string, notFoundValue?: mixed) => mixed;\n    getIn(keyPath: Array<string>, notFoundValue?: mixed) => mixed;\n    updateRequestState(updater: RequestState => RequestState) => Message;\n    toEmpty(): Message<Empty>;\n    toFetching(): Message<Fetching>;\n    toRefetching(response: mixed): Message<Refetching>;\n    toSuccess(response: mixed): Message<Success>;\n    toError(requestError: mixed): Message<Error>;\n}\n`}</code></pre>\n    <h2>{`Properties`}</h2>\n    <h3>{`.response`}</h3>\n    <p><strong parentName=\"p\">{`type:`}</strong>{` `}<inlineCode parentName=\"p\">{`mixed`}</inlineCode>{`  `}</p>\n    <p>{`Once a request has returned the data can be found in response. `}<em parentName=\"p\">{`Note: you can also use\n`}<a parentName=\"em\" {...{\n          \"href\": \"#get\"\n        }}>{`get()`}</a>{` and `}<a parentName=\"em\" {...{\n          \"href\": \"#getin\"\n        }}>{`getIn()`}</a>{` for easy access to the response object.`}</em></p>\n    <h3>{`.requestState`}</h3>\n    <p><strong parentName=\"p\">{`type:`}</strong>{` `}<a parentName=\"p\" {...{\n        \"href\": \"./RequestState\"\n      }}>{`RequestState`}</a></p>\n    <p>{`Holds a variant that represents the current state of the request. By using a variant\nEnty lets you declaratively represent how your component should render under each state of the\nrequest. `}<em parentName=\"p\">{`See `}<a parentName=\"em\" {...{\n          \"href\": \"./RequestState\"\n        }}>{`RequestState`}</a>{` for more details on variants.`}</em></p>\n    <pre><code parentName=\"pre\" {...{\n        \"className\": \"language-jsx\"\n      }}>{`function UserAvatar(props) {\n    const {userMessage} = props;\n    return userMessage.requestState\n        .fetchingMap(() => <Loader/>)\n        .refetchingMap(() => <Loader/>)\n        .successMap(() => <img src={userMessage.get('avatar')} />)\n        .errorMap(() => <span>user not found :(</span>)\n        .value();\n}\n`}</code></pre>\n    <h3>{`.requestError`}</h3>\n    <p><strong parentName=\"p\">{`type:`}</strong>{` `}<inlineCode parentName=\"p\">{`mixed`}</inlineCode>{`  `}</p>\n    <p>{`If the request promise rejects Enty will rerender the view with the caught error in\n`}<inlineCode parentName=\"p\">{`requestError`}</inlineCode>{`. `}<em parentName=\"p\">{`The requestState will also be in an error state.`}</em></p>\n    <pre><code parentName=\"pre\" {...{\n        \"className\": \"language-jsx\"\n      }}>{`function UserAvatar(props) {\n    const {userMessage} = props;\n    return userMessage.requestState\n        .successMap(() => <img src={userMessage.get('avatar')} />)\n        .errorMap(() => <span>{userMessage.requestError.message}</span>)\n        .value();\n}\n`}</code></pre>\n    <h2>{`Methods`}</h2>\n    <h3>{`.onRequest()`}</h3>\n    <p><strong parentName=\"p\">{`type:`}</strong>{` `}<inlineCode parentName=\"p\">{`(payload) => Promise<mixed>`}</inlineCode>{`  `}</p>\n    <p>{`A promise returning function that will dispatch the corresponding api function. `}<em parentName=\"p\">{`This is most often\nused to trigger user initiated requests like save or remove.`}</em></p>\n    <p><em parentName=\"p\">{`Note: The payload given to onRquest is not passed through `}<inlineCode parentName=\"em\">{`config.payloadCreator`}</inlineCode></em></p>\n    <pre><code parentName=\"pre\" {...{\n        \"className\": \"language-jsx\"\n      }}>{`function Button({message}) {\n    return <button onClick={() => message.onRequest()}>Save</button>;\n}\n\nconst SaveUserButton = SaveUserHoc({name: 'message'})(Button);\n`}</code></pre>\n    <h3>{`.get()`}</h3>\n    <p><strong parentName=\"p\">{`type:`}</strong>{` `}<inlineCode parentName=\"p\">{`(key: string, notFoundValue?: mixed) => mixed`}</inlineCode>{`  `}</p>\n    <p>{`Returns the value from `}<inlineCode parentName=\"p\">{`message.response.\\${key}`}</inlineCode>{`. If nothing is found it will return `}<inlineCode parentName=\"p\">{`defaultValue`}</inlineCode>{`\nif provided.`}</p>\n    <pre><code parentName=\"pre\" {...{\n        \"className\": \"language-js\"\n      }}>{`const score = message.get('score', 0);\n`}</code></pre>\n    <h3>{`.getIn()`}</h3>\n    <p><strong parentName=\"p\">{`type:`}</strong>{` `}<inlineCode parentName=\"p\">{`(keyPath: Array<string>, notFoundValue?: mixed) => mixed`}</inlineCode>{`  `}</p>\n    <p>{`Returns the value at the provided key pathm or defaultValue if nothing is found.`}</p>\n    <pre><code parentName=\"pre\" {...{\n        \"className\": \"language-js\"\n      }}>{`const name = message.getIn(['user', 'name'], '-');\n`}</code></pre>\n    <h3>{`.updateRequestState()`}</h3>\n    <p><strong parentName=\"p\">{`type:`}</strong>{` `}<inlineCode parentName=\"p\">{`(updater: RequestState => RequestState) => Message`}</inlineCode>{`  `}</p>\n    <p>{`Update the requestState via a function. Allows the user to change a request state and pass the\nmessage on. `}<em parentName=\"p\">{`Can be used to force the rendering of a specific branch.`}</em></p>\n    <pre><code parentName=\"pre\" {...{\n        \"className\": \"language-js\"\n      }}>{`message.updateRequestState(requestState => requestState.toError());\n`}</code></pre>\n    <h3>{`.toEmpty()`}</h3>\n    <p><strong parentName=\"p\">{`type:`}</strong>{` `}<inlineCode parentName=\"p\">{`() => Message<Empty>;`}</inlineCode></p>\n    <p>{`Cast the current message to a new Message with an empty requestState.`}</p>\n    <h3>{`.toFetching()`}</h3>\n    <p><strong parentName=\"p\">{`type:`}</strong>{` `}<inlineCode parentName=\"p\">{`() => Message<Fetching>;`}</inlineCode></p>\n    <p>{`Cast the current message to a new Message with a fetching requestState.`}</p>\n    <h3>{`.toRefetching()`}</h3>\n    <p><strong parentName=\"p\">{`type:`}</strong>{` `}<inlineCode parentName=\"p\">{`(response: mixed) => Message<Refetching>;`}</inlineCode></p>\n    <p>{`Cast the current message to a new Message with a refetching requestState.`}</p>\n    <h3>{`.toSuccess()`}</h3>\n    <p><strong parentName=\"p\">{`type:`}</strong>{` `}<inlineCode parentName=\"p\">{`(response: mixed) => Message<Success>;`}</inlineCode></p>\n    <p>{`Cast the current message to a new Message with a success requestState.`}</p>\n    <h3>{`.toError()`}</h3>\n    <p><strong parentName=\"p\">{`type:`}</strong>{` `}<inlineCode parentName=\"p\">{`(requestError: mixed) => Message<Error>;`}</inlineCode></p>\n    <p>{`Cast the current message to a new Message with an error requestState.`}</p>\n    <h2>{`Static Unit Functions`}</h2>\n    <p>{`Enty provides a series of helper functions to let you construct messages\nin various request states. These are mostly used for providing default states.`}</p>\n    <h3>{`Message.empty()`}</h3>\n    <p><strong parentName=\"p\">{`type:`}</strong>{` `}<inlineCode parentName=\"p\">{`(MessageProps = {}) => Message<EmptyState>`}</inlineCode></p>\n    <p>{`Create a Message in an Empty state.`}</p>\n    <h3>{`Message.fetching()`}</h3>\n    <p><strong parentName=\"p\">{`type:`}</strong>{` `}<inlineCode parentName=\"p\">{`(MessageProps = {}) => Message<FetchingState>`}</inlineCode></p>\n    <p>{`Create a message in a Fetching state`}</p>\n    <h3>{`Message.refetching()`}</h3>\n    <p><strong parentName=\"p\">{`type:`}</strong>{` `}<inlineCode parentName=\"p\">{`(response: mixed, rest?: MessageProps = {}) => Message<RefetchingState>`}</inlineCode></p>\n    <p>{`Create a message in a Refetching state`}</p>\n    <h3>{`Message.success()`}</h3>\n    <p><strong parentName=\"p\">{`type:`}</strong>{` `}<inlineCode parentName=\"p\">{`(response: mixed, rest?: MessageProps = {}) => Message<SuccessState>`}</inlineCode></p>\n    <p>{`Create a message in a Success state`}</p>\n    <h3>{`Message.error()`}</h3>\n    <p><strong parentName=\"p\">{`type:`}</strong>{` `}<inlineCode parentName=\"p\">{`(requestError: mixed, rest?: MessageProps = {}) => Message<ErrorState>`}</inlineCode></p>\n    <p>{`Create a message in an Error state.`}</p>\n\n    </MDXLayout>;\n}\n\n;\nMDXContent.isMDXComponent = true;"}}