Proposal: useObjectStore Hook
Nadie ha tomado este issue todavía.
Evaluación
- Dificultad
- 5/5
- Tiempo estimado
- Más de una semana
- Aptitud para principiantes
- 25/100
- Tipo de issue
- Nueva funcionalidad
- Claridad
- Bastante claro
- Estado de actividad
- Estancado
- Stack tecnológico
- typescript
- Área
- frontend
Línea de trabajo
Empieza con la interfaz propuesta LocalObjectStore y el ejemplo de useObjectStore en este issue. Resuelve la semántica de CRUD y migración, incluidas las firmas duplicadas de removeObject y las opciones cached/storage, y luego define pruebas para la persistencia y las actualizaciones antes de considerar completa la funcionalidad.
Escrito por el modelo de indexación a partir del texto del issue.
Descripción
Summary: A hook to simplify the creation and management of object dictionaries in LocalStorage, with a simple interface for CRUD operations. This would be useful for storing objects that populate List and Grid views, for example.
Details: This hook would create a LocalStorage entry containing a dictionary of objects as a JSON string, and it would provide easy access to methods for accessing, removing, and updating objects, as well as for performing object key migrations and batch-adding of new keys. A cached option could be provided.
Quite a few extensions store objects in this way and would benefit from a dedicated implementation, especially one that supports future development by providing methods for migrations (since the need/want to rename or delete keys is often unforeseen). Moreover, a standard implementation would allow additional features going forward, e.g. an option to use a JSON file in the extension's support directory rather than in LocalStorage, with minimal changes in extensions' code.
I'd be happy to work on this if there's support for it.
Proposed Interface:
interface LocalObjectStore<T> {
allObjects: () => T[];
// Add an object to the store, return the UUID for the object
addObject: (object: T) => string;
removeObject: (object: T) => void;
getObject: (id: string) => T | undefined;
setObject: (id: string, object: T) => void;
updateObject(id: string, updateFunction: (oldObject: T) => T): void;
removeObject: (id: string) => void;
clear: () => void;
// Rename a key within each object in the store, preserving the value
renameKey: (oldKey: string, newKey: string) => void;
// Add a key to each object in the store, using the provided function to generate the value
addKey: (key: string, valueFunction: (object: T) => any) => void;
// Delete a key from each object in the store
deleteKey: (key: string) => void;
}
Example:
import { Action, ActionPanel, Grid } from "@raycast/api";
import { useObjectStore } from '@raycast/utils';
interface EmojiItem {
name: string;
emoji: string;
description: string;
}
export default function Command() {
// Creates the store if it doesn't exist, or returns the existing store
const emojiStore = useObjectStore<EmojiItem>('emoji-items');
useEffect(() => {
emojiStore.addObject({
name: 'Smile',
emoji: '😀',
description: 'A happy face',
});
}, []);
// Loads items once upon first render, updates when items are added/removed/modified
const emojiItems = emojiStore.allObjects();
return(
<Grid>
{emojiItems.map((item) => (
<Grid.Item
key={item.id} // Auto-generated UUID
title={item.name}
subtitle={item.description}
content={item.emoji}
actions={
<ActionPanel>
<Action
title="Remove"
onAction={() => emojiStore.removeObject(item.id)}
/>
</ActionPanel>
}
/>
))}
</Grid>
);
}
- Lenguaje dominante
- TypeScript
- Estrellas
- 85
- Forks
- 19
- Merge medio
- 4 min
- PR fusionados (30 d)
- 1
Preparar el entorno
Este proyecto no incluye contenedor de desarrollo, Dockerfile ni guía de contribución, así que la configuración corre por tu cuenta: empieza por su README y consulta nuestra guía para la primera contribución para los pasos generales.
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Más de raycast/utils
-
Feature_Request: OAuthService refreshToken support extra queryQuizá libre de nuevo @thomaslombart la tomó hace 902 días y no hay ningún pull request abierto. Abierto
-
Dificultad 5/5 Más de una semana Aptitud para principiantes 25/100
-
Dificultad 5/5 Más de una semana Aptitud para principiantes 25/100
-
Dificultad 5/5 Más de una semana Aptitud para principiantes 25/100
-
Dificultad 5/5 Más de una semana Aptitud para principiantes 18/100
Todos los issues de raycast/utils
Issues similares
-
Add: Class TV ModaAbiertocheck:passed streams:add
Dificultad 1/5 Menos de una hora Aptitud para principiantes 65/100
Los mantenedores suelen responder en 1 día
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 62/100
GiganticMinecraft/seichi-playguide#183 ·
Los mantenedores suelen responder en 1 día
-
area: core complexity: easy impact: medium
Dificultad 2/5 1-3 horas Aptitud para principiantes 86/100
ueberdosis/tiptap#8668 ·
Los mantenedores suelen responder en 1 día
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 78/100
Los mantenedores suelen responder en 1 día
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 68/100
longbridge/nsh#804 ·
Los mantenedores suelen responder en 1 día