Outcome Recipes
Scenario-based patterns for @aurelia/state and @aurelia/store so you can solve common state challenges quickly.
1. Optimistic updates with rollback
Steps
type AppState = { todos: Todo[] }; export const updateTodo = (state: AppState, { id, patch }: { id: string; patch: Partial<Todo> }) => { return { ...state, todos: state.todos.map(todo => todo.id === id ? { ...todo, ...patch } : todo) }; };const store = resolve(IStore<AppState>); async function saveTodo(todo: Todo) { const previous = structuredClone(todo); store.dispatch(updateTodo, { id: todo.id, patch: { title: todo.title } }); try { await api.save(todo); } catch (error) { store.dispatch(updateTodo, { id: todo.id, patch: previous }); notifications.error('Saving failed, changes were reverted'); throw error; } }
Checklist
2. Persist slices of state to IndexedDB
Steps
Checklist
3. Time-travel debugging / replay
Steps
Checklist
4. Micro-frontend friendly shared store
Steps
Checklist
5. Server-side pagination cache
Steps
Checklist
6. Live WebSocket feed reducer
Steps
Checklist
Reference material
Last updated
Was this helpful?