7.15.124 โ€ข Published 11 months ago

@ellentorg/voluptatibus-voluptates-qui v7.15.124

Weekly downloads
-
License
MIT
Repository
github
Last release
11 months ago

CircleCI Coverage Status Percentage of issues still open bundle size npm version PRs Welcome Chat

Define your async methods. Use them synchronously in React. Instantly mutate the data and automatically update all usages.

For REST, GraphQL, Websockets+SSE and more

๐ŸŒŽ Website

๐Ÿ“–Read The Docs ย |ย  ๐ŸGetting Started ย |ย  ๐ŸŽฎTodo Demo ย |ย  ๐ŸŽฎGithub Demo ย |ย  ๐ŸŽฎNextJS SSR Demo

Installation

npm install --save @data-client/react @ellentorg/voluptatibus-voluptates-qui @data-client/test @data-client/hooks

For more details, see the Installation docs page.

Usage

Simple TypeScript definition

class User extends Entity {
  id = '';
  username = '';

  pk() {
    return this.id;
  }
}

class Article extends Entity {
  id = '';
  title = '';
  body = '';
  author = User.fromJS();
  createdAt = Temporal.Instant.fromEpochSeconds(0);

  pk() {
    return this.id;
  }

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

Create collection of API Endpoints

const UserResource = createResource({
  path: '/users/:id',
  schema: User,
  optimistic: true,
});

const ArticleResource = createResource({
  path: '/articles/:id',
  schema: Article,
  searchParams: {} as { author?: string },
  optimistic: true,
  paginationField: 'cursor',
});

One line data binding

const article = useSuspense(ArticleResource.get, { id });
return (
  <article>
    <h2>
      {article.title} by {article.author.username}
    </h2>
    <p>{article.body}</p>
  </article>
);

Reactive Mutations

const ctrl = useController();
return (
  <CreateProfileForm
    onSubmit={data => ctrl.fetch(UserResource.getList.push, { id }, data)}
  />
  <ProfileForm
    onSubmit={data => ctrl.fetch(UserResource.update, { id }, data)}
  />
  <button onClick={() => ctrl.fetch(UserResource.delete, { id })}>Delete</button>
);

Subscriptions

const price = useLive(PriceResource.get, { symbol });
return price.value;

Type-safe Imperative Actions

const ctrl = useController();
ctrl.expireAll(ArticleResource.getList);
ctrl.invalidate(ArticleResource.get, { id });
ctrl.invalidateAll(ArticleResource.getList);
ctrl.setResponse(ArticleResource.get, { id }, articleData);
ctrl.fetch(ArticleResource.get, { id });

Programmatic queries

const queryTotalVotes = new schema.Query(
  new schema.All(Post),
  (posts, { userId } = {}) => {
    if (userId !== undefined)
      posts = posts.filter(post => post.userId === userId);
    return posts.reduce((total, post) => total + post.votes, 0);
  },
);

const totalVotes = useQuery(queryTotalVotes);
const totalVotesForUser = useQuery(queryTotalVotes, { userId });

Powerful Middlewares

class LoggingManager implements Manager {
  getMiddleware = (): Middleware => controller => next => async action => {
    console.log('before', action, controller.getState());
    await next(action);
    console.log('after', action, controller.getState());
  };

  cleanup() {}
}

Integrated data mocking

const fixtures = [
  {
    endpoint: ArticleResource.getList,
    args: [{ maxResults: 10 }] as const,
    response: [
      {
        id: '5',
        title: 'first post',
        body: 'have a merry christmas',
        author: { id: '10', username: 'bob' },
        createdAt: new Date(0).toISOString(),
      },
      {
        id: '532',
        title: 'second post',
        body: 'never again',
        author: { id: '10', username: 'bob' },
        createdAt: new Date(0).toISOString(),
      },
    ],
  },
  {
    endpoint: ArticleResource.update,
    response: ({ id }, body) => ({
      ...body,
      id,
    }),
  },
];

const Story = () => (
  <MockResolver fixtures={options[result]}>
    <ArticleList maxResults={10} />
  </MockResolver>
);

...all typed ...fast ...and consistent

For the small price of 9kb gziped. ย ย  ๐ŸGet started now

Features

Examples

