Skip to content

Instantly share code, notes, and snippets.

@mppapi
mppapi / extendable_xstate_machine.md
Created May 5, 2025 21:28
xstate extendable machine

Below is a pragmatic “inherit‑from‑a‑base‑machine” recipe that works with XState v5 today.
The key idea is that you separate structure (the config object that declares states, transitions, context, …) from implementation (actions, guards, actors, delays).


1  Create a plain, reusable base config

// alarmConfig.ts
import { TypegenDisable } from 'xstate';     // if you are not using typegen
In iOS development, when working with the camera to capture images, you generally have control over the image format you want to capture. To ensure that the camera captures an image in JPEG format, you need to set the appropriate settings and configurations. Here's how you can do that:
1. **AVCaptureSession Configuration:**
Use the `AVCaptureSession` class to manage the flow of data from the input (camera) to the output (image or video). When setting up your `AVCaptureSession`, you can configure the output format using `AVCapturePhotoOutput`.
2. **AVCapturePhotoOutput Settings:**
To capture images in JPEG format, you need to set the desired photo settings for the `AVCapturePhotoOutput` instance. Specifically, you'll be using the `outputSettings` property of `AVCapturePhotoSettings`.
```swift
import AVFoundation
// Function that returns a promise when the first event fires
function waitForEvent1() {
return new Promise((resolve) => {
// Replace 'event1' with the actual event name you are waiting for
document.addEventListener('event1', () => {
resolve();
}, { once: true });
});
}
import React, { useState, useRef, useEffect } from 'react';
import { View, TextInput, FlatList, StyleSheet } from 'react-native';
import { SearchBar, Overlay } from 'react-native-elements';
const SearchComponent = ({ data, onSearch }) => {
const [searchTerm, setSearchTerm] = useState('');
const [isVisible, setIsVisible] = useState(false);
const searchRef = useRef(null);
useEffect(() => {
import { useQuery, useMutation, queryCache } from 'react-query';
const fetchTodos = async () => {
const response = await fetch('https://my-api.com/todos');
return response.json();
};
const addTodo = async (todo) => {
const response = await fetch('https://my-api.com/todos', {
method: 'POST',
import React, { useState } from 'react';
import { View, Text } from 'react-native';
import { Tab, Tabs } from 'react-native-elements';
import { withTheme } from 'react-native-elements';
import { makeStyles } from 'react-native-style-tachyons';
const FirstRoute = () => (
<View style={{ flex: 1, justifyContent: 'center', alignItems: 'center' }}>
<Text>First Route</Text>
</View>