Skip to content

Commit

Permalink
docs: Remove unneeded id pk from examples
Browse files Browse the repository at this point in the history
  • Loading branch information
ntucker committed Sep 1, 2024
1 parent 9ebc6cd commit dda505f
Show file tree
Hide file tree
Showing 15 changed files with 19 additions and 90 deletions.
7 changes: 0 additions & 7 deletions docs/core/concepts/normalization.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,20 +29,13 @@ class Todo extends Entity {
readonly userId: number = 0;
readonly title: string = '';
readonly completed: boolean = false;
pk() {
return `${this.id}`;
}
}
```
```js
import { Entity } from '@data-client/endpoint';
class Todo extends Entity {
pk() {
return `${this.id}`;
}
}
```
Expand Down
4 changes: 0 additions & 4 deletions docs/core/guides/ssr.md
Original file line number Diff line number Diff line change
Expand Up @@ -94,10 +94,6 @@ class User extends Entity {
id = '';
username = '';

pk() {
return this.id;
}

// highlight-next-line
static key = 'User';
}
Expand Down
4 changes: 0 additions & 4 deletions examples/coin-app/src/resources/Currency.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,6 @@ export class Currency extends Entity {
return iconTable[this.id]?.img_url;
}

pk(): string {
return this.id;
}

static key = 'Currency';

static process(
Expand Down
4 changes: 0 additions & 4 deletions examples/coin-app/src/resources/Product.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,6 @@ export class Product extends Entity {
trading_disabled = false;
stats = Stats.fromJS();

pk(): string {
return this.id;
}

static key = 'Product';
static schema = {
stats: Stats,
Expand Down
4 changes: 0 additions & 4 deletions examples/github-app/src/resources/Base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,6 @@ const HOST = 'https://api.github.com';

export class GithubEntity extends Entity {
readonly id: number = -1;

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

export const GithubGqlEndpoint = new GQLEndpoint(
Expand Down
4 changes: 0 additions & 4 deletions examples/github-app/src/resources/Label.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,6 @@ export class Label extends GithubEntity {
readonly description: string = '';
readonly color: string = '000000';
readonly default: boolean = false;

pk() {
return this.id?.toString();
}
}
export const LabelResource = githubResource({
path: '/repos/:owner/:repo/labels/:name',
Expand Down
2 changes: 1 addition & 1 deletion examples/github-app/src/resources/Push.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export class Push extends GithubEntity {
commits: Commit[] = [];

pk() {
return `${this.pushId}`;
return this.pushId;
}
}

Expand Down
4 changes: 0 additions & 4 deletions examples/github-app/src/resources/Reaction.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,6 @@ export class Reaction extends GithubEntity {
return contentToIcon[this.content];
}

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

static schema = {
user: User,
createdAt: Temporal.Instant.from,
Expand Down
6 changes: 1 addition & 5 deletions examples/nextjs/resources/PlaceholderBaseResource.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,8 @@ import {
} from '@data-client/rest';

export abstract class PlaceholderEntity extends Entity {
id = 0;

// all Resources of `jsonplaceholder` use an id for the primary key
pk() {
return `${this.id}`;
}
id = 0;
}

/** Common patterns in the https://jsonplaceholder.typicode.com API */
Expand Down
20 changes: 6 additions & 14 deletions examples/normalizr-github/schema.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,8 @@
import { schema, Entity } from '@data-client/endpoint';

class BaseEntity extends Entity {
id = 0;
export class User extends Entity {}

pk() {
return this.id;
}
}

export class User extends BaseEntity {}

export class Commit extends BaseEntity {
export class Commit extends Entity {
sha = '';

static schema = {
Expand All @@ -23,15 +15,15 @@ export class Commit extends BaseEntity {
}
}

export class Label extends BaseEntity {}
export class Label extends Entity {}

export class Milestone extends BaseEntity {
export class Milestone extends Entity {
static schema = {
creator: User,
};
}

export class Issue extends BaseEntity {
export class Issue extends Entity {
static schema = {
assignee: User,
assignees: [User],
Expand All @@ -41,7 +33,7 @@ export class Issue extends BaseEntity {
};
}

export class PullRequest extends BaseEntity {
export class PullRequest extends Entity {
static schema = {
assignee: User,
assignees: [User],
Expand Down
20 changes: 6 additions & 14 deletions examples/normalizr-redux/src/api/schema.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,8 @@
import { schema, Entity } from '@data-client/endpoint';

class BaseEntity extends Entity {
id = 0;
export class User extends Entity {}

pk() {
return `${this.id}`;
}
}

export class User extends BaseEntity {}

export class Commit extends BaseEntity {
export class Commit extends Entity {
sha = '';

static schema = {
Expand All @@ -23,15 +15,15 @@ export class Commit extends BaseEntity {
}
}

export class Label extends BaseEntity {}
export class Label extends Entity {}

export class Milestone extends BaseEntity {
export class Milestone extends Entity {
static schema = {
creator: User,
};
}

export class Issue extends BaseEntity {
export class Issue extends Entity {
static schema = {
assignee: User,
assignees: [User],
Expand All @@ -41,7 +33,7 @@ export class Issue extends BaseEntity {
};
}

export class PullRequest extends BaseEntity {
export class PullRequest extends Entity {
static schema = {
assignee: User,
assignees: [User],
Expand Down
14 changes: 3 additions & 11 deletions examples/normalizr-relationships/schema.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,6 @@
import { Entity } from '@data-client/endpoint';

class BaseEntity extends Entity {
id = 0;

pk() {
return this.id;
}
}

class User extends BaseEntity {
class User extends Entity {
static process(value, parent, key) {
switch (key) {
case 'author':
Expand All @@ -29,7 +21,7 @@ class User extends BaseEntity {
};
}
}
class Comment extends BaseEntity {
class Comment extends Entity {
static schema = {
commenter: User,
};
Expand All @@ -39,7 +31,7 @@ class Comment extends BaseEntity {
}
}

class Post extends BaseEntity {
class Post extends Entity {
static schema = {
author: User,
comments: [Comment],
Expand Down
6 changes: 1 addition & 5 deletions examples/todo-app/src/resources/PlaceholderBaseResource.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,8 @@ import {
import { v4 as uuid } from 'uuid';

export abstract class PlaceholderEntity extends Entity {
id = 0;

// all Resources of `jsonplaceholder` use an id for the primary key
pk() {
return `${this.id}`;
}
id = 0;
}

/** Common patterns in the https://jsonplaceholder.typicode.com API */
Expand Down
4 changes: 0 additions & 4 deletions website/src/fixtures/posts-collection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,6 @@ class Post extends Entity {
title = '';
group = '';
author = '';

pk() {
return this.id;
}
}
export const getPosts = new RestEndpoint({
path: '/:group/posts',
Expand Down
6 changes: 1 addition & 5 deletions website/src/fixtures/profiles.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,11 @@
import { Entity, resource, RestEndpoint } from '@data-client/rest';
import { Entity, resource } from '@data-client/rest';

export class Profile extends Entity {
id: number | undefined = undefined;
img = '';
fullName = '';
bio = '';

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

static key = 'Profile';
}

Expand Down

0 comments on commit dda505f

Please sign in to comment.