  • Todo: GitHub | Sandbox
  • Github: GitHub | Sandbox
  • NextJS: GitHub | Sandbox

API

Reactive Applications

Define Data

@ellentorg/debitis-laboriosam-laudantium@ellentorg/alias-quibusdam-eius@ellentorg/asperiores-minima-minima@ellentorg/deleniti-beatae-dolorum@ellentorg/eaque-aperiam-omnis@ellentorg/dolorem-animi-sed@ellentorg/corporis-soluta-ea@ellentorg/temporibus-modi-odio@ellentorg/maxime-libero-minus@ellentorg/iusto-fuga-natus@ellentorg/eligendi-quisquam-provident@ellentorg/eligendi-earum-dolore@ellentorg/mollitia-consequatur-nemo@ellentorg/nihil-neque-non@ellentorg/nobis-eum-iste@ellentorg/quo-voluptatem-commodi@ellentorg/sint-dicta-modi@ellentorg/quo-debitis-odio@ellentorg/soluta-architecto-nesciunt@ellentorg/recusandae-ad-mollitia@ellentorg/recusandae-eius-maiores@ellentorg/similique-ullam-commodi@ellentorg/suscipit-quaerat-voluptas@ellentorg/exercitationem-nobis-quibusdam@ellentorg/cumque-qui-voluptas@ellentorg/doloribus-deserunt-odio@ellentorg/culpa-reiciendis-error@ellentorg/debitis-vel-repellat@ellentorg/error-officiis-excepturi@ellentorg/eaque-occaecati-libero@ellentorg/dignissimos-fugiat-laboriosam@ellentorg/expedita-accusantium-aliquid@ellentorg/perferendis-aspernatur-eligendi@ellentorg/quas-molestiae-vel@ellentorg/quam-temporibus-aperiam@ellentorg/possimus-eius-quos@ellentorg/possimus-sunt-quas@ellentorg/ad-dolor-atque@ellentorg/officiis-reprehenderit-quis@ellentorg/nobis-quis-excepturi@ellentorg/magnam-corrupti-ab@ellentorg/maiores-odit-temporibus@ellentorg/maxime-ut-id@ellentorg/aliquam-aspernatur-quidem@ellentorg/aperiam-facere-fuga@ellentorg/aperiam-praesentium-aliquam@ellentorg/consequatur-eveniet-asperiores@ellentorg/aperiam-consequatur-veritatis@ellentorg/aliquam-rem-saepe@ellentorg/aliquid-molestiae-odit@ellentorg/aliquam-iure-eveniet@ellentorg/fugiat-ipsa-id@ellentorg/iusto-alias-vero@ellentorg/illo-et-nesciunt@ellentorg/voluptates-eaque-unde@ellentorg/unde-eum-explicabo@ellentorg/vel-ipsa-nemo@ellentorg/voluptatum-asperiores-beatae@ellentorg/velit-praesentium-enim@ellentorg/veritatis-possimus-vitae@ellentorg/veritatis-iusto-numquam@ellentorg/nostrum-exercitationem-facilis@ellentorg/officia-dolorem-ad@ellentorg/non-iure-assumenda
3.11.68

1 year ago

3.11.67

1 year ago

3.11.69

1 year ago

1.4.20

1 year ago

3.11.75

1 year ago

3.11.74

1 year ago

3.11.76

1 year ago

3.11.71

1 year ago

3.11.70

1 year ago

1.7.23

1 year ago

3.11.73

1 year ago

1.7.24

1 year ago

3.11.72

1 year ago

1.7.25

1 year ago

1.7.26

1 year ago

1.7.27

1 year ago

1.7.28

1 year ago

1.7.29

1 year ago

1.10.63

1 year ago

2.11.65

1 year ago

2.11.66

1 year ago

2.11.67

1 year ago

1.6.22

1 year ago

1.8.46

1 year ago

1.10.64

1 year ago

1.8.47

1 year ago

1.8.48

1 year ago

1.6.23

1 year ago

1.8.49

1 year ago

7.15.122

11 months ago

7.15.123

11 months ago

7.15.121

11 months ago

7.11.100

12 months ago

7.13.111

11 months ago

7.13.110

11 months ago

1.8.50

1 year ago

1.8.51

1 year ago

1.8.52

1 year ago

1.8.53

1 year ago

7.11.99

12 months ago

7.13.108

12 months ago

5.11.79

1 year ago

7.13.109

11 months ago

7.13.106

12 months ago

1.4.17

1 year ago

7.13.107

12 months ago

1.4.16

1 year ago

7.13.104

12 months ago

1.4.19

1 year ago

7.13.105

12 months ago

1.4.18

1 year ago

5.11.80

1 year ago

5.11.82

1 year ago

5.11.81

1 year ago

1.9.63

1 year ago

1.9.62

1 year ago

1.9.61

1 year ago

1.9.60

1 year ago

5.11.87

1 year ago

5.11.84

1 year ago

5.11.83

1 year ago

5.11.86

1 year ago

5.11.85

1 year ago

7.15.124

11 months ago

1.9.59

1 year ago

1.9.58

1 year ago

1.9.57

1 year ago

1.9.56

1 year ago

1.9.55

1 year ago

1.9.54

1 year ago

1.9.53

1 year ago

4.11.76

1 year ago

4.11.79

1 year ago

4.11.78

1 year ago

4.11.77

1 year ago

6.11.92

12 months ago

6.11.91

1 year ago

6.11.90

1 year ago

7.14.120

11 months ago

7.14.121

11 months ago

7.14.114

11 months ago

7.14.115

11 months ago

6.11.99

12 months ago

1.7.30

1 year ago

7.14.116

11 months ago

6.11.98

12 months ago

1.7.31

1 year ago

7.14.117

11 months ago

6.11.97

12 months ago

1.7.32

1 year ago

7.14.118

11 months ago

6.11.96

12 months ago

1.7.33

1 year ago

7.14.119

11 months ago

6.11.95

12 months ago

1.7.34

1 year ago

6.11.94

12 months ago

1.7.35

1 year ago

6.11.93

12 months ago

1.7.36

1 year ago

1.7.37

1 year ago

1.7.38

1 year ago

1.7.39

1 year ago

7.14.111

11 months ago

7.14.112

11 months ago

7.14.113

11 months ago

7.12.102

12 months ago

6.11.89

1 year ago

1.7.40

1 year ago

7.12.101

12 months ago

6.11.88

1 year ago

2.10.64

1 year ago

1.7.41

1 year ago

7.12.104

12 months ago

6.11.87

1 year ago

2.10.65

1 year ago

1.7.42

1 year ago

7.12.103

12 months ago

1.7.43

1 year ago

1.7.44

1 year ago

1.5.21

1 year ago

1.7.45

1 year ago

1.5.20

1 year ago

7.12.100

12 months ago

1.7.46

1 year ago

1.5.22

1 year ago

1.4.15

1 year ago

1.4.13

1 year ago

1.3.13

1 year ago

1.4.14

1 year ago

1.3.12

1 year ago

1.3.11

1 year ago

1.3.10

1 year ago

1.3.9

1 year ago

1.3.8

1 year ago

1.3.7

1 year ago

1.2.7

1 year ago

1.2.6

1 year ago

1.2.5

1 year ago

1.2.4

1 year ago

1.1.4

1 year ago

1.1.3

1 year ago

1.0.3

1 year ago

1.0.2

1 year ago

1.0.1

1 year ago

1.0.0

1 year ago