存儲工具
檢查命名狀態是否已保存,並查詢實際存儲和保存鍵信息。
hasRxState
指定名稱和存儲選項,以布林值確認該位置是否存在值。
ts
const exists = await hasRxState("count", {
storage: "sessionstorage",
});
// booleanfindRxStateStorages
僅傳遞名稱,將返回確認值的實際存儲後端,並且不會重複。自動保存的值也會在結果中返回為實際選定的後端。
ts
const storages = await findRxStateStorages("count");
// RxStateResolvedStorage[]
// 예: ["indexeddb", "localstorage", "sessionstorage"]getRxStateStorageInfo
始終返回確認的存儲位置的數組。如果相同的名稱存在於多個存儲或不同的名稱/storeName/keyPrefix 設置中,則將分別返回每個項目。可以將存儲選項作為第二個參數傳遞,以根據該條件進行查詢。
ts
const infos = await getRxStateStorageInfo("count");
const indexedDbInfos = await getRxStateStorageInfo("count", {
storage: "indexeddb",
});
// RxStateStorageInfo[]ts
interface RxStateStorageInfo {
key: string;
storageKey: string;
fullKey: string;
storage: RxStateResolvedStorage;
name: string;
storeName: string;
keyPrefix: string;
}storageKey 是傳遞給存儲的項目鍵,而 fullKey 是可以在像 localStorage 這樣的扁平鍵後端中查看的完整鍵。存儲將返回實際後端,而不是 auto。
實際操作測試
可以通過下面的按鈕將相同的測試鍵實際保存到多個存儲中,然後立即檢查三個 API 的返回值。
保存測試值
可以在多個存儲中保存相同的名稱,然後檢查三個工具的實際返回值。
查詢存儲
本地存儲
尚未執行。
Reducer 存儲工具
Reducer 也以相同的方式提供 hasRxReducer、findRxReducerStorages、getRxReducerStorageInfo。
ts
await hasRxReducer("cart", { storage: "sessionstorage" });
await findRxReducerStorages("cart");
await getRxReducerStorageInfo("cart");
await getRxReducerStorageInfo("cart", { storage: "indexeddb" });