Skip to content

Commit 5436c47

Browse files
Amaljith-Kajmaln
andauthored
Added support for default values (#22)
* Added support for default values * Added docs --------- Co-authored-by: Ajmal Noushad <[email protected]>
1 parent 4be46d0 commit 5436c47

File tree

5 files changed

+17
-3
lines changed

5 files changed

+17
-3
lines changed

README.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,8 @@ module.exports = {
4141

4242
## Available plugins
4343

44-
- [zustand-pick](https://github.com/bigbinary/babel-preset-neeto/blob/e8433f3a019cf96dcb0ea29d46393bcf5868406d/docs/zustand-pick.md)
45-
- [zustand-pick-from](https://github.com/bigbinary/babel-preset-neeto/blob/e8433f3a019cf96dcb0ea29d46393bcf5868406d/docs/zustand-pick-from.md)
44+
- [zustand-pick](https://github.com/bigbinary/babel-preset-neeto/blob/main/docs/zustand-pick.md)
45+
- [zustand-pick-from](https://github.com/bigbinary/babel-preset-neeto/blob/main/docs/zustand-pick-from.md)
4646

4747
## Other links
4848

docs/zustand-pick.md

+3
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,9 @@ const { order, setOrder } = useGlobalStore.pick();
7575
// picks `id` and `user` from inside store.order
7676
const { id, user } = useGlobalStore.pick("order");
7777

78+
// supports default values
79+
const { user = {} } = useGlobalStore.pick();
80+
7881
// picks `quantity` of dynamically obtained item of id `itemId`
7982
const { quantity } = useGlobalStore.pick(["order", "items", itemId]);
8083

src/plugins/zustand-pick/constants.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,9 @@ const PICK_STRICT_PATTERN = {
5353
matches({
5454
type: "ObjectProperty",
5555
method: false,
56-
value: { type: "Identifier" },
56+
value: {
57+
type: includes(__, ["Identifier", "AssignmentPattern"]),
58+
},
5759
})
5860
),
5961
},
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
const { orderId = "#1001", customer = {} } = useGlobalStore.pick();
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import { shallow } from "zustand/shallow";
2+
const { orderId = "#1001", customer = {} } = useGlobalStore(
3+
store => ({
4+
orderId: store["orderId"],
5+
customer: store["customer"],
6+
}),
7+
shallow
8+
);

0 commit comments

Comments
 (0)