3.11.114 โ€ข Published 1 year ago

@taktikorg/ratione-veniam-velit v3.11.114

Weekly downloads
-
License
MIT
Repository
github
Last release
1 year 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 @taktikorg/ratione-veniam-velit @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

Uint32ArraydataimportexportsetterjapanesevariablesnodejsownhasOwnPropertyduplexmime-dbyupinternalvaluereact poseMicrosoftfile cachedirectoryflattenlanguagemaptrimEnddefinePropertyimportoptiontsextendBigInt64ArrayserializationprogresstslibbinddefaultremovequeuejsonpathclonecallicuassignURLroutingemrwrapsafetermargumentsdateObject.fromEntriesupincludesreact animationpicomatchinstalleslintconfigrateconsumediffroute53formstextredirectURLSearchParamsCSShttpswalkingconcatMapes7utilityES2015byteOffsetconcurrencyes2018ECMAScript 2019iameslintpluginnodesuperagentregexmoveWebSocketprotocol-bufferstoArraythroattypesafeform[[Prototype]]dataViewcommandloggercollection.es6varspromisesfast-deep-clonebytenopewriteomitrmstringifyshrinkwrapjsxbrowsergroupreact-testing-libraryforEachzodgroupBywgetcompilereslook-upintrinsicpositiverecursivekeyrm -rfstructuredClonelengthtypedwidthbluebirdRFC-6455package managerwarningUint16Arraymkdirgenericsxhrarraybuffertypescriptcopyyamlloadingtddstringifierloadbalancingprivatejshintawssymlinksimmerwritablesharedarraybuffercallbind__proto__randomjasmineArray.prototype.flatUnderscoresortfull-widthphoneenumerablesymbolssomeglacierconfigInt8Arrayargvpackage.jsonmatchAllES2023serializerrmdirstoragegatewayassertES3processES2022eventEmitterecmascripteveryshames2016postcss-pluginsnsnamefilelimitESnextaccessibilityfastcopyUint8ArrayfigletECMAScript 2021TypedArrayES2020joigetterpathObject.definePropertyjsonglobalregularreact-hook-formtypedarraysreact-hookshas-ownES7eventDispatcherenvironmentmonorepostyleguideECMAScript 2017Int32Arraygdprnegativeregular expressionstimeserializedescriptionreal-timelookworkercmdchaiworkspace:*flagES2021readablewaitreades8descriptorlockfiletesterpopmotiontypepropertiesartcollectionflagsglobconvertsesspeclastMapcensorqsdataviewprotobufcreatehasOwncharactersES2016regexpspinnerscoveragestylingsequencebrowserslistsimple cacherdsFloat32ArrayinstrumentationFunction.prototype.nameebsvalidmochafastclonechildmakeES2017metadataweakmaptraversepersistentECMAScript 2018whichiterationmake dircryptoio-tshash
3.6.69

1 year ago

3.6.68

1 year ago

3.6.67

1 year ago

3.6.66

1 year ago

3.10.97

1 year ago

3.10.98

1 year ago

3.10.95

1 year ago

3.10.96

1 year ago

3.10.99

1 year ago

3.10.90

1 year ago

3.10.93

1 year ago

3.10.94

1 year ago

3.10.91

1 year ago

3.10.92

1 year ago

3.6.70

1 year ago

3.11.114

1 year ago

3.11.113

1 year ago

2.3.49

1 year ago

2.3.46

1 year ago

2.3.45

1 year ago

2.3.48

1 year ago

2.3.47

1 year ago

2.5.65

1 year ago

2.3.42

1 year ago

2.5.66

1 year ago

2.3.41

1 year ago

2.3.44

1 year ago

2.3.43

1 year ago

2.3.40

1 year ago

3.10.86

1 year ago

3.10.87

1 year ago

3.10.84

1 year ago

3.10.85

1 year ago

3.10.88

1 year ago

3.10.89

1 year ago

3.10.82

1 year ago

3.10.83

1 year ago

2.3.53

1 year ago

2.3.52

1 year ago

3.8.72

1 year ago

2.3.54

1 year ago

3.8.70

1 year ago

3.8.71

1 year ago

2.3.51

1 year ago

2.3.50

1 year ago

2.2.17

1 year ago

2.2.18

1 year ago

2.2.15

1 year ago

2.2.16

1 year ago

2.2.13

1 year ago

2.2.14

1 year ago

2.2.12

1 year ago

3.7.70

1 year ago

3.10.108

1 year ago

3.10.107

1 year ago

3.10.109

1 year ago

3.10.104

1 year ago

3.10.103

1 year ago

3.10.106

1 year ago

2.2.19

1 year ago

3.10.105

1 year ago

3.10.111

1 year ago

2.2.28

1 year ago

3.10.110

1 year ago

2.2.29

1 year ago

3.10.113

1 year ago

2.2.26

1 year ago

3.10.112

1 year ago

2.2.27

1 year ago

2.2.24

1 year ago

2.2.25

1 year ago

2.2.22

1 year ago

2.2.23

1 year ago

2.6.66

1 year ago

2.2.20

1 year ago

2.2.21

1 year ago

3.9.79

1 year ago

3.9.77

1 year ago

3.9.78

1 year ago

3.10.100

1 year ago

2.2.39

1 year ago

3.10.102

1 year ago

2.2.37

1 year ago

3.10.101

1 year ago

2.2.38

1 year ago

2.4.58

1 year ago

2.2.35

1 year ago

2.4.57

1 year ago

2.2.36

1 year ago

2.2.33

1 year ago

2.4.59

1 year ago

2.2.34

1 year ago

3.9.75

1 year ago

2.4.54

1 year ago

2.2.31

1 year ago

3.9.76

1 year ago

2.2.32

1 year ago

3.9.73

1 year ago

2.4.56

1 year ago

3.9.74

1 year ago

2.4.55

1 year ago

2.2.30

1 year ago

3.9.72

1 year ago

2.4.65

1 year ago

2.4.64

1 year ago

2.2.40

1 year ago

3.9.82

1 year ago

2.4.61

1 year ago

2.4.60

1 year ago

3.9.80

1 year ago

2.4.63

1 year ago

3.9.81

1 year ago

2.4.62

1 year ago

2.2.11

1 year ago

2.2.10

1 year ago

1.2.8

1 year ago

1.2.7

1 year ago

1.2.9

1 year ago

1.2.10

1 year ago

1.1.7

1 year ago

1.0.7

1 year ago

1.0.6

1 year ago

1.0.5

1 year ago

1.0.4

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