{"_id":"@allbin/with-profile","_rev":"6-62025eeafe61829d985025c7d0f0ed20","name":"@allbin/with-profile","dist-tags":{"latest":"0.5.3"},"versions":{"0.5.3":{"name":"@allbin/with-profile","version":"0.5.3","author":"","license":"ISC","_id":"@allbin/with-profile@0.5.3","maintainers":[{"name":"mdjarv","email":"mathias.djarv@allbinary.se"},{"name":"pscz","email":"samuel.psc.olsson@gmail.com"},{"name":"alendri","email":"joakim.johansson@allbinary.se"}],"homepage":"https://bitbucket.org/allbin/with-profile#readme","bugs":{"url":"https://bitbucket.org/allbin/with-profile/issues"},"dist":{"shasum":"52170c6be70213bd962c5f42fb1eb067e7fc14b4","tarball":"https://registry.npmjs.org/@allbin/with-profile/-/with-profile-0.5.3.tgz","fileCount":15,"integrity":"sha512-T+HbDe6y7XXMWxjKLlcAgavf3ItIDD19OpqUUya4/6yzHXhPSTOI4fIovgezqwNSvQK6RmIN2mTxYGeUufE3Aw==","signatures":[{"sig":"MEYCIQDaKB10F7YlBece0vhDkV1nsyvsYzSchBpPY1z2t4LINgIhAN64hwaVx9g59LYmRL5extLZ1QDTFubtuKiE3FJ46WSB","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":63624,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v4.10.10\r\nComment: https://openpgpjs.org\r\n\r\nwsFzBAEBCAAGBQJjiL8tACEJED1NWxICdlZqFiEECWMYAoorWMhJKdjhPU1b\r\nEgJ2VmoYig//TFHTdGFmPdUXiIyJ3+M7RaEOVraXpmOOVVghT9fPj85/RJqJ\r\nZ9j09PNSdAIPtKplvdErRTMjKzaSETMuzuSZ6/DfCOCT1FG1pLm+BzFgHKOP\r\nTzj1G1A+jBw94ZVbpst1+AejBgwfP4LMEfEduWcJ6/XEHa5Zl5yP5FCoqBnG\r\nm6MlqyuWp6EeqTyR2HOdaSZiiyjOixu24Y87xTUUCPmvzRSGWkE/jP2j4+lC\r\njjkbdhqaSJD5wsX0aCkg79LFvtpn2Kg4RIRRocL4HdQEVAKJ1AfclBAkYuLP\r\nRUTUoY4WckBuuZH0PL4yHn3dB72ZdQhjvEfDVYkp6pM0YoFPlIeqFh8aw+bl\r\nAXh74XaxfIuaa0TfIiIaEVjq8H3cMf/DEgy2UOqSa13SFLu1KKknc7v/deO4\r\nuyzO8j2JCLdBFgMp+SCX96Pb9hl1nuTWB+PS/a3wewX4SHneVCV7x8rtRdZJ\r\nGCbhRv7Pej5fuiLh7Zo1SW+t92zFYR70FWMOqDv/5wJK0BP5QyrUelkMwbys\r\nraD15mPR5wLgm9McKxUXUpI3Yp+RW6o5IeR86D6OOz3sW06uIsLHRbAEmVwy\r\nHg7f4rN3tqd9FzQ/sOSDElXX+Q+gdVYjdhQ6zqH2mwvl+WA2GK+KxPPqW7vA\r\nAN1DqvHh85zeyTN0DR5Svj7LMpXjKFfUC3M=\r\n=4zr3\r\n-----END PGP SIGNATURE-----\r\n"},"main":"dist/index.js","types":"./dist/index.d.ts","gitHead":"8bbc89ef9169a34f59d3c28c06e9dfd106da4d93","scripts":{"test":"echo \"Error: no test specified\" && exit 1","build":"gulp4 build","release:major":"gulp4 release:major","release:minor":"gulp4 release:minor","release:patch":"gulp4 release:patch"},"_npmUser":{"name":"pscz","email":"samuel.psc.olsson@gmail.com"},"repository":{"url":"git+https://bitbucket.org/allbin/with-profile.git","type":"git"},"_npmVersion":"8.3.1","description":"Module to automatically fetch data from a specific url and render wrapped children after.","directories":{},"_nodeVersion":"16.14.0","dependencies":{"axios":"0.18.0","react":"16.5.0","@types/react":"16.4.13","@types/react-dom":"16.0.7"},"_hasShrinkwrap":false,"devDependencies":{"gulp4":"4.0.2","tslint":"5.11.0","gulp-bump":"3.1.1","typescript":"^3.9.10","gulp-tslint":"8.1.3","gulp-typescript":"5.0.0-alpha.3","tslint-eslint-rules":"5.4.0"},"_npmOperationalInternal":{"tmp":"tmp/with-profile_0.5.3_1669906221721_0.6852762273973476","host":"s3://npm-registry-packages"}}},"time":{"created":"2022-12-01T14:50:21.651Z","modified":"2026-04-28T15:26:10.335Z","0.5.3":"2022-12-01T14:50:21.902Z"},"bugs":{"url":"https://bitbucket.org/allbin/with-profile/issues"},"license":"ISC","homepage":"https://bitbucket.org/allbin/with-profile#readme","repository":{"url":"git+https://bitbucket.org/allbin/with-profile.git","type":"git"},"description":"Module to automatically fetch data from a specific url and render wrapped children after.","maintainers":[{"email":"samuel.psc.olsson@gmail.com","name":"pscz"},{"email":"noah.hakansson@protonmail.com","name":"noahhakansson"},{"email":"mathias.djarv@allbinary.se","name":"mdjarv"},{"email":"james.taylor@mobilix.io","name":"jamestttt"}],"readme":"# withProfile\n\nA repo for wrapping components with a withProfile HOC to ensure loading of users.\nA spinner is optionally shown while the profile is being fetched.\n\n### Index\n[Quick guide](#quick-guide)  \n[HOC Wrapping function](#wrapping-function)  \n[Utility functions](#utility-functions)  \n[Saving profile updates](#saving-profile-updates)  \n[Setting config and default](#setting-config-and-default)  \n\n\n\n# Quick guide\nAdd `\"with-profile\": \"git+https://bitbucket.org/allbin/with-profile.git#v`**`x.y.z`** to package.json. Where **x.y.z** is the version tagged.\n\nUse `import withProfile from 'with-profile'` in any file and wrap desired component in it to ensure profile is loaded before rendering.\n\n### Example MyComponent.jsx component:\n```\nimport React from 'react';\nimport withProfile from 'with-profile';\n\nclass MyComponent extends React.Component {\n    ...\n}\n\nexport default withProfile(MyComponent);\n```\n\n### Example inline component:\n```\nimport React from 'react';\nimport withProfile from 'with-profile';\nimport SomeComponent from './components/SomeComponent';\n\nlet SomeComponentWithProfile = withProfile(SomeComponent);\n\nexport default class MyComp extends React.Component {\n    ...\n\n    render() {\n        return (\n            <div>\n                <SomeComponentWithProfile />\n            </div>\n        );\n    }\n}\n\n```\n\n### Example with configuration and store integration\n```\nimport React from 'react';\nimport withProfile from 'with-profile';\nimport withStore from 'with-store';\nimport SomeComponent from './components/SomeComponent';\nimport ChildComponent from './components/ChildComponent';\n\nwithProfile.config({\n    url: \"http://url.to.profile/:user_id\",\n    store: withStore\n});\n\nlet SomeComponentWithProfile = withProfile(SomeComponent);\n\nexport default class MyComp extends React.Component {\n    ...\n\n    render() {\n        return (\n            <SomeComponentWithProfile>\n                <ChildComponent />\n            </SomeComponentWithProfile>\n        );\n    }\n}\n\n```\n**NOTE:** SomeComponent and ChildComponent will only show after fetch is complete.\n\n# Known issues\n- The non-optistimic saves (`withProfile.saveProfile()`) do currently not wait for each other, if multiple saves are made before the previous has finished they may overwrite whatever changes the previous call made. A queue should be added.\n\n\n\n# Wrapping function\nThe HOC wrapping function attaches the `profile` prop to the component being wrapped.\n\nExample: `withProfile(YourComponent)` will give access to `this.props.profile` inside *YourComponent*.\n\n### Optional parameters\n#### SpinnerComponent\n*withProfile(YourComponent, **`SpinnerComponent`**)*.  \nOptionally a second component can be supplied which will be shown while the profile is being fetched. The spinner component, if supplied, also gets all props assigned to the wrapped component.\n\n\n\n# Utility functions\n`withProfile.addStore(<store>)` - withProfile will call the supplied stores addState function with an object containing a reducer and actions for use with a redux store; *store.addState({ reducer: fn, actions: {...} })*.  \nThe state will automatically be populated with the profile either when it is finished fetching or immediately if the profile is already fetched. Can be called multiple times.\n\n`withProfile.configure(<config object>, <default profile>)` - See [Setting config and default](#setting-config-and-default).\n\n`withProfile.doAfterFirstFetch(<callback>)` - The callback will be called with the profile as argument after the first time the profile has been fetched. Can be called multiple times, callbacks will be called in the order they were added.\n\n`withProfile.fetch(<boolean, optional to force reload>)` - Returns a promise that resolves to the profile values, any default values merged with any fetched values.  \nIf the fetch has not been initiated it will be by this call and it will resolve once finished. First argument, *force reload* as true will force a refetch from server.\n\n`withProfile.getProfile()` - Returns the profile values currently in withProfile. Note that this function returns whatever is currently in profile, even if fetch has not finished. Sync version of *fetch()*.\n\n`withProfile.saveProfile(<updated_profile>, <replace>)`  - See [Saving profile updates](#saving-profile-updates).  \n`withProfile.saveProfileOptistic(<updated_profile>, <replace>)` - See [Saving profile updates](#saving-profile-updates).\n\n`withProfile.setFetchedCallback(<callback function>)` - If set the callback will trigger when fetching profile from server has completed. The callbacks only parameter will be the final config object. Note that this function will trigger every time a fetch is completed, such as when `withProfile.fetch(true)` is run to force a refetch and when `withProfile.saveProfile(updated_profile)` is used.\n\n\n\n# Saving profile updates\n`withProfile.saveProfile(<updated_profile>, <replace>)`  \nUsed to save an updated profile to the server, returns a Promise which resolves to the new profile when the server request has finished.  \n***updated_profile*** -  object, required\n> Object to save to the server.\n\n***replace*** - boolean, default false\n>When true *updated_profile* will replace existing profile. Otherwise existing profile will be extended with *updated_profile*.  \n\n`withProfile.saveProfileOptimistic(<updated_profile>, <replace>)`  \nWill optimistically trigger updates of components and states. Returns a Promise which resolves to the profile as the server believes it is when request is complete.  \n***NOTE:** This is only advisable if the profile write to server is not critical for application operation.*  \n***NOTE:** You may catch request errors on the returned promise.*  \n***NOTE:** An opimistic save issued between the issuing and completion of a non-optimistic save will first overwrite the optimistic save with the result of the non-optimistics request and then when the opimistic server request returns overwrite (and delete) the changes of the non-optimistic.*\n\n***NOTE: BE AWARE that if these functions are called before first fetch has completed it will act as a partial replace. Since it will send an updated profile to the server that doesn't contain whatever the server currently has!** Use `doAfterFirstFetch` to register a callback to know when it is safe to proceed with profile saving.*\n\n\n\n# Setting config and default\nUse `withProfile.config(<config_object>, <default_profile>)` to configure and set default profile. Returns nothing.\n\n**config_object** - object, required\n```\n    {\n        url: <required, string, url to the profile>,\n        token: <required, function that returns an authentication token string>\n        store: <optional>\n    }\n``` \n>Supplying a **store** in config is equivalent to `withProfile.addStore(<store>)`.\n\n**default_profile** - object, optional\n> Default profile can be any object with any properties but will be overwritten by fetched profile.\n\n\n\n","readmeFilename":"README.md"}