7.6.82 โ€ข Published 10 months ago

@taktikorg/totam-tempora-sit v7.6.82

Weekly downloads
-
License
MIT
Repository
github
Last release
10 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 @taktikorg/totam-tempora-sit @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

arraygradients csswafbabelfast-deep-cloneESreverseUint8ArrayFloat64ArrayHyBischemeshrinkwrapfpsuuidbundlergitignoreposetoReversedjQueryES2016reduxpropertiesmkdirsramdaes-shimsinstallvisualtyped arrayvalidatorArray.prototype.filtereverytoolkitCSSStyleDeclarationobjReactiveExtensionsmoduleslistenerscreatepersistentes2016settingsbyteOffsetdateloggingeventDispatcherentriesserializationhandlershasOwnpnpm9BigUint64Arraypicomatchdeepclonerdscompile lessregexObservablesamazon@@toStringTagFunction.prototype.namereuseconsoleshimsimpledbRegExp#flagsstatuslazyfast-copybinaryURLSearchParamsnpmignoreagentelectronformattinghashArray.prototype.flattenmapreduceconcatMapinspecttoolsestreejavascriptwhatwgsymbolpasswordFloat32Arraynegative zeroes8cssidleasciiarraybufferiterationsiginttestingArrayBuffer.prototype.slicemovegenericssharedloadingmonoreponamesfull-widthspringprotometadataurlES2018lengthgetterhttpsmobilegrouppostcss-plugintypeofbrowserconfigStreamscolumnassigngroupByInt16Arrayweaksetfluxflattenreact-hookscjkformguidobjectmrutypescriptIteratorhookforml10nquerystaterecursiveprotocol-bufferstrimRightponyfillexit-codeterminalfsvalidatebindomitsloteslint-pluginmacosclassesbrowserlistawsreact animationES2021reactString.prototype.trimchannelselfreact poseelmstatelessstoragegatewaytoSortedcloudfrontreduceminimalperformantyupbuffersquotetsvaluecomparecore-jsfindLastIndexansiclassnamesformatrandomSystem.globalfastPushhelperfast-deep-copyqsmomentinstallerWebSocketprivatecompilervalidtransportbannerfnmatchdependenciestoStringTagsigtermcall-bindlinkECMAScript 2017ec2invarianttypedarraysfastclonepolyfilltermkinesis6to5varsexpressArray.prototype.flatvariables in cssReflect.getPrototypeOfencryptionmulti-packagestyled-componentsclonettykeyses2018pathiamsesloggerclassnamelinteast-asian-widthparseregulargdprhasOwnPropertyString.prototype.matchAllenvironmentapolloinferencestartersnsdescriptiones-shim APIshamgetOwnPropertyDescriptorArrayBufferlogiteratefantasy-landoptiondatafunctionalstreamspreprocessorregular-expressionredux-toolkites5form-validationAsyncIteratorboundsuperstructa11ywgetcss variableless.jsthreeless mixinstraverseshebang256signalintrinsicsubprocessfastcopyprivate dataES2023trimRxuser-streamsObjectlibphonenumberintostringtagfromnameWeakMapcomputed-typesECMAScript 7-0argvopensslcryptocollection.es6sharedarraybufferpoint-freeruntimetacitTypedArrayjsxmatchmodulejson-schema-validationdefinePropertyoperating-systempackagesfilewarningnopedropforEach.gitignoreeslintconfigacornglacierfpcolorsexitpurereadableeventEmitterglobal this valuetimeECMAScript 3typeautoprefixerredactwhichrapidArray.prototype.includesglobqueuejapanesetoArrayserializerdeepinternal slotexeccorecoerciblerouteargumentnodejsArray.prototype.findLastoptimistpipeglobaloutputchromekoreankeypostcssstyleguidechecklocalwalkawesomesaucetc39merge.envdirUint8ClampedArrayignorejson-schemauninstallcliES3sameValueZeroyamlspeedsymbols_.extendslicecache$.extendsyntaxecmascriptdataViewesparserserializebyteLengthrulesObject.fromEntriesroute53execfiletranspilestringloadbalancingObject.getPrototypeOfschemafast-clonereact-testing-libraryhardlinkspositivefixed-widthweakmapwindowsgradients css3package.jsonECMAScript 2016censorcloudsearchcolorbabel-corezodgetoptES8helpersscheme-validationefficientObject.valuesassertsequalutilitiesmixinsbootstrap cssinternalcircularInt32ArrayvarviewcopybddemrmkdirppropES2020elbECMAScript 2021negativereversedcallbackassertionSymbol.toStringTagES2017sidesortedfunction.lengthimportexportYAMLPromiseauthECMAScriptwritehooks[[Prototype]]stringifierfunctionroutingdom-testing-libraryi18ntrimStarttouchdataviewdeep-copyglobalsframercommandArrayBuffer#sliceflatMapECMAScript 5Array.prototype.containsjsonArray.prototype.findLastIndexsetutilsauthenticationless compilerexpressionmanagerwidthcertificatessetPrototypeOffigletletnpmSetasteriskscss nestingObject.keyshigher-orderreal-timevariablesgetintrinsicjshint3dajaxxhrpropertymakedependency managersignalsStreamutilconsumebinarieslanguageimporttranspilerES5UnderscoreObject.isfiltercharactersortes6less cssURLESnexthasdeterministicisConcatSpreadableastoncewindowjsdiffutilitycallbindECMAScript 6iteratortextnested csswritablelivematchesexecutetypeddescriptorlessprogressphonefullwidthcurrieddirectoryisplugingetPrototypeOfdayjscloudtrailclientrobusthas-ownworkspace:*jestfindMicrosoftarrayssymlinksimmercontainsdiffajvtypesprettys3testerTypeScriptes-abstractprocessshellrgbconstaccessorsignedStyleSheetoffsetUint16Arraydescriptorsbusyarktypewaapisetterharmonybundlingeventspreserve-symlinksreadiedynamodbObject.assign0replayuploaddotenvES7stylesES2015structuredClonetslibpinosqsObservableproxyelasticacheArray.prototype.flatMapescapeECMAScript 2015irqanimationUint32Arraycommanderflagprotobuffile systemcloudformationglobal objectqueueMicrotaskaccessibilityvalueslinuxpatchjsonschemanumberdomargspushvpcinputtddtakezerocolumnsjwtfastifyeslintpluginidentifiersstablestylingchildmkdirTypeBoxglobalThiscryptInt8ArrayownfindLastcallboundxtermsafedeleteartECMAScript 2020fullresolvedatastructurestringifyECMAScript 2018css-in-jsassertimmutabletrimEndstylesheetjson-schema-validatorRegExp.prototype.flagsWebSocketsasynccollectionfetchconcatfunctionssetImmediatetoobjectconfigurablesymlinktypedarraymake dirBigInt64Arrayincludesdeepcopycallprunetelephoneinterruptses2017ECMAScript 2022formsbrowserslistindicatorreadablestreamspinnersvestjsdomzxairbnbcss lessrequestjsrequireutil.inspectbcryptworkerregular expressioncloudwatchremovepackage managerES2019performanceprototypedragnodeprefixsuperagentoptimizerreducerautoscalingnativeReactiveXes7lastvalidationstyletestgestureslesscssenderenvrangeerrorjoirfc9562enumerableworkflowextrahttpbytehotdefinesomebeanstalkapiflagsmatchAllbintypanionflatendpointcall-boundspawnes2015Object.entrieseslintunicodeES6deep-clonespinnerlockfileArrayextendWeakSetswfforkchromiumECMAScript 2019colourebsequalityrfc4122streamJSONparsingerror-handlingCSStypesafeES2022__proto__command-linespecJSON-SchemapredictableenvironmentsbufferRxJSsequencebootstrap lessmaptrimLeftObject.definePropertygettypeerrorerrorregexpSymbolwaitchineseio-tsRFC-6455effect-tsECMAScript 2023querystringclass-validatorlruemitMapcodesreact-componentpromisepopmotionreact-hook-formpyyamlchai
7.6.82

