-
-
Notifications
You must be signed in to change notification settings - Fork 55
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #255 from evoluhq/new-api
New API
- Loading branch information
Showing
72 changed files
with
4,576 additions
and
3,831 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,45 @@ | ||
--- | ||
"eslint-config-evolu": major | ||
"@evolu/common-react": major | ||
"@evolu/react-native": major | ||
"@evolu/common-web": major | ||
"@evolu/common": major | ||
"@evolu/server": major | ||
"native": major | ||
"server": major | ||
"web": major | ||
"@evolu/react": minor | ||
--- | ||
|
||
New API | ||
|
||
With the upcoming React 19 `use` Hook, I took a chance to review and improve the Evolu API. I moved as many logic and types as possible to the Evolu interface to make platform variants more lightweight and to allow the use of Evolu directly out of any UI library. | ||
|
||
The most significant change is the split of SQL query declaration and usage. The rest of the API is almost the same except for minor improvements. | ||
|
||
### Example | ||
|
||
```ts | ||
// Create queries. | ||
const allTodos = evolu.createQuery((db) => db.selectFrom("todo").selectAll()); | ||
const todoById = (id: TodoId) => | ||
evolu.createQuery((db) => | ||
db.selectFrom("todo").selectAll().where("id", "=", id), | ||
); | ||
|
||
// We can load a query or many queries. | ||
const allTodosPromise = evolu.loadQuery(allTodos).then(({ rows }) => { | ||
console.log(rows); | ||
}); | ||
evolu.loadQueries([allTodos, todoById(1)]); | ||
|
||
// useQuery can load once or use a promise. | ||
const { rows } = useQuery(allTodos); | ||
const { rows } = useQuery(allTodos, { once: true }); | ||
const { rows } = useQuery(allTodos, { promise: allTodosPromise }); | ||
const { row } = useQuery(todoById(1)); | ||
``` | ||
|
||
I also refactored (read: simplified a lot) Effect Layer usage across all libraries. | ||
|
||
There is no breaking change in data storage or protocol. |
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 +1,3 @@ | ||
{} | ||
{ | ||
"plugins": ["./node_modules/prettier-plugin-jsdoc/dist/index.js"] | ||
} |
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
Oops, something went wrong.
e3a2dd9
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs:
evolu – ./
evolu-git-main-evolu.vercel.app
evolu-evolu.vercel.app
evolu.vercel.app
evolu.dev
www.evolu.dev