Skip to content

Commit

Permalink
enhance: Entity.pk() default provided that uses id
Browse files Browse the repository at this point in the history
  • Loading branch information
ntucker committed Aug 14, 2024
1 parent d2898c6 commit fd5b296
Show file tree
Hide file tree
Showing 37 changed files with 327 additions and 489 deletions.
8 changes: 0 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,6 @@ For more details, see [the Installation docs page](https://dataclient.io/docs/ge
class User extends Entity {
id = '';
username = '';

pk() {
return this.id;
}
}

class Article extends Entity {
Expand All @@ -58,10 +54,6 @@ class Article extends Entity {
author = User.fromJS();
createdAt = Temporal.Instant.fromEpochSeconds(0);

pk() {
return this.id;
}

static schema = {
author: User,
createdAt: Temporal.Instant.from,
Expand Down
12 changes: 0 additions & 12 deletions __tests__/new.ts
Original file line number Diff line number Diff line change
Expand Up @@ -162,10 +162,6 @@ export class User extends Entity {
readonly username: string = '';
readonly email: string = '';
readonly isAdmin: boolean = false;

pk() {
return this.id?.toString();
}
}
export const UserResource = resource({
path: 'http\\://test.com/user/:id',
Expand All @@ -179,10 +175,6 @@ export class Article extends Entity {
readonly author: User | null = null;
readonly tags: string[] = [];

pk() {
return this.id?.toString();
}

static schema = {
author: User,
};
Expand Down Expand Up @@ -621,10 +613,6 @@ export abstract class UnionBase extends Entity {
readonly id: string = '';
readonly body: string = '';
readonly type: string = '';

pk() {
return this.id;
}
}
export class FirstUnion extends UnionBase {
readonly type = 'first';
Expand Down
1 change: 0 additions & 1 deletion docs/core/api/useSubscription.md
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,6 @@ function useSubscription<
### Only subscribe while element is visible

```tsx title="MasterPrice.tsx"
import { useRef } from 'react';
import { useSuspense, useSubscription } from '@data-client/react';
import { getPrice } from 'api/Price';

Expand Down
9 changes: 0 additions & 9 deletions docs/core/getting-started/data-dependency.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,6 @@ export class User extends Entity {
return `https://i.pravatar.cc/64?img=${this.id + 4}`;
}

pk() {
return this.id;
}
static key = 'User';
}
export const UserResource = resource({
Expand All @@ -57,9 +54,6 @@ export class Post extends Entity {
title = '';
body = '';

pk() {
return this.id;
}
static key = 'Post';

static schema = {
Expand Down Expand Up @@ -322,9 +316,6 @@ export class Profile extends Entity {
fullName = '';
bio = '';

pk() {
return this.id?.toString();
}
static key = 'Profile';
}

Expand Down
4 changes: 1 addition & 3 deletions docs/core/getting-started/mutations.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,7 @@ export class Todo extends Entity {
userId = 0;
title = '';
completed = false;
pk() {
return `${this.id}`;
}

static key = 'Todo';
}
export const TodoResource = resource({
Expand Down
3 changes: 0 additions & 3 deletions docs/core/getting-started/resource.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,6 @@ export class Todo extends Entity {
title = '';
completed = false;

pk() {
return `${this.id}`;
}
static key = 'Todo';
}

Expand Down
3 changes: 0 additions & 3 deletions docs/core/shared/_VoteDemo.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,6 @@ export class Post extends Entity {
body = '';
votes = 0;

pk() {
return this.id;
}
static key = 'Post';

static schema = {
Expand Down
3 changes: 0 additions & 3 deletions docs/core/shared/_useLoading.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,6 @@ export class Post extends Entity {
body = '';
votes = 0;

pk() {
return this.id;
}
static key = 'Post';

get img() {
Expand Down
16 changes: 12 additions & 4 deletions docs/rest/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ export class User extends Entity {
pk() {
return this.id;
}

static key = 'User';
}
```

Expand All @@ -59,12 +61,12 @@ export class Article extends Entity {
return this.id;
}

static key = 'Article';

static schema = {
author: User,
createdAt: Temporal.Instant.from,
};

static key = 'Article';
}

export const ArticleResource = resource({
Expand Down Expand Up @@ -263,14 +265,20 @@ resolves to the new Resource created by the API. It will automatically be added
import { useController } from '@data-client/react';
import { Article, ArticleResource } from 'api/article';

export default function ArticleWithDelete({ article }: { article: Article }) {
export default function ArticleWithDelete({
article,
}: {
article: Article;
}) {
const ctrl = useController();
return (
<article>
<h2>{article.title}</h2>
<div>{article.content}</div>
<button
onClick={() => ctrl.fetch(ArticleResource.delete, { id: article.id })}
onClick={() =>
ctrl.fetch(ArticleResource.delete, { id: article.id })
}
>
Delete
</button>
Expand Down
Loading

0 comments on commit fd5b296

Please sign in to comment.