Proposal: useObjectStore Hook
まだ誰も着手していません。
評価
- 難易度
- 5/5
- 見積もり時間
- 1週間以上
- 初心者へのやさしさ
- 25/100
- issue の種類
- 機能追加
- 明瞭さ
- おおむね明確
- 活発さ
- 停滞
- 技術スタック
- typescript
- 領域
- frontend
調査の方向性
この issue の提案された LocalObjectStore インターフェースと useObjectStore の例から始めます。重複する removeObject シグネチャと cached/storage オプションを含む CRUD と移行のセマンティクスを確定し、機能が完成したと見なす前に、永続化と更新のテストを定義します。
索引モデルが issue の本文から書いたものです。
説明
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>
);
}
- 主要言語
- TypeScript
- スター
- 85
- フォーク
- 19
- 平均マージ
- 8分
- マージ済み PR(30日)
- 2
環境構築
このプロジェクトには開発コンテナ、Dockerfile、コントリビューションガイドがありません。まず README を読み、一般的な手順ははじめてのコントリビューションガイドを参照してください。
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
raycast/utils のほかの issue
-
Feature_Request: OAuthService refreshToken support extra query再び着手できるかも @thomaslombart が 893 日前に担当しましたが、オープン中のプルリクエストはありません。 オープン
-
難易度 5/5 1週間以上 初心者へのやさしさ 25/100
-
難易度 5/5 1週間以上 初心者へのやさしさ 25/100
-
難易度 5/5 1週間以上 初心者へのやさしさ 25/100
-
難易度 5/5 1週間以上 初心者へのやさしさ 18/100
似ている issue
-
難易度 2/5 1〜3時間 初心者へのやさしさ 68/100
awesome-dsh-plugin/awesome-dsh-plugin#9184 ·
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 75/100
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 85/100
farion1231/cc-switch#8829 ·
メンテナーはふだん 1 日以内に返信
-
[core-client] Remove unused hand-maintained transport helpers after the definition-table cutoverオープンdoc-audit enhancement
難易度 2/5 1〜3時間 初心者へのやさしさ 88/100
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 85/100