{"componentChunkName":"component---src-components-api-layout-js","path":"/api/react-enty/message/","webpackCompilationHash":"","result":{"data":{"allFile":{"group":[{"fieldValue":"Enty","nodes":[{"childMdx":{"fields":{"slug":"api/enty/array-schema/"},"frontmatter":{"title":"Array Schema"},"headings":[{"value":"Params","depth":2},{"value":"shape","depth":3},{"value":"options.create","depth":3},{"value":"options.merge","depth":3},{"value":"Methods","depth":2},{"value":".normalize()","depth":3},{"value":".denormalize()","depth":3}]}},{"childMdx":{"fields":{"slug":"api/enty/composite-entity-schema/"},"frontmatter":{"title":"Composite Entity Schema"},"headings":[{"value":"Params","depth":2},{"value":"name","depth":3},{"value":"options.shape","depth":3},{"value":"options.compositeKeys","depth":3},{"value":"options.idAttribute","depth":3},{"value":"Methods","depth":2},{"value":".normalize()","depth":3},{"value":".denormalize()","depth":3}]}},{"childMdx":{"fields":{"slug":"api/enty/dynamic-schema/"},"frontmatter":{"title":"Dynamic Schema"},"headings":[{"value":"Params","depth":2},{"value":"shape","depth":3},{"value":"Methods","depth":2},{"value":".normalize()","depth":3},{"value":".denormalize()","depth":3},{"value":"Examples","depth":2},{"value":"Non-homogeneous Array","depth":3},{"value":"Union Type","depth":3}]}},{"childMdx":{"fields":{"slug":"api/enty/entity-schema/"},"frontmatter":{"title":"Entity Schema"},"headings":[{"value":"Params","depth":2},{"value":"name","depth":3},{"value":"options.shape","depth":3},{"value":"options.idAttribute","depth":3},{"value":"Methods","depth":2},{"value":".normalize()","depth":3},{"value":".denormalize()","depth":3}]}},{"childMdx":{"fields":{"slug":"api/enty/id-schema/"},"frontmatter":{"title":"Id Schema"},"headings":[{"value":"Params","depth":2},{"value":"shape","depth":3},{"value":"options.create","depth":2},{"value":"Methods","depth":2},{"value":".normalize()","depth":3},{"value":".denormalize()","depth":3}]}},{"childMdx":{"fields":{"slug":"api/enty/object-schema/"},"frontmatter":{"title":"Object Schema"},"headings":[{"value":"Params","depth":2},{"value":"shape","depth":3},{"value":"options.create","depth":3},{"value":"options.merge","depth":3},{"value":"Methods","depth":2},{"value":".normalize()","depth":3},{"value":".denormalize()","depth":3}]}},{"childMdx":{"fields":{"slug":"api/enty/value-schema/"},"frontmatter":{"title":"Value Schema"},"headings":[{"value":"Params","depth":2},{"value":"shape","depth":3},{"value":"options.shape","depth":3},{"value":"Methods","depth":2},{"value":".normalize()","depth":3},{"value":".denormalize()","depth":3}]}}]},{"fieldValue":"Enty Immutable","nodes":[{"childMdx":{"fields":{"slug":"api/enty-immutable/list-schema/"},"frontmatter":{"title":"List Schema"},"headings":[{"value":"Params","depth":2},{"value":"shape","depth":3},{"value":"options.shape","depth":3},{"value":"options.merge","depth":3},{"value":"Methods","depth":2},{"value":".normalize()","depth":3},{"value":".denormalize()","depth":3}]}},{"childMdx":{"fields":{"slug":"api/enty-immutable/map-schema/"},"frontmatter":{"title":"Map Schema"},"headings":[{"value":"Params","depth":2},{"value":"shape","depth":3},{"value":"Methods","depth":2},{"value":".normalize()","depth":3},{"value":".denormalize()","depth":3}]}}]},{"fieldValue":"React Enty","nodes":[{"childMdx":{"fields":{"slug":"api/react-enty/entity-api/"},"frontmatter":{"title":"Entity Api"},"headings":[{"value":"Params","depth":2},{"value":"actionMap","depth":3},{"value":"schema","depth":3},{"value":"Returns","depth":2},{"value":"useRequest","depth":3},{"value":"RequestHoc","depth":3},{"value":"Root Returns","depth":2},{"value":"Provider","depth":3},{"value":"ProviderHoc","depth":3},{"value":"useRemove","depth":3},{"value":"RemoveHoc","depth":3},{"value":"Examples","depth":2},{"value":"Combining Multiple Apis","depth":3}]}},{"childMdx":{"fields":{"slug":"api/react-enty/message/"},"frontmatter":{"title":"Message"},"headings":[{"value":"Properties","depth":2},{"value":".response","depth":3},{"value":".requestState","depth":3},{"value":".requestError","depth":3},{"value":"Methods","depth":2},{"value":".onRequest()","depth":3},{"value":".get()","depth":3},{"value":".getIn()","depth":3},{"value":".updateRequestState()","depth":3},{"value":".toEmpty()","depth":3},{"value":".toFetching()","depth":3},{"value":".toRefetching()","depth":3},{"value":".toSuccess()","depth":3},{"value":".toError()","depth":3},{"value":"Static Unit Functions","depth":2},{"value":"Message.empty()","depth":3},{"value":"Message.fetching()","depth":3},{"value":"Message.refetching()","depth":3},{"value":"Message.success()","depth":3},{"value":"Message.error()","depth":3}]}},{"childMdx":{"fields":{"slug":"api/react-enty/remove-hook/"},"frontmatter":{"title":"useRemove"},"headings":[{"value":"Examples","depth":2}]}},{"childMdx":{"fields":{"slug":"api/react-enty/request-hoc/"},"frontmatter":{"title":"RequestHoc"},"headings":[{"value":"Config","depth":2},{"value":".name","depth":3},{"value":".auto","depth":3},{"value":".payloadCreator","depth":3},{"value":".shouldComponentAutoRequest","depth":3},{"value":"Examples","depth":2},{"value":"Fetch On Load","depth":3},{"value":"Fetch On Prop Change","depth":3},{"value":"Fetch On Callback","depth":3},{"value":"Fetch Series","depth":3},{"value":"Fetch Parallel","depth":3}]}},{"childMdx":{"fields":{"slug":"api/react-enty/request-hook/"},"frontmatter":{"title":"useRequest"},"headings":[{"value":"Examples","depth":2},{"value":"Fetch On Load","depth":3},{"value":"Fetch On Prop Change","depth":3},{"value":"Fetch On Callback","depth":3},{"value":"Fetch Series","depth":3},{"value":"Fetch Parallel","depth":3}]}},{"childMdx":{"fields":{"slug":"api/react-enty/request-state/"},"frontmatter":{"title":"Request State"},"headings":[{"value":"Properties","depth":2},{"value":".is{State}","depth":3},{"value":"Methods","depth":2},{"value":".{state}Map()","depth":3},{"value":".{state}FlatMap()","depth":3},{"value":".to{state}()","depth":3},{"value":".value()","depth":3},{"value":"Unit Functions","depth":3},{"value":"Examples","depth":2},{"value":"ApplyLoader","depth":3},{"value":"Merging RequestStates","depth":3},{"value":"Any Success","depth":3}]}}]}]},"mdx":{"id":"8e163ce1-23d3-5fd0-8972-dbe233d0a2d3","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;","fields":{"slug":"api/react-enty/message/"},"headings":[{"depth":2,"value":"Properties"},{"depth":3,"value":".response"},{"depth":3,"value":".requestState"},{"depth":3,"value":".requestError"},{"depth":2,"value":"Methods"},{"depth":3,"value":".onRequest()"},{"depth":3,"value":".get()"},{"depth":3,"value":".getIn()"},{"depth":3,"value":".updateRequestState()"},{"depth":3,"value":".toEmpty()"},{"depth":3,"value":".toFetching()"},{"depth":3,"value":".toRefetching()"},{"depth":3,"value":".toSuccess()"},{"depth":3,"value":".toError()"},{"depth":2,"value":"Static Unit Functions"},{"depth":3,"value":"Message.empty()"},{"depth":3,"value":"Message.fetching()"},{"depth":3,"value":"Message.refetching()"},{"depth":3,"value":"Message.success()"},{"depth":3,"value":"Message.error()"}],"frontmatter":{"title":"Message"}}},"pageContext":{"isCreatedByStatefulCreatePages":false,"id":"8e163ce1-23d3-5fd0-8972-dbe233d0a2d3"}}}