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 577ffc1
Show file tree
Hide file tree
Showing 10 changed files with 17 additions and 72 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
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

0 comments on commit 577ffc1

Please sign in to comment.