Skip to content

Commit b2f17f4

Browse files
committed
refactor(async-list): rename loading more context flag
1 parent 253a586 commit b2f17f4

4 files changed

Lines changed: 25 additions & 20 deletions

File tree

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@zag-js/async-list": patch
3+
---
4+
5+
Rename the internal load-more state flag to `isLoadingMore` for consistency with the public API.

packages/machines/async-list/src/async-list.connect.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ export function connect<Item, Filter, Sorting, Cursor>(
66
const { state, context, send, prop } = service
77

88
const isLoading = state.matches("loading", "sorting")
9-
const isLoadingMore = state.matches("loading") && context.get("isLoadMore")
9+
const isLoadingMore = state.matches("loading") && context.get("isLoadingMore")
1010
const isSorting = state.matches("sorting")
1111

1212
const items = context.get("items")

packages/machines/async-list/src/async-list.machine.ts

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ export const machine = createMachine<AsyncListSchema<any, any, any, any>>({
2525
error: bindable<any>(() => ({
2626
defaultValue: undefined,
2727
})),
28-
isLoadMore: bindable<boolean>(() => ({
28+
isLoadingMore: bindable<boolean>(() => ({
2929
defaultValue: false,
3030
})),
3131
}
@@ -52,7 +52,7 @@ export const machine = createMachine<AsyncListSchema<any, any, any, any>>({
5252
RELOAD: {
5353
target: "loading",
5454
reenter: true,
55-
actions: ["clearItems", "clearIsLoadMore"],
55+
actions: ["clearItems", "clearIsLoadingMore"],
5656
},
5757
},
5858

@@ -64,22 +64,22 @@ export const machine = createMachine<AsyncListSchema<any, any, any, any>>({
6464
LOAD_MORE: {
6565
guard: "hasCursor",
6666
target: "loading",
67-
actions: ["setIsLoadMore"],
67+
actions: ["setIsLoadingMore"],
6868
},
6969
SORT: [
7070
{
7171
guard: "hasSortFn",
7272
target: "sorting",
73-
actions: ["setSorting", "clearCursor", "clearIsLoadMore", "performSort"],
73+
actions: ["setSorting", "clearCursor", "clearIsLoadingMore", "performSort"],
7474
},
7575
{
7676
target: "loading",
77-
actions: ["setSorting", "clearCursor", "clearIsLoadMore"],
77+
actions: ["setSorting", "clearCursor", "clearIsLoadingMore"],
7878
},
7979
],
8080
FILTER: {
8181
target: "loading",
82-
actions: ["setFilter", "clearCursor", "clearIsLoadMore"],
82+
actions: ["setFilter", "clearCursor", "clearIsLoadingMore"],
8383
},
8484
},
8585
},
@@ -102,7 +102,7 @@ export const machine = createMachine<AsyncListSchema<any, any, any, any>>({
102102
FILTER: {
103103
reenter: true,
104104
target: "loading",
105-
actions: ["setFilter", "clearCursor", "clearIsLoadMore"],
105+
actions: ["setFilter", "clearCursor", "clearIsLoadingMore"],
106106
},
107107
},
108108
},
@@ -122,22 +122,22 @@ export const machine = createMachine<AsyncListSchema<any, any, any, any>>({
122122
},
123123
FILTER: {
124124
target: "loading",
125-
actions: ["setFilter", "clearCursor", "cancelSort", "clearIsLoadMore"],
125+
actions: ["setFilter", "clearCursor", "cancelSort", "clearIsLoadingMore"],
126126
},
127127
RELOAD: {
128128
target: "loading",
129-
actions: ["clearItems", "cancelSort", "clearIsLoadMore"],
129+
actions: ["clearItems", "cancelSort", "clearIsLoadingMore"],
130130
},
131131
SORT: [
132132
{
133133
guard: "hasSortFn",
134134
target: "sorting",
135135
reenter: true,
136-
actions: ["setSorting", "clearCursor", "cancelSort", "clearIsLoadMore", "performSort"],
136+
actions: ["setSorting", "clearCursor", "cancelSort", "clearIsLoadingMore", "performSort"],
137137
},
138138
{
139139
target: "loading",
140-
actions: ["setSorting", "clearCursor", "cancelSort", "clearIsLoadMore"],
140+
actions: ["setSorting", "clearCursor", "cancelSort", "clearIsLoadingMore"],
141141
},
142142
],
143143
},
@@ -160,12 +160,12 @@ export const machine = createMachine<AsyncListSchema<any, any, any, any>>({
160160
send({ type: "RELOAD" })
161161
},
162162

163-
setIsLoadMore({ context }) {
164-
context.set("isLoadMore", true)
163+
setIsLoadingMore({ context }) {
164+
context.set("isLoadingMore", true)
165165
},
166166

167-
clearIsLoadMore({ context }) {
168-
context.set("isLoadMore", false)
167+
clearIsLoadingMore({ context }) {
168+
context.set("isLoadingMore", false)
169169
},
170170

171171
performFetch({ context, prop, refs, send, event }) {
@@ -176,19 +176,19 @@ export const machine = createMachine<AsyncListSchema<any, any, any, any>>({
176176
const seq = refs.get("seq") + 1
177177
refs.set("seq", seq)
178178

179-
const isLoadMore = context.get("isLoadMore")
179+
const isLoadingMore = context.get("isLoadingMore")
180180

181181
const loadFn = prop("load")
182182
loadFn({
183183
signal: abort?.signal,
184184
items: context.get("items"),
185-
cursor: isLoadMore ? context.get("cursor") : null,
185+
cursor: isLoadingMore ? context.get("cursor") : null,
186186
filter: event.filter ?? context.get("filter"),
187187
sorting: event.sorting ?? context.get("sorting"),
188188
})
189189
.then(({ items, cursor }) => {
190190
if (seq !== refs.get("seq")) return
191-
send({ type: "SUCCESS", items, cursor, append: isLoadMore })
191+
send({ type: "SUCCESS", items, cursor, append: isLoadingMore })
192192
})
193193
.catch((error) => {
194194
if (seq !== refs.get("seq")) return

packages/machines/async-list/src/async-list.types.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ export interface AsyncListSchema<Item, Filter, Sorting, Cursor> {
8989
cursor?: Cursor | undefined
9090
sorting?: Sorting | undefined
9191
error?: Error | undefined
92-
isLoadMore: boolean
92+
isLoadingMore: boolean
9393
}
9494
refs: {
9595
abort: AbortController | null

0 commit comments

Comments
 (0)