Skip to content

Commit

Permalink
refactor(core): move actions to internal exports
Browse files Browse the repository at this point in the history
  • Loading branch information
tien committed Nov 24, 2024
1 parent ae8c1c4 commit ec673a7
Show file tree
Hide file tree
Showing 20 changed files with 110 additions and 40 deletions.
7 changes: 7 additions & 0 deletions .changeset/kind-shrimps-tan.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
"@reactive-dot/react": patch
"@reactive-dot/core": patch
"@reactive-dot/vue": patch
---

Moved core actions to internal exports.
5 changes: 3 additions & 2 deletions packages/core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,9 @@
"exports": {
".": "./build/index.js",
"./wallets.js": "./build/wallets/index.js",
"./internal/maths.js": "./build/maths/index.js",
"./internal.js": "./build/internal.js"
"./internal.js": "./build/internal.js",
"./internal/actions.js": "./build/actions/index.js",
"./internal/maths.js": "./build/maths/index.js"
},
"scripts": {
"dev": "tsc --build --watch",
Expand Down
9 changes: 9 additions & 0 deletions packages/core/src/actions/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
export { aggregateWallets } from "./aggregate-wallets.js";
export { connectWallet } from "./connect-wallet.js";
export { disconnectWallet } from "./disconnect-wallet.js";
export { getAccounts } from "./get-accounts.js";
export { getBlock, unstable_getBlockExtrinsics } from "./get-block.js";
export { getClient } from "./get-client.js";
export { getConnectedWallets } from "./get-connected-wallets.js";
export { initializeWallets } from "./initialize-wallets.js";
export { preflight, query } from "./query.js";
72 changes: 63 additions & 9 deletions packages/core/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,3 @@
export { aggregateWallets } from "./actions/aggregate-wallets.js";
export { connectWallet } from "./actions/connect-wallet.js";
export { disconnectWallet } from "./actions/disconnect-wallet.js";
export { getAccounts } from "./actions/get-accounts.js";
export { getBlock, unstable_getBlockExtrinsics } from "./actions/get-block.js";
export { getClient } from "./actions/get-client.js";
export { getConnectedWallets } from "./actions/get-connected-wallets.js";
export { initializeWallets } from "./actions/initialize-wallets.js";
export { preflight, query } from "./actions/query.js";
export type { AsyncValue } from "./async-state.js";
export type { ChainId } from "./chains.js";
export { defineConfig, type ChainConfig, type Config } from "./config.js";
Expand All @@ -15,3 +6,66 @@ export { Query } from "./query-builder.js";
export type { Register } from "./register.js";
export { Storage } from "./storage.js";
export { idle, pending } from "./symbols.js";

export {
/**
* @deprecated Use the "/internal/actions.js" subpath export instead.
*/
aggregateWallets,
} from "./actions/aggregate-wallets.js";
export {
/**
* @deprecated Use the "/internal/actions.js" subpath export instead.
*/
connectWallet,
} from "./actions/connect-wallet.js";
export {
/**
* @deprecated Use the "/internal/actions.js" subpath export instead.
*/
disconnectWallet,
} from "./actions/disconnect-wallet.js";
export {
/**
* @deprecated Use the "/internal/actions.js" subpath export instead.
*/
getAccounts,
} from "./actions/get-accounts.js";
export {
/**
* @deprecated Use the "/internal/actions.js" subpath export instead.
*/
getBlock,
/**
* @deprecated Use the "/internal/actions.js" subpath export instead.
*/
unstable_getBlockExtrinsics,
} from "./actions/get-block.js";
export {
/**
* @deprecated Use the "/internal/actions.js" subpath export instead.
*/
getClient,
} from "./actions/get-client.js";
export {
/**
* @deprecated Use the "/internal/actions.js" subpath export instead.
*/
getConnectedWallets,
} from "./actions/get-connected-wallets.js";
export {
/**
* @deprecated Use the "/internal/actions.js" subpath export instead.
*/
initializeWallets,
} from "./actions/initialize-wallets.js";
export {
/**
* @deprecated Use the "/internal/actions.js" subpath export instead.
*/
preflight,
/**
* @deprecated Use the "/internal/actions.js" subpath export instead.
*/
query,
} from "./actions/query.js";
3 changes: 2 additions & 1 deletion packages/react/src/hooks/use-accounts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ import { internal_useChainId } from "./use-chain-id.js";
import { chainSpecDataAtom } from "./use-chain-spec-data.js";
import { useConfig } from "./use-config.js";
import { connectedWalletsAtom } from "./use-wallets.js";
import { getAccounts, type ChainId, type Config } from "@reactive-dot/core";
import { type ChainId, type Config } from "@reactive-dot/core";
import { getAccounts } from "@reactive-dot/core/internal/actions.js";
import { useAtomValue } from "jotai";
import { atomWithObservable } from "jotai/utils";

Expand Down
3 changes: 2 additions & 1 deletion packages/react/src/hooks/use-block.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ import type { ChainHookOptions } from "./types.js";
import { internal_useChainId } from "./use-chain-id.js";
import { clientAtom } from "./use-client.js";
import { useConfig } from "./use-config.js";
import { type ChainId, type Config, getBlock } from "@reactive-dot/core";
import { type ChainId, type Config } from "@reactive-dot/core";
import { getBlock } from "@reactive-dot/core/internal/actions.js";
import { useAtomValue } from "jotai";
import { atomWithObservable } from "jotai/utils";
import { from } from "rxjs";
Expand Down
3 changes: 2 additions & 1 deletion packages/react/src/hooks/use-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ import type { ChainHookOptions } from "./types.js";
import { internal_useChainId } from "./use-chain-id.js";
import { useConfig } from "./use-config.js";
import type { ChainId, Config } from "@reactive-dot/core";
import { getClient, ReactiveDotError } from "@reactive-dot/core";
import { ReactiveDotError } from "@reactive-dot/core";
import { getClient } from "@reactive-dot/core/internal/actions.js";
import { useAtomValue } from "jotai";
import { atom } from "jotai";

Expand Down
10 changes: 2 additions & 8 deletions packages/react/src/hooks/use-query.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,7 @@ import { internal_useChainId } from "./use-chain-id.js";
import { useConfig } from "./use-config.js";
import { useQueryRefresher } from "./use-query-refresher.js";
import { typedApiAtom } from "./use-typed-api.js";
import {
type ChainId,
type Config,
idle,
preflight,
query,
Query,
} from "@reactive-dot/core";
import { type ChainId, type Config, idle, Query } from "@reactive-dot/core";
import {
type ChainDescriptorOf,
type Falsy,
Expand All @@ -23,6 +16,7 @@ import {
type QueryInstruction,
stringify,
} from "@reactive-dot/core/internal.js";
import { preflight, query } from "@reactive-dot/core/internal/actions.js";
import { type Atom, atom, useAtomValue, type WritableAtom } from "jotai";
import { atomWithObservable, atomWithRefresh } from "jotai/utils";
import { useMemo } from "react";
Expand Down
2 changes: 1 addition & 1 deletion packages/react/src/hooks/use-wallet-connector.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { useAsyncAction } from "./use-async-action.js";
import { useConfig } from "./use-config.js";
import { walletsAtom } from "./use-wallets.js";
import { connectWallet } from "@reactive-dot/core";
import { connectWallet } from "@reactive-dot/core/internal/actions.js";
import type { Wallet } from "@reactive-dot/core/wallets.js";
import { useAtomCallback } from "jotai/utils";
import { useCallback } from "react";
Expand Down
2 changes: 1 addition & 1 deletion packages/react/src/hooks/use-wallet-disconnector.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { useAsyncAction } from "./use-async-action.js";
import { useConfig } from "./use-config.js";
import { walletsAtom } from "./use-wallets.js";
import { disconnectWallet } from "@reactive-dot/core";
import { disconnectWallet } from "@reactive-dot/core/internal/actions.js";
import type { Wallet } from "@reactive-dot/core/wallets.js";
import { useAtomCallback } from "jotai/utils";
import { useCallback } from "react";
Expand Down
2 changes: 1 addition & 1 deletion packages/react/src/hooks/use-wallets-initializer.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { useWallets } from "./use-wallets.js";
import {
idle,
initializeWallets,
pending,
type AsyncValue,
type ReactiveDotError,
} from "@reactive-dot/core";
import { initializeWallets } from "@reactive-dot/core/internal/actions.js";
import { useCallback, useState } from "react";

/**
Expand Down
4 changes: 2 additions & 2 deletions packages/react/src/hooks/use-wallets.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { atomFamilyWithErrorCatcher } from "../utils/jotai.js";
import { useConfig } from "./use-config.js";
import type { Config } from "@reactive-dot/core";
import {
aggregateWallets,
type Config,
getConnectedWallets,
} from "@reactive-dot/core";
} from "@reactive-dot/core/internal/actions.js";
import { atom, useAtomValue } from "jotai";
import { atomWithObservable } from "jotai/utils";

Expand Down
2 changes: 1 addition & 1 deletion packages/vue/src/composables/use-accounts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { internal_useChainId } from "./use-chain-id.js";
import { useChainSpecDataPromise } from "./use-chain-spec-data.js";
import { useLazyValue } from "./use-lazy-value.js";
import { useConnectedWalletsObservable } from "./use-wallets.js";
import { getAccounts } from "@reactive-dot/core";
import { getAccounts } from "@reactive-dot/core/internal/actions.js";
import { computed } from "vue";

/**
Expand Down
2 changes: 1 addition & 1 deletion packages/vue/src/composables/use-block.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { useAsyncData } from "./use-async-data.js";
import { internal_useChainId } from "./use-chain-id.js";
import { useClientPromise } from "./use-client.js";
import { useLazyValue } from "./use-lazy-value.js";
import { getBlock } from "@reactive-dot/core";
import { getBlock } from "@reactive-dot/core/internal/actions.js";
import { from, switchMap } from "rxjs";
import { computed, type MaybeRefOrGetter, toValue } from "vue";

Expand Down
2 changes: 1 addition & 1 deletion packages/vue/src/composables/use-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { useAsyncData } from "./use-async-data.js";
import { internal_useChainId } from "./use-chain-id.js";
import { useChainConfig } from "./use-config.js";
import { useLazyValue } from "./use-lazy-value.js";
import { getClient } from "@reactive-dot/core";
import { getClient } from "@reactive-dot/core/internal/actions.js";
import { computed, toValue } from "vue";

/**
Expand Down
11 changes: 5 additions & 6 deletions packages/vue/src/composables/use-query.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,7 @@ import { useAsyncData } from "./use-async-data.js";
import { internal_useChainId } from "./use-chain-id.js";
import { lazyValue, useLazyValuesCache } from "./use-lazy-value.js";
import { useTypedApiPromise } from "./use-typed-api.js";
import {
type ChainId,
query as executeQuery,
preflight,
Query,
} from "@reactive-dot/core";
import { type ChainId, Query } from "@reactive-dot/core";
import {
type ChainDescriptorOf,
type Falsy,
Expand All @@ -24,6 +19,10 @@ import {
type QueryInstruction,
stringify,
} from "@reactive-dot/core/internal.js";
import {
query as executeQuery,
preflight,
} from "@reactive-dot/core/internal/actions.js";
import type { ChainDefinition, TypedApi } from "polkadot-api";
import { combineLatest, from, type Observable, of } from "rxjs";
import { map, switchMap } from "rxjs/operators";
Expand Down
2 changes: 1 addition & 1 deletion packages/vue/src/composables/use-wallet-connector.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { useAsyncAction } from "./use-async-action.js";
import { useWalletsPromise } from "./use-wallets.js";
import { connectWallet } from "@reactive-dot/core";
import { connectWallet } from "@reactive-dot/core/internal/actions.js";
import type { Wallet } from "@reactive-dot/core/wallets.js";

/**
Expand Down
2 changes: 1 addition & 1 deletion packages/vue/src/composables/use-wallet-disconnector.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { useAsyncAction } from "./use-async-action.js";
import { useConnectedWalletsObservable } from "./use-wallets.js";
import { disconnectWallet } from "@reactive-dot/core";
import { disconnectWallet } from "@reactive-dot/core/internal/actions.js";
import type { Wallet } from "@reactive-dot/core/wallets.js";
import { firstValueFrom } from "rxjs";

Expand Down
2 changes: 1 addition & 1 deletion packages/vue/src/composables/use-wallets-initializer.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { useAsyncAction } from "./use-async-action.js";
import { useWalletsPromise } from "./use-wallets.js";
import { initializeWallets } from "@reactive-dot/core";
import { initializeWallets } from "@reactive-dot/core/internal/actions.js";

/**
* Composable for initializing wallets.
Expand Down
5 changes: 4 additions & 1 deletion packages/vue/src/composables/use-wallets.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
import { useAsyncData } from "./use-async-data.js";
import { useConfig } from "./use-config.js";
import { useLazyValue } from "./use-lazy-value.js";
import { aggregateWallets, getConnectedWallets } from "@reactive-dot/core";
import {
aggregateWallets,
getConnectedWallets,
} from "@reactive-dot/core/internal/actions.js";

/**
* Composable for getting all available wallets.
Expand Down

0 comments on commit ec673a7

Please sign in to comment.