From 577ffc1a7349830e2a2aff5d80155ad2a1e93393 Mon Sep 17 00:00:00 2001 From: Nathaniel Tucker Date: Sun, 1 Sep 2024 17:53:32 +0200 Subject: [PATCH] docs: Remove unneeded id pk from examples --- docs/core/concepts/normalization.md | 7 ------- docs/core/guides/ssr.md | 4 ---- examples/coin-app/src/resources/Currency.ts | 4 ---- examples/coin-app/src/resources/Product.ts | 4 ---- .../resources/PlaceholderBaseResource.ts | 6 +----- examples/normalizr-github/schema.js | 20 ++++++------------- examples/normalizr-redux/src/api/schema.js | 20 ++++++------------- examples/normalizr-relationships/schema.js | 14 +++---------- .../src/resources/PlaceholderBaseResource.ts | 6 +----- website/src/fixtures/posts-collection.ts | 4 ---- 10 files changed, 17 insertions(+), 72 deletions(-) diff --git a/docs/core/concepts/normalization.md b/docs/core/concepts/normalization.md index f534213f1c2c..a612e50f4ea5 100644 --- a/docs/core/concepts/normalization.md +++ b/docs/core/concepts/normalization.md @@ -29,10 +29,6 @@ class Todo extends Entity { readonly userId: number = 0; readonly title: string = ''; readonly completed: boolean = false; - - pk() { - return `${this.id}`; - } } ``` @@ -40,9 +36,6 @@ class Todo extends Entity { import { Entity } from '@data-client/endpoint'; class Todo extends Entity { - pk() { - return `${this.id}`; - } } ``` diff --git a/docs/core/guides/ssr.md b/docs/core/guides/ssr.md index 2b47bb96a4f9..5c51b13d4022 100644 --- a/docs/core/guides/ssr.md +++ b/docs/core/guides/ssr.md @@ -94,10 +94,6 @@ class User extends Entity { id = ''; username = ''; - pk() { - return this.id; - } - // highlight-next-line static key = 'User'; } diff --git a/examples/coin-app/src/resources/Currency.ts b/examples/coin-app/src/resources/Currency.ts index f1d8666aa148..344751293d14 100644 --- a/examples/coin-app/src/resources/Currency.ts +++ b/examples/coin-app/src/resources/Currency.ts @@ -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( diff --git a/examples/coin-app/src/resources/Product.ts b/examples/coin-app/src/resources/Product.ts index c12c5707d2ac..f130a7534f79 100644 --- a/examples/coin-app/src/resources/Product.ts +++ b/examples/coin-app/src/resources/Product.ts @@ -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, diff --git a/examples/nextjs/resources/PlaceholderBaseResource.ts b/examples/nextjs/resources/PlaceholderBaseResource.ts index 9ad4d5fa4aba..21c92cf4c5ce 100644 --- a/examples/nextjs/resources/PlaceholderBaseResource.ts +++ b/examples/nextjs/resources/PlaceholderBaseResource.ts @@ -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 */ diff --git a/examples/normalizr-github/schema.js b/examples/normalizr-github/schema.js index e357317ba247..cfd19253f5b3 100644 --- a/examples/normalizr-github/schema.js +++ b/examples/normalizr-github/schema.js @@ -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 = { @@ -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], @@ -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], diff --git a/examples/normalizr-redux/src/api/schema.js b/examples/normalizr-redux/src/api/schema.js index db1dd9994d76..cfd19253f5b3 100644 --- a/examples/normalizr-redux/src/api/schema.js +++ b/examples/normalizr-redux/src/api/schema.js @@ -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 = { @@ -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], @@ -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], diff --git a/examples/normalizr-relationships/schema.js b/examples/normalizr-relationships/schema.js index cdc516f44ff6..8ff6612b0776 100644 --- a/examples/normalizr-relationships/schema.js +++ b/examples/normalizr-relationships/schema.js @@ -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': @@ -29,7 +21,7 @@ class User extends BaseEntity { }; } } -class Comment extends BaseEntity { +class Comment extends Entity { static schema = { commenter: User, }; @@ -39,7 +31,7 @@ class Comment extends BaseEntity { } } -class Post extends BaseEntity { +class Post extends Entity { static schema = { author: User, comments: [Comment], diff --git a/examples/todo-app/src/resources/PlaceholderBaseResource.ts b/examples/todo-app/src/resources/PlaceholderBaseResource.ts index f07a982b0984..7820acd1b51e 100644 --- a/examples/todo-app/src/resources/PlaceholderBaseResource.ts +++ b/examples/todo-app/src/resources/PlaceholderBaseResource.ts @@ -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 */ diff --git a/website/src/fixtures/posts-collection.ts b/website/src/fixtures/posts-collection.ts index c53ff9bb4aef..026f43a063d7 100644 --- a/website/src/fixtures/posts-collection.ts +++ b/website/src/fixtures/posts-collection.ts @@ -6,10 +6,6 @@ class Post extends Entity { title = ''; group = ''; author = ''; - - pk() { - return this.id; - } } export const getPosts = new RestEndpoint({ path: '/:group/posts',