-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Have facade take a type argument instead of relying on satisfies
- Loading branch information
Showing
8 changed files
with
106 additions
and
93 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
# data-facade | ||
|
||
An abstraction layer between a React application and its underlying data source. | ||
|
||
## Motivation | ||
|
||
The initial version of the mobile app will get its data from the `wallet-server`, a server that gets data from an Iron Fish node. Though the data source is fixed for now, we want to make it easy to switch to a different data source in the future. By using this abstraction layer, we'll be able to switch between data sources without needing to make changes to the React components themselves. | ||
|
||
## Usage | ||
|
||
1. Define your interface and create handlers | ||
2. Create facade context and export `FacadeProvider` and `useFacade` | ||
3. Wrap your application with `FacadeProvider` | ||
4. Use `useFacade` hook to access the facade in your components |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
export type { FacadeDefinition, Query, Mutation } from "./types"; | ||
export type { Query, Mutation } from "./types"; | ||
export { f } from "./facade"; | ||
export { createFacadeContext } from "./react-context"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,9 @@ | ||
import { FacadeDefinition, Query } from "data-facade"; | ||
import { Query, Mutation } from "data-facade"; | ||
|
||
export type AccountsMethods = FacadeDefinition<{ | ||
export type AccountsMethods = { | ||
getAccounts: Query<(count: number) => string[]>; | ||
getAllAccounts: Query<() => string[]>; | ||
getAccountsWithZod: Query<(args: { limit: number }) => string[]>; | ||
}>; | ||
createAccount: Mutation<(account: string) => string[]>; | ||
createAccountWithZod: Mutation<(args: { account: string }) => string[]>; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,7 @@ | ||
import { accountsHandlers } from "./accounts/handlers"; | ||
import { AccountsMethods } from "./accounts/types"; | ||
|
||
import { createFacadeContext } from "data-facade"; | ||
import { accountsHandlers } from "./accounts/handlers"; | ||
|
||
const facadeContext = createFacadeContext( | ||
accountsHandlers satisfies AccountsMethods, | ||
); | ||
const facadeContext = createFacadeContext(accountsHandlers); | ||
|
||
export const FacadeProvider = facadeContext.Provider; | ||
export const useFacade = facadeContext.useFacade; |