@myriadcodelabs/uiflow 0.2.1 → 0.2.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -168,31 +168,37 @@ type Props = {
|
|
|
168
168
|
```ts
|
|
169
169
|
import { defineFlow } from "@myriadcodelabs/uiflow";
|
|
170
170
|
|
|
171
|
-
type
|
|
171
|
+
type DomainData = {
|
|
172
172
|
deckId: string;
|
|
173
|
+
};
|
|
174
|
+
|
|
175
|
+
type InternalData = {
|
|
173
176
|
cards: CardState[];
|
|
174
177
|
activeCardId: string | null;
|
|
175
178
|
};
|
|
176
179
|
|
|
177
|
-
export const flow = defineFlow<
|
|
180
|
+
export const flow = defineFlow<DomainData, InternalData>(
|
|
178
181
|
{
|
|
179
182
|
fetchCards: {
|
|
180
|
-
input: (
|
|
181
|
-
action: async ({ deckId },
|
|
183
|
+
input: (domain) => ({ deckId: domain.deckId }),
|
|
184
|
+
action: async ({ deckId }, _domain, internal) => {
|
|
182
185
|
const cards = await fetchCardsAction(deckId);
|
|
183
|
-
|
|
184
|
-
|
|
186
|
+
internal.cards = cards ?? [];
|
|
187
|
+
internal.activeCardId = null;
|
|
185
188
|
return { ok: true };
|
|
186
189
|
},
|
|
187
190
|
onOutput: () => "study",
|
|
188
191
|
},
|
|
189
192
|
|
|
190
193
|
study: {
|
|
191
|
-
input: (
|
|
194
|
+
input: (_domain, internal) => ({
|
|
195
|
+
cards: internal.cards,
|
|
196
|
+
activeCardId: internal.activeCardId,
|
|
197
|
+
}),
|
|
192
198
|
view: StudyView,
|
|
193
|
-
onOutput: (
|
|
199
|
+
onOutput: (_domain, internal, output, events) => {
|
|
194
200
|
if (output.action === "flip") {
|
|
195
|
-
|
|
201
|
+
internal.activeCardId = output.cardId;
|
|
196
202
|
return "study";
|
|
197
203
|
}
|
|
198
204
|
if (output.action === "next") {
|
|
@@ -202,7 +208,13 @@ export const flow = defineFlow<Data>(
|
|
|
202
208
|
},
|
|
203
209
|
},
|
|
204
210
|
},
|
|
205
|
-
{
|
|
211
|
+
{
|
|
212
|
+
start: "fetchCards",
|
|
213
|
+
createInternalData: () => ({
|
|
214
|
+
cards: [],
|
|
215
|
+
activeCardId: null,
|
|
216
|
+
}),
|
|
217
|
+
}
|
|
206
218
|
);
|
|
207
219
|
```
|
|
208
220
|
|