{"_id":"@alesmenzel/nuclear-core","name":"@alesmenzel/nuclear-core","dist-tags":{"latest":"1.0.0"},"versions":{"1.0.0":{"name":"@alesmenzel/nuclear-core","version":"1.0.0","description":"Framework agnostic state management library","license":"MIT","main":"./dist/nuclear-core.js","types":"./dist/types/index.d.ts","author":{"name":"Aleš Menzel","email":"alesmenzel@gmail.com","url":"https://github.com/alesmenzel"},"scripts":{"build":"rm -rf dist && rollup --config rollup.config.js","lint":"eslint .","format":"eslint --fix .","pretest":"run-s lint types","test":"jest --ci --config ./jest/jest.config.js","test:coverage":"jest --ci --config ./jest/jest-coverage.config.js","types":"tsc --noEmit --project tsconfig.json","prepublishOnly":"npm run test","prepare":"husky install"},"engines":{"node":">=12.0.0"},"repository":{"type":"git","url":"git+ssh://git@github.com/alesmenzel/nuclear-core.git"},"dependencies":{"@alesmenzel/event-emitter":"^1.1.1"},"devDependencies":{"@babel/core":"^7.17.10","@babel/plugin-proposal-class-properties":"^7.16.7","@babel/plugin-transform-runtime":"^7.17.10","@babel/preset-env":"^7.17.10","@babel/preset-typescript":"^7.16.7","@babel/runtime":"^7.17.9","@babel/runtime-corejs3":"^7.17.9","@rollup/plugin-typescript":"^8.3.2","@types/jest":"^27.5.1","@types/lodash":"^4.14.182","@types/rollup-plugin-progress":"^1.1.1","@typescript-eslint/eslint-plugin":"^5.23.0","@typescript-eslint/parser":"^5.23.0","core-js":"^3.22.5","eslint":"^8.15.0","eslint-config-airbnb":"^19.0.4","eslint-config-airbnb-base":"^15.0.0","eslint-config-prettier":"^8.5.0","eslint-import-resolver-typescript":"^2.7.1","eslint-plugin-import":"^2.26.0","eslint-plugin-jest":"^26.2.1","eslint-plugin-jsx-a11y":"^6.5.1","eslint-plugin-node":"^11.1.0","eslint-plugin-prettier":"^4.0.0","eslint-plugin-promise":"^6.0.0","eslint-plugin-react":"^7.29.4","eslint-plugin-react-hooks":"^4.5.0","husky":"^8.0.1","jest":"^28.1.0","lint-staged":"^12.4.1","lodash":"^4.17.21","npm-run-all":"^4.1.5","prettier":"^2.6.2","rollup":"^2.73.0","rollup-plugin-babel":"^4.4.0","rollup-plugin-commonjs":"^10.1.0","rollup-plugin-node-resolve":"^5.2.0","rollup-plugin-progress":"^1.1.2","rollup-plugin-terser":"^7.0.2","ts-node":"^10.7.0","tslib":"^2.4.0","typescript":"^4.6.4"},"lint-staged":{"*.js":"eslint --cache --fix"},"gitHead":"42ea69df1c7a5d2afe9986f6a3047dac2aa565b0","bugs":{"url":"https://github.com/alesmenzel/nuclear-core/issues"},"homepage":"https://github.com/alesmenzel/nuclear-core#readme","_id":"@alesmenzel/nuclear-core@1.0.0","_nodeVersion":"16.15.0","_npmVersion":"8.5.5","dist":{"integrity":"sha512-wIDe67BQkOkFhKYCBd036zQnEf+0lbtoaD6GAsT7BdNnjSIku3rjMTvjATzMQjngiJjnbrGfQF4a1l844kerjA==","shasum":"3dede72ad39f440f729a50f242e345bdd7dfae53","tarball":"https://registry.npmjs.org/@alesmenzel/nuclear-core/-/nuclear-core-1.0.0.tgz","fileCount":23,"unpackedSize":30675,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQDLrhO4mVkvhUx7v9mph8wGrggPY2z4H9ku/7QTWPPtGwIgJLNTTlYXRedewBUF0zMDdl2U+74GeYVLW+RFWLVfaZg="}],"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v4.10.10\r\nComment: https://openpgpjs.org\r\n\r\nwsFzBAEBCAAGBQJigRYVACEJED1NWxICdlZqFiEECWMYAoorWMhJKdjhPU1b\r\nEgJ2VmpHuA//VWTqznm+A85K+E/8YwMxa1QICSZPebH9z61Of7ueO7RMpXMB\r\ntv6hlV8ZieaFgSV/N0sxvf8v2v+FAYkpYtIwzBDjjOvEtia+cEMcmlcc2nKQ\r\nULCSv6tW91HNlyNnM5fDLTqFGZz2C1339amSt/lBw22oH2jT/NB14DkTJBi8\r\nb5f7CPpvAcV/sv4U37n/PaWwabmx/LJPJ6xuHgGdJPVwXojex9tqD+mNe98W\r\nIK27pab6LJP7c4YI1kSt6hS7JA3NpOW1YAUU/nbG072YHttp4+FFGKG6pXvJ\r\nZOj7LaJhph1+Fu75XeMijHNWvm72zhph7Fkz/wg4bbZjHxBjPFP6bpMZCRDT\r\nYlqJ0HVz5tXtGv8DsDXSJmLSjg1o4acnfNBPW/JaULsRppyGzRZ4o9KIcRvU\r\nkzBOA0gyJH0i9OMoZ4vDUsN3+kCNKKME4tpA9PA1GwWbg3sSBEr6n3QuGSxA\r\n5ltIzkMtXCeaQ4x03olppWXdOvn/QFFHkE0DQZeMaTiEAtIRCo+5JCXJi/Cx\r\n0GYWP5VsShfy0ejR6riBlRRs0UcvsWdtA1KwZ9HtvPResjXZ0NaePCLf5Hes\r\n9dVEla948yu+wlAsQnl4KXWsJPsGK/ocbkq5Hh1xEe9iBrxoMpaKg5mPa2w3\r\nnmJ8Kp/dFrJHZbWk664tk8zJMqdX9aUSBkw=\r\n=HHZ8\r\n-----END PGP SIGNATURE-----\r\n"},"_npmUser":{"name":"alesmenzel","email":"alesmenzel@gmail.com"},"directories":{},"maintainers":[{"name":"alesmenzel","email":"alesmenzel@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/nuclear-core_1.0.0_1652626965245_0.02007991243843077"},"_hasShrinkwrap":false}},"time":{"created":"2022-05-15T15:02:45.136Z","1.0.0":"2022-05-15T15:02:45.638Z","modified":"2022-05-15T15:02:45.776Z"},"maintainers":[{"name":"alesmenzel","email":"alesmenzel@gmail.com"}],"description":"Framework agnostic state management library","homepage":"https://github.com/alesmenzel/nuclear-core#readme","repository":{"type":"git","url":"git+ssh://git@github.com/alesmenzel/nuclear-core.git"},"author":{"name":"Aleš Menzel","email":"alesmenzel@gmail.com","url":"https://github.com/alesmenzel"},"bugs":{"url":"https://github.com/alesmenzel/nuclear-core/issues"},"license":"MIT","readme":"# 🍱 Nuclear Core\n\nFramework agnostic reactive state management library.\n\n## Installation\n\n```bash\nnpm install @alesmenzel/nuclear-core\n```\n\n### Usage\n\n#### Atom\n\n`Atom` is the basic building block. It is a micro observable wrapper that emits an `update` event you can\nlisten on with `subscribe(...)`. The value of `Atom` can be anything. By default the `update` event will\nbe fired only when the value changes with strict value comparison `===`, but you can change the equality function\nto for example deepEqual if you want to with atom's options.\n\n```ts\nimport { atom } from \"@alesmenzel/nuclear-core\"\n\nconst listOfBears = atom(['🧸', '🐻', '🐻‍❄️'])\n// With options\n// const listOfBears = atom(['🧸', '🐻', '🐻‍❄️'], { equal: _.deepEqual })\nlistOfBears.value // -> ['🧸', '🐻', '🐻‍❄️']\nlistOfBears.get() // -> ['🧸', '🐻', '🐻‍❄️']\nlistOfBears.value = ['🐻‍❄️'] // -> ['🐻‍❄️']\nlistOfBears.set((bears) => [...bears, '🐻‍❄️']) // -> ['🐻‍❄️', '🐻‍❄️']\nlistOfBears.set(['🐻‍❄️', '🐻‍❄️', '🐻‍❄️']) // -> ['🐻‍❄️', '🐻‍❄️', '🐻‍❄️']\n\nconst onUpdate = (bears) => {\n  console.log(bears)\n}\nconst unsubscribe = listOfBears.subscribe(onUpdate)\nlistOfBears.unsubscribe(onUpdate) // or unsubscribe()\n```\n\n#### Derived Atom\n\n`DerivedAtom` is also an `Atom`, but its value is derived from the given list of `atoms` and a `select` function. Since `DerivedAtom` is also an `Atom`, you can do anything that you can do with `Atom` (see above).\n\n```ts\nimport { derive } from \"@alesmenzel/nuclear-core\"\n\nconst shoppingList = atom([{name: '🍎', qt: 10, price: 3}, {name: '🍐', qt: 2, price: 5}])\nconst grandTotal = derive([shoppingList], (list) => {\n  return list.reduce((acc, item) => acc + item.qt * item.price, 0)\n})\n\ngrandTotal.value // 40\n```\n\n### Custom Atom\n\nAtom by itself is pretty plain reactive container, would it be great if we could create a reactive model with helper methods like `addItemToCart(...)` or `increase/decreaseQuantity(...)`? I think it would.\n\n```ts\nimport { Atom, derive } from \"@alesmenzel/nuclear-core\"\n\ntype ShoppingListItem = {name: string, qt: number, price: number}\n\nclass ShoppingListAtom extends Atom<ShoppingListItem[]> {\n  addItemToCart(item: ShoppingListItem) {\n    this._value = [...this._value, item]\n  }\n\n  increaseQuantity(itemName, count = 1) {\n    // In a real project, you would probably want to store the items in a Map instead, so you can access them directly\n    this._value = this._value.map(item => item.name === itemName ? {...item, qt: item.qt + count} : item)\n  }\n}\n\nconst shoppingList = new ShoppingListAtom([{name: '🍎', qt: 10, price: 3}, {name: '🍐', qt: 2, price: 5}])\nconst grandTotal = derive([shoppingList], (list) => {\n  return list.reduce((acc, item) => acc + item.qt * item.price, 0)\n})\n\ngrandTotal.value // 40\n```\n\nYou could also create your custom `DeriveAtom` if you want to with helper functions like `getPriceInEuro(...)` for example.\n","readmeFilename":"README.md"}