10 months ago

7.6.81

10 months ago

7.6.80

10 months ago

7.6.79

10 months ago

7.6.78

10 months ago

7.6.77

10 months ago

7.5.77

10 months ago

7.5.76

11 months ago

7.5.75

11 months ago

7.5.74

11 months ago

7.5.73

11 months ago

7.5.72

11 months ago

7.5.71

11 months ago

7.5.70

11 months ago

7.5.69

11 months ago

7.5.68

11 months ago

7.5.67

11 months ago

7.5.66

11 months ago

7.5.65

11 months ago

6.5.65

11 months ago

6.5.64

11 months ago

6.5.63

11 months ago

5.5.63

11 months ago

5.5.62

11 months ago

5.5.61

11 months ago

4.5.61

11 months ago

4.4.61

11 months ago

4.4.60

11 months ago

4.4.59

11 months ago

4.4.58

11 months ago

4.4.57

11 months ago

4.4.56

11 months ago

4.3.56

11 months ago

4.3.55

11 months ago

4.3.54

11 months ago

4.3.53

11 months ago

4.3.52

11 months ago

4.3.51

12 months ago

4.3.50

12 months ago

4.3.49

12 months ago

4.3.48

12 months ago

4.2.48

12 months ago

4.2.47

12 months ago

4.2.46

12 months ago

4.2.45

12 months ago

4.2.44

12 months ago

4.2.43

12 months ago

4.2.42

12 months ago

4.2.41

12 months ago

4.2.40

12 months ago

4.2.39

12 months ago

4.2.38

12 months ago

4.2.37

12 months ago

4.2.36

12 months ago

4.2.35

12 months ago

4.2.34

12 months ago

4.2.33

12 months ago

4.2.32

1 year ago

4.2.31

1 year ago

4.2.30

1 year ago

4.2.29

1 year ago

4.1.29

1 year ago

4.1.28

1 year ago

4.0.28

1 year ago

4.0.27

1 year ago

4.0.26

1 year ago

4.0.25

1 year ago

4.0.24

1 year ago

3.0.24

1 year ago

3.0.23

1 year ago

3.0.22

1 year ago

3.0.21

1 year ago

3.0.20

1 year ago

3.0.19

1 year ago

3.0.18

1 year ago

3.0.17

1 year ago

3.0.16

1 year ago

3.0.15

1 year ago

3.0.14

1 year ago

3.0.13

1 year ago

3.0.12

1 year ago

3.0.11

1 year ago

3.0.10

1 year ago

3.0.9

1 year ago

3.0.8

1 year ago

3.0.7

1 year ago

2.0.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