{"_id":"@avine/rx-data-store","_rev":"8-7ca8912bdd7661df1ae71bf752848cbb","name":"@avine/rx-data-store","dist-tags":{"latest":"0.1.5"},"versions":{"0.1.0":{"name":"@avine/rx-data-store","description":"From data source to reactive data store.","version":"0.1.0","private":false,"repository":{"type":"git","url":"git+https://github.com/avine/ng-libs.git"},"keywords":["rxjs","redux","state","angular"],"author":{"name":"Stéphane Francel","email":"contact@avine.io"},"license":"MIT","bugs":{"url":"https://github.com/avine/ng-libs/issues"},"homepage":"https://github.com/avine/ng-libs/tree/main/projects/rx-data-store#readme","peerDependencies":{"@angular/common":">=14.0.0","@angular/core":">=14.0.0"},"dependencies":{"tslib":"^2.3.0"},"module":"fesm2015/avine-rx-data-store.mjs","es2020":"fesm2020/avine-rx-data-store.mjs","esm2020":"esm2020/avine-rx-data-store.mjs","fesm2020":"fesm2020/avine-rx-data-store.mjs","fesm2015":"fesm2015/avine-rx-data-store.mjs","typings":"index.d.ts","exports":{"./package.json":{"default":"./package.json"},".":{"types":"./index.d.ts","esm2020":"./esm2020/avine-rx-data-store.mjs","es2020":"./fesm2020/avine-rx-data-store.mjs","es2015":"./fesm2015/avine-rx-data-store.mjs","node":"./fesm2015/avine-rx-data-store.mjs","default":"./fesm2020/avine-rx-data-store.mjs"}},"sideEffects":false,"gitHead":"e4a13c0b8842afa6b054e6f9458d2a3b3b70e34f","_id":"@avine/rx-data-store@0.1.0","_nodeVersion":"18.12.1","_npmVersion":"8.19.2","dist":{"integrity":"sha512-4EzBkHVHtDr6nsZ6Nm8WIM5nPal1a7IJXNKxiaeNVpWcc58F7ZfjvWWA0M6cdVJt3Qgr8nXtIasN1JMn5A5fKQ==","shasum":"f0692a0a8b88c8cf427ca580be53aaa2ca68a71a","tarball":"https://registry.npmjs.org/@avine/rx-data-store/-/rx-data-store-0.1.0.tgz","fileCount":14,"unpackedSize":100365,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEQCIDNoz5wIdLW+Cp2IdRq1n/Qr4FU2hsnpi3z9aLScRhj5AiB1yzL8qPD0eItxYRwMPt1QFdgdpO8r6OHwG5EO1PwWoQ=="}],"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v4.10.10\r\nComment: https://openpgpjs.org\r\n\r\nwsFzBAEBCAAGBQJjh+4VACEJED1NWxICdlZqFiEECWMYAoorWMhJKdjhPU1b\r\nEgJ2Vmqqog/+M8Zp/Hdn6AM42T2vLkIzQt46pqsKDUcoIlDhHuMakIXxWr3J\r\nsUUYthCgTjmtpHchCswiy711eJ/f2ochAIr3tQDnTa+FVJpzFFSxBEZMmzlW\r\nZvFt6t33MDF3QKPa/ui+7wshBTi+iuLx5ywQ40VT87XaGGicaNgehXv3fDl+\r\n611RgdlG23Yh0xyTfe+gmTxJz+3oiz1Bda28ncVggFw0AATTuI3cfU3WdSR/\r\nt4/bd0tXMYwJEr/wXgEWkTuFmUtXaI8fm0jsVPWPOPwnDZ/Ed/6KcbHqTIQb\r\n44AgstlRDyMC8ff4ieV8SpHgS1BG8je75RzgE5pyzyWoYEC6XJVkYIqWJ+L0\r\nRu/U26GTc1ZOKWms8N4tLASMnBy719CXeYKFPoLn5Yidg62sEsRiizaL4n35\r\nXKeqvvHrtHgukHjENDQDt7dcZTQAgbnh24cBgtRiCMVDc13LBSV42eop3w4G\r\nH3Yd5Mbgkxsafr3tHGVlfHywM5/rTraALXGQ/LOEgGfLcST0/tKcoqcNK5uc\r\nfzumhr45UzD97nzX9TAOaJO3xfuGqWZkIBbyiRgET4qaosXZpbq4IS7q1MAj\r\nG9uIjoUCpbTCMmXAQnyNuVQE5+PJ4IIRjc+xKyPLQwu5aZ1i9+BqlVWVcKns\r\nsxcDaM33sPn44xOzYnRQ2f/oRTew+UX5scM=\r\n=/Zd9\r\n-----END PGP SIGNATURE-----\r\n"},"_npmUser":{"name":"avine","email":"contact@avine.io"},"directories":{},"maintainers":[{"name":"avine","email":"contact@avine.io"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/rx-data-store_0.1.0_1669852693435_0.3413213893504128"},"_hasShrinkwrap":false},"0.1.2":{"name":"@avine/rx-data-store","description":"From data source to reactive data store.","version":"0.1.2","private":false,"repository":{"type":"git","url":"git+https://github.com/avine/ng-libs.git"},"keywords":["rxjs","redux","state","angular"],"author":{"name":"Stéphane Francel","email":"contact@avine.io"},"license":"MIT","bugs":{"url":"https://github.com/avine/ng-libs/issues"},"homepage":"https://github.com/avine/ng-libs/tree/main/projects/rx-data-store#readme","peerDependencies":{"@angular/common":">=14.0.0","@angular/core":">=14.0.0"},"dependencies":{"tslib":"^2.3.0"},"module":"fesm2015/avine-rx-data-store.mjs","es2020":"fesm2020/avine-rx-data-store.mjs","esm2020":"esm2020/avine-rx-data-store.mjs","fesm2020":"fesm2020/avine-rx-data-store.mjs","fesm2015":"fesm2015/avine-rx-data-store.mjs","typings":"index.d.ts","exports":{"./package.json":{"default":"./package.json"},".":{"types":"./index.d.ts","esm2020":"./esm2020/avine-rx-data-store.mjs","es2020":"./fesm2020/avine-rx-data-store.mjs","es2015":"./fesm2015/avine-rx-data-store.mjs","node":"./fesm2015/avine-rx-data-store.mjs","default":"./fesm2020/avine-rx-data-store.mjs"}},"sideEffects":false,"gitHead":"d1c37d291f1d77e55f3d8ba4a668dafe7d836f58","_id":"@avine/rx-data-store@0.1.2","_nodeVersion":"18.12.1","_npmVersion":"8.19.2","dist":{"integrity":"sha512-dcplByA+i53NCvx7jzPbxiKI8yPhADNnTzctQEAxXOgb498r4u9ffgLakQwXrjgx4mWhd1+HGrV48D2yrnNC2w==","shasum":"6ed29d98795f1ee643c56c437e82d8cd3205c540","tarball":"https://registry.npmjs.org/@avine/rx-data-store/-/rx-data-store-0.1.2.tgz","fileCount":14,"unpackedSize":100813,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEQCIQDb9NyY5Kl2udkuWvpGc9phHTu5QhjKwFEdcGiKYZs2YwIfGKXNhVQ1/OSaDfuFEDwjA+QZ8Dac3NF26o3SzaQSXw=="}],"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v4.10.10\r\nComment: https://openpgpjs.org\r\n\r\nwsFzBAEBCAAGBQJjiTFOACEJED1NWxICdlZqFiEECWMYAoorWMhJKdjhPU1b\r\nEgJ2VmrZ5Q/+N01QCUDoDF7DWLM3PaadLN+Sd+WI+ta6PWFnOCNyUulf6GvF\r\ngBw0Srf/iV3cnsJM2T4XfEAaDiNtkTDrqw2WLPBTF6XyPiqw/FwN4YWT6pUI\r\n27eFKx8Zb5lULePP1Sy+n5NzrDvEzBUWBp5Ulb/ZAM2lQWbaYnWTnSEMO5SV\r\nzwdmjDyKKfH4xR/s4PwoIz7gIoPJ79+a2uPZ4wRVlrd3Qa5e/id/ljy2fh48\r\nXnSKXx6EkNQnrc8YtjogxPPVKwsRXcDDDRkZqDIdMDl0X6F8Fbfu9UeNPl79\r\n0fkFNwE/aoqRpkPvwZ7REnN6fdZTgTDw6+eAb+BsCF7xsI7ZfEEwNaAZvYkf\r\nSfM71g83vhYDViXhO1OUBeSwZeTer0iNuFsDWIwWsIUG+NF7tHfiKQvhFVYY\r\ny7ClHO2jI9bBxU7a7TWZeMQKmeUT2gKtkV17Zjfb07W8ucIfv5YRNCemPZs8\r\n7FS/s9phv5DQbBB4BzSAnd3338AuAKia+6I7HyuKK/mtKRk7SaCdznpIU/8Y\r\nhUhn3FvryvZKqcIS91M1knj2PSGBve+dvFOJ2l7Ib73DjiV/fiQfKavDlNFl\r\nXQWmhuboYvJavSvCXeoUgPgLju0FNVNDLS9UXCrrGeLEVc3TfsBpo5jbWoJV\r\nd0YlzwpaXHygOeSFJN0GtDzBvjBOF1krSRM=\r\n=E8dh\r\n-----END PGP SIGNATURE-----\r\n"},"_npmUser":{"name":"avine","email":"contact@avine.io"},"directories":{},"maintainers":[{"name":"avine","email":"contact@avine.io"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/rx-data-store_0.1.2_1669935438387_0.1833577376443516"},"_hasShrinkwrap":false},"0.1.3":{"name":"@avine/rx-data-store","description":"From data source to reactive data store.","version":"0.1.3","private":false,"repository":{"type":"git","url":"git+https://github.com/avine/ng-libs.git"},"keywords":["rxjs","redux","state","angular"],"author":{"name":"Stéphane Francel","email":"contact@avine.io"},"license":"MIT","bugs":{"url":"https://github.com/avine/ng-libs/issues"},"homepage":"https://github.com/avine/ng-libs/tree/main/projects/rx-data-store#readme","peerDependencies":{"rxjs":"^7.5.0"},"dependencies":{"tslib":"^2.3.0"},"module":"fesm2015/avine-rx-data-store.mjs","es2020":"fesm2020/avine-rx-data-store.mjs","esm2020":"esm2020/avine-rx-data-store.mjs","fesm2020":"fesm2020/avine-rx-data-store.mjs","fesm2015":"fesm2015/avine-rx-data-store.mjs","typings":"index.d.ts","exports":{"./package.json":{"default":"./package.json"},".":{"types":"./index.d.ts","esm2020":"./esm2020/avine-rx-data-store.mjs","es2020":"./fesm2020/avine-rx-data-store.mjs","es2015":"./fesm2015/avine-rx-data-store.mjs","node":"./fesm2015/avine-rx-data-store.mjs","default":"./fesm2020/avine-rx-data-store.mjs"}},"sideEffects":false,"gitHead":"72e56d83fe3466fa15c2cfff6fa7acb53584c43c","_id":"@avine/rx-data-store@0.1.3","_nodeVersion":"18.12.1","_npmVersion":"8.19.2","dist":{"integrity":"sha512-ZDTeiiM0OwNkgc23T6D8jxLEe8/XblS8tYv4IBoppardBkG8MjXSi4TO+U4qLug+OBy1MPfNpVCFeZxJdYDS7Q==","shasum":"f3a4288c909447ae0068e9ff75367ca269f2b6a6","tarball":"https://registry.npmjs.org/@avine/rx-data-store/-/rx-data-store-0.1.3.tgz","fileCount":14,"unpackedSize":100767,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQCU5VDeipUo8DRaGT1AaDAfY/MJVXyPzeeQpefdm5Z8tgIgbKJ9py8Jx1Zbs58wxcBudnV6U2bfPz9KCtt0MBi77jc="}],"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v4.10.10\r\nComment: https://openpgpjs.org\r\n\r\nwsFzBAEBCAAGBQJji8l+ACEJED1NWxICdlZqFiEECWMYAoorWMhJKdjhPU1b\r\nEgJ2VmrmyQ//ZdlIrR7MVGUXgxVpgWa3dGAG7zzQ5PiFeBDW4O7LCY5yP2DI\r\nLvXMc1Y9j6mpkXdMkVzkTIr2ImgWVs5Og50DhD2sdI2u0+MWlzXhYPYX8HQ1\r\nVmZCpLo4yd1pKu5IYgigjeeeb6ScgQSfycJpB9vLutczYfG4ihEK2QXA5pnE\r\nqez7QUfxO+921pyn/e9LwFVKhEo+CvkyBi9ozvI2qaCO1ojhzg8mKJreQf9X\r\nI2BXJES1jkHcVPy/lKaVnnSolqUNtXFWv76FP0QV3u612NaQOuscqy384vHy\r\nnBgkC9yXOOrWFgdcVyCVcWpTMUv12mdTJuM9wo7FOG0iq/DOW9tfkLIXktF3\r\nZGknRnzmXLV3PaWyzAbqc7Ha2/EWStJvanYqkfrzfPesb1DhAvjGqQU34Jfi\r\nQLq7MsSVA0WAXJ/1UPUO6wdGzs7KzeVUV1BqB6WOY8YknYYRVb3J+k96nWZk\r\nyCe+0PP+Y4h4Ijgx6I/gilT6Y2bzm+whotw3X2OomIFJ4s1JwJmvL4vFHT1R\r\nDf/Ux3DQmZIA1A/wAVo+i56SHGF/JXz4iaK5TmcEFOm2qQz3C/KV0wVmSE1c\r\nXdQPomw2YAzrq/1+48OOTKS/0jjrEPU/AyGExnWfDs7L4XwK7uVXn88ZF38v\r\nmXYu33DIBsCtp2b8tWJgCa4GpAz03DSMJBg=\r\n=K04B\r\n-----END PGP SIGNATURE-----\r\n"},"_npmUser":{"name":"avine","email":"contact@avine.io"},"directories":{},"maintainers":[{"name":"avine","email":"contact@avine.io"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/rx-data-store_0.1.3_1670105470210_0.2909712686255208"},"_hasShrinkwrap":false},"0.1.4":{"name":"@avine/rx-data-store","description":"From data source to reactive data store.","version":"0.1.4","private":false,"repository":{"type":"git","url":"git+https://github.com/avine/ng-libs.git"},"keywords":["rxjs","redux","state","angular"],"author":{"name":"Stéphane Francel","email":"contact@avine.io"},"license":"MIT","bugs":{"url":"https://github.com/avine/ng-libs/issues"},"homepage":"https://github.com/avine/ng-libs/tree/main/projects/rx-data-store#readme","peerDependencies":{"rxjs":"^7.5.0"},"dependencies":{"tslib":"^2.3.0"},"module":"fesm2015/avine-rx-data-store.mjs","es2020":"fesm2020/avine-rx-data-store.mjs","esm2020":"esm2020/avine-rx-data-store.mjs","fesm2020":"fesm2020/avine-rx-data-store.mjs","fesm2015":"fesm2015/avine-rx-data-store.mjs","typings":"index.d.ts","exports":{"./package.json":{"default":"./package.json"},".":{"types":"./index.d.ts","esm2020":"./esm2020/avine-rx-data-store.mjs","es2020":"./fesm2020/avine-rx-data-store.mjs","es2015":"./fesm2015/avine-rx-data-store.mjs","node":"./fesm2015/avine-rx-data-store.mjs","default":"./fesm2020/avine-rx-data-store.mjs"}},"sideEffects":false,"gitHead":"ded73bf008b7c0a975973981ee2943e0b871826c","_id":"@avine/rx-data-store@0.1.4","_nodeVersion":"18.12.1","_npmVersion":"8.19.2","dist":{"integrity":"sha512-yl80GnYZStGi7G3EmLtd7pknSmnmM98AWBCv+ReY9x35VKmkW3wf6Nia1ajrzFHs+1Uq98BdFwy3+9dmRRptoQ==","shasum":"76a71fa4de7893943ad2e7c05a861ed0300e5d06","tarball":"https://registry.npmjs.org/@avine/rx-data-store/-/rx-data-store-0.1.4.tgz","fileCount":14,"unpackedSize":100645,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEQCIE2V8c5jW3UKZPxivW/EHi5tYW1+Dd8LWPhXHvErIww6AiA2Y5RG6h5ptRNTIFCFwlUFHpZlfOiifcKEWkINi0nWnA=="}],"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v4.10.10\r\nComment: https://openpgpjs.org\r\n\r\nwsFzBAEBCAAGBQJjo28bACEJED1NWxICdlZqFiEECWMYAoorWMhJKdjhPU1b\r\nEgJ2VmpV0RAAkGox2zYc8wtYTvlstpM53EEfevu3Or9wGdvPd20xU5WRRqHO\r\niXhL82YgOuvdK1C5IYEJ7WqaAmXnnPLBzRkGCca8aSRZAZfDePSZHgPSpnjf\r\nLoebZcO4Nke4ZaOEmJzdjn2ZurAktRk0BMfn8K6dbmP+3yfAHBXw/c7MCXI7\r\ngVMtYG6kx2qzYPy3Vq1ts5mSb0RdAdJ81CCTY+kfuuqxB8p9p6bNHj0gnzK5\r\nr4gMw9Nf0/RMSLo+247EXnhVC4x3pdyNwjkl3enhg6FaaiFjBZV3LSTbh0oU\r\niisn1+ZsgpkRIpGDgchryO792u8RXHPWKz/uvm+DiL9U9UQTovc8eNirsjoy\r\nxsFxViNlTRyzO2cTdZTg0u0AhWLnv70bYsXkRoKvThuNEZ4c46aGKsGaGLde\r\nwb1c/76J486UJIuSENcm4nMrfo3ghT51/WpQdSMUYIlpGotqDa0NE7yGXj41\r\nPpfONE8rSPBlVcWIdhQ/Jt2XlsrLfqkQ+qZlNMsd5i0IJF6edJq93C8SWpcy\r\noD4aRkJr5Rt+XGuEt4/oSzNyOSaps4tlp4oTrSv3rLRKCxRbcRQy9lW/uEgs\r\nLE8LbAU8/KRoJZc4+mrbux16IXPE9vYYBFoVSvuCkZyjYedMmDnriKUIF/wq\r\nm/eYTPmZucsEZcawat4Rso0VvnENxTmxYSY=\r\n=za9Q\r\n-----END PGP SIGNATURE-----\r\n"},"_npmUser":{"name":"avine","email":"contact@avine.io"},"directories":{},"maintainers":[{"name":"avine","email":"contact@avine.io"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/rx-data-store_0.1.4_1671655195515_0.041330360586978365"},"_hasShrinkwrap":false},"0.1.5":{"name":"@avine/rx-data-store","description":"From data source to reactive data store.","version":"0.1.5","private":false,"repository":{"type":"git","url":"git+https://github.com/avine/ng-libs.git"},"keywords":["rxjs","redux","state","angular"],"author":{"name":"Stéphane Francel","email":"contact@avine.io"},"license":"MIT","bugs":{"url":"https://github.com/avine/ng-libs/issues"},"homepage":"https://github.com/avine/ng-libs/tree/main/projects/rx-data-store#readme","peerDependencies":{"rxjs":">= 7.5.0"},"dependencies":{"tslib":"^2.3.0"},"module":"fesm2022/avine-rx-data-store.mjs","typings":"index.d.ts","exports":{"./package.json":{"default":"./package.json"},".":{"types":"./index.d.ts","esm2022":"./esm2022/avine-rx-data-store.mjs","esm":"./esm2022/avine-rx-data-store.mjs","default":"./fesm2022/avine-rx-data-store.mjs"}},"sideEffects":false,"gitHead":"63969728bdc756230e0851074d4bbf76320d352a","_id":"@avine/rx-data-store@0.1.5","_nodeVersion":"18.17.1","_npmVersion":"9.6.7","dist":{"integrity":"sha512-+2sXksmkBVm8or+d/DXkY519Xg2BFbNt6FaiHord1cMnGX/hfVqOV3Oh102ReaqKRxCcm3gZ9xkw6hoOxhvJ2A==","shasum":"948d737a1c1d8552c7f36deed4fd2da3ca980aa6","tarball":"https://registry.npmjs.org/@avine/rx-data-store/-/rx-data-store-0.1.5.tgz","fileCount":12,"unpackedSize":74049,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQD03a4BcOogvJl6XyConN84/jN5JSyMpeMECdASWmfWwQIgW25099ouf6+JwafLJrD/EpSQcIXiJVQMRCDumPu6mk0="}]},"_npmUser":{"name":"avine","email":"contact@avine.io"},"directories":{},"maintainers":[{"name":"avine","email":"contact@avine.io"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/rx-data-store_0.1.5_1695115468803_0.990739010170437"},"_hasShrinkwrap":false}},"time":{"created":"2022-11-30T23:58:13.380Z","0.1.0":"2022-11-30T23:58:13.600Z","modified":"2023-09-19T09:24:29.213Z","0.1.1":"2022-12-01T22:50:18.346Z","0.1.2":"2022-12-01T22:57:18.568Z","0.1.3-beta":"2022-12-03T22:09:03.793Z","0.1.3":"2022-12-03T22:11:10.416Z","0.1.4":"2022-12-21T20:39:55.736Z","0.1.5":"2023-09-19T09:24:29.017Z"},"maintainers":[{"name":"avine","email":"contact@avine.io"}],"description":"From data source to reactive data store.","homepage":"https://github.com/avine/ng-libs/tree/main/projects/rx-data-store#readme","keywords":["rxjs","redux","state","angular"],"repository":{"type":"git","url":"git+https://github.com/avine/ng-libs.git"},"author":{"name":"Stéphane Francel","email":"contact@avine.io"},"bugs":{"url":"https://github.com/avine/ng-libs/issues"},"license":"MIT","readme":"# rx-data-store\n\nFrom data source to reactive data store.\n\n## Demo\n\nCheck out [demo here](https://avine.github.io/ng-libs/rx-data-store).\n\n## Introduction\n\nYou don't want to use NgRx for the state management of your application, but you are still looking for a lightweight solution.\n\nNow, if you write the following code all the time, then this package is for you...\n\nLet's say you have the following **data source**:\n\n```ts\nimport { HttpClient } from '@angular/common/http';\nimport { Injectable } from '@angular/core';\n\n@Injectable()\nexport class UserApiService {\n  constructor(private httpClient: HttpClient) {}\n\n  get() {\n    return this.httpClient.get<User>('/api/user');\n  }\n}\n```\n\nHere is the associated **data store** service and the component that consumes it:\n\n```ts\nimport { Component, Injectable, OnInit } from '@angular/core';\nimport { map, ReplaySubject, tap } from 'rxjs';\n\n@Injectable()\nexport class UserService {\n  private _user$ = new ReplaySubject<User>(1);\n\n  user$ = this._user$.asObservable();\n\n  constructor(private userApiService: UserApiService) {}\n\n  get() {\n    return this.userApiService.get().pipe(\n      tap((user) => this._user$.next(user)),\n      map(() => undefined), // Force the developer to get the user data from `user$`\n    );\n  }\n}\n\n@Component({\n  selector: 'app-root',\n  template: '<h1>Hello {{ (user$ | async)?.name }}</h1>',\n})\nexport class AppComponent implements OnInit {\n  // Select data from data store\n  user$ = this.userService.user$;\n\n  constructor(private userService: UserService) {}\n\n  ngOnInit() {\n    // Dispatch data store action\n    this.userService.get().subscribe();\n  }\n}\n```\n\nHmm... This is very verbose just to expose the `user$` observable.\nNow let's use `RxDataStore` to simplify it all!\n\n```ts\n@Injectable()\nexport class UserService extends RxDataStore<User> {\n  constructor(private userApiService: UserApiService) {\n    // Calling 'super' is equivalent to writing:\n    //   const dataSource = () => this.userApiService.get();\n    //   const dataStore = new RxDataStore(dataSource, []);\n    super(() => this.userApiService.get(), []);\n  }\n}\n\n@Component({\n  selector: 'app-root',\n  template: '<h1>Hello {{ (user$ | async)?.name }}</h1>',\n})\nexport class AppComponent {\n  // The observable `data$` is an instance property of the class `RxDataStore`.\n  user$ = this.userService.data$;\n\n  constructor(private userService: UserService) {}\n}\n```\n\nIn this example, the `UserService` inherits from `RxDataStore`.\nBut, it's perfectly fine to use `RxDataStore` as an instance property of the `UserService`.\n\n```ts\n@Injectable()\nexport class UserService {\n  store = new RxDataStore<User>(() => this.userApiService.get(), []);\n\n  constructor(private userApiService: UserApiService) {}\n}\n```\n\nWe're just scratching the surface here.\nLet's dive into the features of `RxDataStore`.\n\n## Usage\n\n`RxDataStore` integrates naturally with Angular since it is based on RxJS.\nBut since it only depends on RxJS, it can be used with any other framework.\n\n## API\n\nThe data source is a function that returns an observable.\nLet's say this observable emits 2 consecutive values.\n\n```ts\nimport { of } from 'rxjs';\n\nconst dataSource = (n: number) => of(n, n + 1).pipe(delay(0));\n```\n\n### fetch data from data source\n\n```ts\nimport { RxDataStore } from '@avine/rx-data-store';\n\n// Define the data store\nconst dataStore = new RxDataStore(dataSource);\n\n// Fetch data from the data source (subscribe to `dataSource(1)`)\ndataStore.fetch(1);\n\n// Subscribe to data from the data store\ndataStore.data$.subscribe((data) => console.log(data)); // 1, 2\n```\n\nNote that the order does not matter.\nYou can subscribe to `data$` even after the `fetch` method has been called.\n\n### Set default arguments for data fetching\n\nCalling the `fetch` method is not necessary when the default arguments of the data source function are provided in the constructor.\n\n```ts\n// Data will be fetched using the provided arguments (but only when `data$` is subscribed)\nconst dataStore = new RxDataStore(dataSource, [1]);\n\ndataStore.data$.subscribe((data) => console.log(data)); // 1, 2\n```\n\nNote that even when the data source function has no arguments, you must set the default arguments to an empty array\n(if you don't want to call the `fetch` method).\n\n```ts\nnew RxDataStore(dataSource, []);\n```\n\n### setData\n\nReplace data in the data store without fetching the data source.\n\n```ts\nconst dataStore = new RxDataStore(dataSource, [1]);\n\ndataStore.data$.subscribe((data) => console.log(data)); // 1, 2, 3\n\n// Set data in data store\ndataStore.setData(3);\n```\n\n### updateData\n\nUpdate the data in the data store based on the current state of the data.\n\n```ts\nconst dataStore = new RxDataStore(dataSource, [1]);\n\ndataStore.data$.subscribe((data) => console.log(data)); // 1, 2, 3\n\ndataStore.updateData((data) => data + 1);\n```\n\n### refresh\n\nRefresh data from the data source using the latest arguments.\n\n```ts\nconst dataStore = new RxDataStore(dataSource, [1]);\n\ndataStore.data$.subscribe((data) => console.log(data)); // 1, 2, 1, 2\n\n// Subscribe to `dataSource(1)` again\ndataStore.refresh();\n```\n\n### mutation\n\nSubscribe to an observable (the mutation) and update the data in the data store based on the current state of the data and the response of the mutation.\n\n```ts\nconst dataStore = new RxDataStore(dataSource, [1]);\n\ndataStore.data$.subscribe((data) => console.log(data)); // 1, 2, 3\n\n// Note that you must call `subscribe` in order to execute the mutation.\ndataStore.mutation(of(1), (data, response) => data + response).subscribe(); // 2 + 1 === 3\n```\n\n### mutationQueue\n\nExecute several mutations in order.\n\n```ts\nconst dataStore = new RxDataStore(dataSource, [1]);\n\ndataStore.data$.subscribe((data) => console.log(data)); // 1, 2, 3, 4\n\n// Note that this time you don't call `subscribe` in order to execute the mutations.\ndataStore.mutationQueue(of(1), (data, response) => data + response); // 2 + 1 === 3\ndataStore.mutationQueue(of(1), (data, response) => data + response); // 3 + 1 === 4\n```\n\n### pending$\n\nThe observable `pending$` emits `true` when a task is in progress and `false` when it is idle.\n\n```ts\ndataStore.pending$.subscribe(console.log); // true, false\n```\n\n### error$\n\nThe observable `error$` emits errors that occur during task processing.\n\n```ts\ndataStore.error$.subscribe(console.log);\n```\n\n### map\n\nYou can map the data emitted by the `data$` observable.\nThis can be useful if, for example, you want to deeply clone the emitted data for immutability reasons.\n\n```ts\nimport { cloneDeep } from 'lodash';\n\n// Set the `map` method locally for the dataStore instance only.\ndataStore.map = cloneDeep;\n\n// Or set the `map` method globally for all dataStore instances.\nRxDataStore.map = cloneDeep;\n\n// You can still bypass the global settings for a particular instance this way:\ndataStore.map = 'noop';\n```\n\n### useCache\n\nNote that the latest data is always cached in the data store.\nEnabling the cache is useful when the data source is called with different arguments.\n\n```ts\nconst useCache = true;\nconst dataStore = new RxDataStore(dataSource, undefined, useCache);\n\ndataStore.fetch(1); // Calling `dataSource(1)`\n\ndataStore.fetch(2); // Calling `dataSource(2)`\n\ndataStore.fetch(1); // Getting data from the data store cache\n```\n\n### clearCache\n\nYou can clear the cache at any time.\n\n```ts\ndataStore.clearCache();\n```\n\n## License\n\n[MIT](https://github.com/avine/ng-libs/blob/main/LICENSE)\n\n_Enjoy and have fun with `RxDataStore`._\n","readmeFilename":"README.md"}