{"_id":"@90pixel/zustand.macro","_rev":"4-d26fbdfebccc0a0890062362dbc8c6d4","name":"@90pixel/zustand.macro","dist-tags":{"latest":"1.1.4"},"versions":{"1.1.4":{"name":"@90pixel/zustand.macro","version":"1.1.4","author":{"name":"Serkan Bircan","email":"serkanbircan21@yandex.com","url":"https://github.com/fasetto"},"homepage":"https://github.com/90pixel/zustand-macro","bugs":{"url":"https://github.com/90pixel/zustand-macro/issues"},"license":"MIT","main":"build/index.macro.js","types":"build/index.macro.d.ts","keywords":["babel-macro","babel-plugin-macros","zustand"],"scripts":{"build":"tsc","test":"jest","test:update":"jest --updateSnapshot"},"dependencies":{"@babel/helper-module-imports":"^7.14.5","babel-plugin-macros":"^3.1.0"},"devDependencies":{"@babel/core":"^7.14.6","@types/babel-plugin-macros":"^2.8.5","@types/babel-plugin-tester":"^9.0.4","@types/jest":"^26.0.24","@types/node":"^16.3.3","babel-plugin-tester":"^10.1.0","jest":"^27.0.6","ts-jest":"^27.0.3","typescript":"^4.3.5"},"peerDependencies":{"babel-plugin-macros":"^3.1.0"},"babelMacros":{"zustandMacro":{"useStore":{"importName":"useShallowStore","importSource":"hooks"}}},"gitHead":"b6430cb25801c6df083f88e96796cecf9e575f4f","description":"<div align=\"center\"> <h1>zustand.macro</h1> <img alt=\"babel-macro\" src=\"https://img.shields.io/badge/-babel--macro-blueviolet\" /> <a href=\"https://www.npmjs.com/package/@90pixel/zustand.macro\"> <img alt=\"npm\" src=\"https://img.shields.io/npm/v/@90pixel/zus","_id":"@90pixel/zustand.macro@1.1.4","_nodeVersion":"14.17.3","_npmVersion":"6.14.13","dist":{"integrity":"sha512-mXH3y7ncl7nUugJcsUeIrzO4R8gCuyY5iP2CQXz+aw61FPYf1VPNFZaFayAwXcuJBLuTE5jQn4lFuOkFJa7XZw==","shasum":"c5e40b49beed572d4967706648c2f6241cf24ae7","tarball":"https://registry.npmjs.org/@90pixel/zustand.macro/-/zustand.macro-1.1.4.tgz","fileCount":9,"unpackedSize":11075,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.13\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJg/uufCRA9TVsSAnZWagAA8f0P+QFsSQuCjp/msgtvJ5RW\nd19ojVs7OfPkuubsI+fPGGL2KugGIRXlOydIYdUyv6j3CdziWB4RNhq5G5QR\n+glBd9d56LnBfQ2D2X9XCbV+w05o1cMxNtSltpTWjdjFfszG0oR2Pk/Do5QD\nuijgiCp6yKyccc+YTIZCf7Ms5gUovgrslDX6MLZ/nibcEWJGrZOfdQLZPog4\nkPIgz75n7bYbV/EtnY9/bgRQ+nmUNbS6DThxQhDT9yY8+6bndOoAEDSAdjyx\n2to6p9BhImZ/0n5pNzeON+hhMb7lNbStg+PL45CtmwU2a6mIi0uG29H85Xlk\nCCX8Cc/ZtCbdnJkKHu0zMghDMZJvWyeo9ePQ5at7er73gn+PyprgYwkLiLUU\n3t5ujYCAliJ6erNrN1R9TMijaxCVFoUxAq99BYoyhFeO/IktyGBYjep2KTGT\nTHKmjd2gJ4T4LP1WTs4w4+Q7Ft/yFtsje3v5OCNx/LOxXzcQcVuwIKmL5PLA\nr7LFiX05O+v8AbzaAco9za7Ni1N1NOeP2tGUwtg6CZYi6guAONUA0yZQbJ7p\nJ/t5YdPanHlcnLHqQBgGmTDzG1uxtrmwGZbaflimtyNpDOOFNpYO2Hf418mC\nkTv7NdnmKpnkgMZFkVKv562a6PjuXzxqn/rIi666Cga1kNpjDhktLbo/drm/\nHryp\r\n=Cdtx\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEYCIQCpqV0dH7xwVk+ibaWIYxGK1RxFej3ezjUZkDSEQXsTEQIhAIICla9H2jn+rOBEN40ADMl9Sa6KVVk62p0QvUihYfjm"}]},"_npmUser":{"name":"fasetto","email":"serkanbircan21@yandex.com"},"directories":{},"maintainers":[{"name":"fasetto","email":"serkanbircan21@yandex.com"},{"name":"birkoo","email":"e.birkankervan@gmail.com"},{"name":"fatihcandev","email":"contact@fatihcan.dev"},{"name":"aydogansari","email":"aydogansari@hotmail.com"},{"name":"brkcrdk","email":"brkcrdk@gmail.com"},{"name":"muhittinozer","email":"muhittin@90pixel.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/zustand.macro_1.1.4_1627319199029_0.24854974800259888"},"_hasShrinkwrap":false}},"time":{"created":"2021-07-26T17:06:38.989Z","1.1.4":"2021-07-26T17:06:39.177Z","modified":"2023-07-20T14:57:46.236Z"},"maintainers":[{"email":"contact@tugaydemirel.com","name":"tugaydemirel"},{"email":"muhittin@90pixel.com","name":"muhittinozer"},{"email":"brkcrdk@gmail.com","name":"brkcrdk"},{"email":"aydogansari@hotmail.com","name":"aydogansari"}],"description":"<div align=\"center\"> <h1>zustand.macro</h1> <img alt=\"babel-macro\" src=\"https://img.shields.io/badge/-babel--macro-blueviolet\" /> <a href=\"https://www.npmjs.com/package/@90pixel/zustand.macro\"> <img alt=\"npm\" src=\"https://img.shields.io/npm/v/@90pixel/zus","homepage":"https://github.com/90pixel/zustand-macro","keywords":["babel-macro","babel-plugin-macros","zustand"],"author":{"name":"Serkan Bircan","email":"serkanbircan21@yandex.com","url":"https://github.com/fasetto"},"bugs":{"url":"https://github.com/90pixel/zustand-macro/issues"},"license":"MIT","readme":"<div align=\"center\">\n<h1>zustand.macro</h1>\n<img alt=\"babel-macro\" src=\"https://img.shields.io/badge/-babel--macro-blueviolet\" />\n<a href=\"https://www.npmjs.com/package/@90pixel/zustand.macro\">\n<img alt=\"npm\" src=\"https://img.shields.io/npm/v/@90pixel/zustand.macro?label=%4090pixel%2Fzustand.macro\" />\n</a>\n<a href=\"https://www.npmjs.com/package/@90pixel/zustand.macro\">\n<img alt=\"npm\" src=\"https://img.shields.io/npm/dm/@90pixel/zustand.macro\" />\n</a>\n<img alt=\"NPM\" src=\"https://img.shields.io/npm/l/@90pixel/zustand.macro\" />\n</div>\n\n## Getting Started\n\nThis package is designed to improve the **Developer Experience (DX)** when working with `zustand` to manage the state in React applications.\n\n## Table of Contents\n\n-   [The Problem](#the-problem)\n    -   [What if we need more then one prop?](#what-if-we-need-more-than-one-prop)\n-   [Solution](#solution)\n-   [Installation](#installation)\n    -   [Updating your babel config](#updating-your-babel-config)\n    -   [Adding useShallowStore hook](#adding-useshallowstore-hook)\n    -   [Configuration](#configuration)\n\n<br />\n\n## The Problem\n\nLets say we have a store like this;\n\n```js\nimport create from \"zustand\";\n\nconst useStore = create((set) => ({\n    count: 0,\n    incrementCount: () => set((state) => ({ count: state.count + 1 })),\n    decrementCount: () => set((state) => ({ count: state.count - 1 })),\n}));\n```\n\nIf we use this store like this;\n\n```js\nexport default function CounterA() {\n    const { count } = usestore();\n    // ...\n}\n```\n\nWe will encounter re-rendering issues. The `<CounterA />` component will re-render when any of the properties changed in store.\n\nWe will need to use the store like this, to avoid re-rendering issues.\n\n```js\nexport default function CounterA() {\n    const count = useStore((state) => state.count);\n    // ...\n}\n```\n\n### What if we need more than one prop?\n\nNow we need to use the store with shallow equality function.\n\n```js\nimport shallow from \"zustand/shallow\";\n\nexport default function CounterA() {\n    const { count, incrementCount, decrementCount } = useStore(\n        (s) => ({\n            count: s.count,\n            incrementCount: s.incrementCount,\n            decrementCount: s.decrementCount,\n        }),\n        shallow\n    );\n    // ...\n}\n```\n\nWe are repeating a lot.\n\n## Solution\n\nUsing `babel-plugin-macros` we can turn this code into this below, at `compile-time`.\n\n```js\nimport useStoreMacro from \"@90pixel/zustand.macro\";\n\nconst {\n  count,\n  decrementCount,\n  incrementCount,\n} = useStoreMacro();\n\n      ↓ ↓ ↓ ↓ ↓ ↓\n\n// You can replace this with your own hook. Look at the Configuration section to learn more about it.\nimport { useShallowStore as _useShallowStore } from \"hooks\";\n\nconst {\n  count,\n  decrementCount,\n  incrementCount,\n} = _useShallowStore((s) => ({\n  count: s.count,\n  decrementCount: s.decrementCount,\n  incrementCount: s.incrementCount,\n}));\n```\n\n## Installation\n\nInstallation of the dependencies.\n\n```term\nnpm install --save-dev @90pixel/zustand.macro babel-plugin-macros\n```\n\nor using yarn\n\n```term\nyarn add -D @90pixel/zustand.macro babel-plugin-macros\n```\n\n### Updating Your Babel config\n\nYou must add the `babel-plugin-macros` plugin into your babel plugin list.\n\n```js\n{\n  // ...\n  \"plugins\": [\n    // ...other plugins\n\n    // This must be added\n    \"macros\"\n  ]\n}\n```\n\n### Adding useShallowStore hook\n\nAdd this hook into your custom hooks.\n\n```js\nimport shallow from \"zustand/shallow\";\n// Your store..\nimport { useStore } from \"store\";\n\nexport default function useShallowStore(selector, equalityFn = shallow) {\n    return useStore(selector, equalityFn);\n}\n```\n\n### Configuration\n\nBy default when you import the macro, the import statement will be deleted at compile-time.\n\nShallow store implementation will be added instead.\n\n```js\nimport useStoreMacro from \"@90pixel/zustand.macro\";\n      ↓ ↓ ↓ ↓ ↓ ↓\nimport { useShallowStore as _useShallowStore } from \"hooks\";\n```\n\nAs you can see, import name `(useShallowStore)` and the import source `(import .. from 'hooks')` is hard coded.\n\nYou can change these in your `package.json` file.\n\n```json\n{\n  ...\n  \"babelMacros\": {\n\n    \"zustandMacro\": {\n      \"useStore\": {\n        \"importName\": \"useShallowStore\",\n        \"importSource\": \"hooks\"\n      }\n    }\n  }\n}\n```\n\n\n**You are ready to go now.**\n","readmeFilename":"README.md"}