[go: up one dir, main page]

Skip to main content

v0.19: Batch Controller.set(), Faster TypeScript

· 58 min read
Nathaniel Tucker
Creator of Reactive Data Client

v0.19 lets a Manager write a whole batch of streamed rows in one store update, type-checks endpoint code about 2x faster, and fixes a round of TypeScript and Vue issues.

Batch Controller.set() writes a whole stream of rows, like price tickers from a websocket, in one store update with ctrl.set([Ticker], rows). That is up to 95x faster than one set() per row.

Try both buttons below. This browser check starts from an empty store and times Promise.all of 500 set() calls against one batch set(). Both paths are one React commit, and each writes 500 new prices.

import { useController } from '@data-client/react';
import { Ticker, newPrices } from './Ticker';
import { useTimed, Timing } from './Timing';
import PriceHeader from './PriceHeader';

function PriceStream() {
  const ctrl = useController();
  const [perRowMs, perRow] = useTimed(newPrices, rows =>
    Promise.all(
      rows.map(row => ctrl.set(Ticker, { product_id: row.product_id }, row)),
    ),
  );
  const [batchMs, batch] = useTimed(newPrices, rows =>
    ctrl.set([Ticker], rows),
  );

  return (
    <>
      <PriceHeader />
      <dl className="stats">
        <Timing label="500 set() calls" ms={perRowMs} />
        <Timing label="1 batch set()" ms={batchMs} />
      </dl>
      <div className="buttonGroup">
        <button onClick={perRow}>set() per row</button>
        <button onClick={batch}>batch set()</button>
      </div>
    </>
  );
}
render(<PriceStream />);
Live Preview
Node setMany into a 500-entity store
50 rows20xOne set() per row 10.8 ms → set([Ticker], rows) 0.54 ms
500 rows95xOne set() per row 103 ms → set([Ticker], rows) 1.08 ms

Faster TypeScript: editors and tsc check RestEndpoint and resource() code about 2x faster with 40% less memory, and still report every error they reported before.

Checking 150 RestEndpoints with long paths
TypeScript 61.9xv0.18 3.83 s → v0.19 1.98 s
TypeScript 72.2xv0.18 1.5 s → v0.19 0.69 s

More in v0.19:

Breaking Changes:

Get ready for future releases:

Adopt new features: npx @data-client/codemods v0.19 src/ --improvements=only batches set() loops and drops workarounds 0.19 makes unnecessary

v0.18: Scalar, Typed File Downloads, Filter-aware Collections

· 11 min read
Nathaniel Tucker
Creator of Reactive Data Client

v0.18 focuses on richer data modeling for values that vary by request context, simpler typed downloads, and collection matching that better reflects real API filters.

New Features:

Other Improvements:

import { Collection, Entity, RestEndpoint, Scalar } from '@data-client/rest';

export class Company extends Entity {
  id = '';
  name = '';
  price = 0;
  pct_equity = 0;
  shares = 0;
}

const PortfolioScalar = new Scalar({
  lens: args => args[0]?.portfolio,
  key: 'portfolio',
  entity: Company,
});
Company.schema = {
  pct_equity: PortfolioScalar,
  shares: PortfolioScalar,
};

export const getCompanies = new RestEndpoint({
  path: '/companies',
  searchParams: {} as { portfolio: string },
  // `portfolio` is a lens, not a filter — the returned Company list is the same
  // regardless of lens. Dropping it from `argsKey` collapses every portfolio to
  // one Collection pk, so `Collection.queryKey()` finds the list on every
  // switch and `useSuspense` reuses it without refetching.
  schema: new Collection([Company], { argsKey: () => ({}) }),
});

export const getPortfolioColumns = new RestEndpoint({
  path: '/companies/columns',
  searchParams: {} as { portfolio: string },
  schema: new Collection([PortfolioScalar], {
    argsKey: ({ portfolio }: { portfolio: string }) => ({ portfolio }),
  }),
});
Live Preview

The example shows the same Company entities rendered through different portfolio lenses. Stable Entity fields are reused, while lens-dependent values are selected from separate Scalar cells.

Breaking Changes:

Using an AI agent? Install the migration skill — it runs the codemod, registers argsKey for args-dependent schemas, and handles the cases the codemod can't (class fields, dynamic method assignment, SFC <script> blocks, custom helpers):

npx skills add reactive/data-client --skill data-client-v0.18-migration
Run in your terminal

Otherwise, run the codemod directly — it covers the common cases:

npx jscodeshift -t https://dataclient.io/codemods/v0.18.js --extensions=ts,tsx,js,jsx src/
Run in your terminal

v0.16: Parallel Fetching, Collection.move, Lazy

· 12 min read
Nathaniel Tucker
Creator of Reactive Data Client

New Features:

Other Improvements:

Collection.move makes it easy to move entities between Collections with a single operation:

import { useController } from '@data-client/react';
import { TaskResource, type Task } from './TaskResource';

export default function TaskCard({ task }: { task: Task }) {
  const handleMove = () => ctrl.fetch(
    TaskResource.getList.move,
    { id: task.id },
    { id: task.id, status: task.status === 'backlog' ? 'in-progress' : 'backlog' },
  );
  const ctrl = useController();
  return (
    <div className="listItem">
      <span style={{ flex: 1 }}>{task.title}</span>
      <button onClick={handleMove}>
        {task.status === 'backlog' ? '\u25bc' : '\u25b2'}
      </button>
    </div>
  );
}
Live Preview

Breaking Changes:

Upgrade with an automated codemod for all breaking changes:

npx jscodeshift -t https://dataclient.io/codemods/v0.16.js --extensions=ts,tsx,js,jsx src/
Run in your terminal

v0.15: Vue 3, Collection.remove, useDebounce Upgrade

· 9 min read
Nathaniel Tucker
Creator of Reactive Data Client

New Platforms:

  • Vue 3 with full composables: useSuspense, useCache, useDLE, useController, useQuery

New Features:

Performance:

Breaking Changes:

Upgrade with an automated codemod for common breaking changes:

npx jscodeshift -t https://dataclient.io/codemods/v0.15.js --extensions=ts,tsx,js,jsx src/
Run in your terminal

v0.14: Streamlined Manager APIs, Performance, and GC

· 12 min read
Nathaniel Tucker
Creator of Reactive Data Client

Managers:

Manager APIs have been streamlined—flatter action shapes reduce code complexity and improve performance by minimizing distinct inline cache entries, while simpler configuration APIs make customization more delightful.

Performance:

Schema/Data Modeling:

Testing:

Garbage Collection:

  • GCPolicy - automatic garbage collection of stale data

Breaking Changes:

v0.13: NextJS App Router, Expo, React 19, Redux

· 8 min read
Nathaniel Tucker
Creator of Reactive Data Client

Platforms:

Testing:

Packages moved inside @data-client/react:

  • Redux
  • Hooks

Other Improvements

Breaking Changes:

note

Version 0.12 was skipped due to a publishing mishap.

v0.11 Queries, Queryable, and useQuery

· 11 min read
Nathaniel Tucker
Creator of Reactive Data Client

Besides the performance and data integrity benefits of normalizing the state, we get the added benefit of being able to safely access and query the store directly.

In this release we tune and simplify this functionality by unifying around the concepts of Querable Schemas. These include Entity, All, Collection, Query, and Union

The biggest impact of this change is the introduction of a new hook useQuery(), which allows direct store lookups using the Querable Schemas.

class User extends Entity {
username = '';
id = '';
groupId = '';
pk() {
return this.id;
}
static index = ['username' as const];
}

const bob = useQuery(User, { username: 'bob' });
const bob = useQuery(User, { id: '5' });

Similarly, we can lookup Querables with controller and snapshot using the controller.get

const bob = snapshot.get(User, { username: 'bob' });

Additionally, we have invested in further performance improvements, resulting in around a 2x performance increase for most operations and Queries being 16x faster.

Migration guide

Breaking Changes:

Other Highlights:

v0.10: Consistent Null Handling, URL Utilities

· 4 min read
Nathaniel Tucker
Creator of Reactive Data Client

This release focuses on consistency and extensibility. Null handling is now uniform across all schema types, making data transformations more predictable. New URL utilities enable custom URL construction and search parameter encoding.

class MyEndpoint<O extends RestGenerics = any> extends RestEndpoint<O> {
searchToString(searchParams) {
// Use qs library for complex nested object encoding
return qs.stringify(searchParams);
}
}
Migration guide

Breaking Changes:

Other Improvements:

v0.9: DevTools, Resource.extend, and Legacy Cleanup

· 7 min read
Nathaniel Tucker
Creator of Reactive Data Client

This release focuses on developer experience with a devtools button that appears in development mode, better DevTools history, and new controller methods like controller.expireAll() and controller.fetchIfStale().

Resource.extend() provides three powerful ways to customize resources - adding new endpoints, overriding existing ones, or deriving from base endpoints.

const UserResource = createResource({
path: '/users/:id',
schema: User,
}).extend('current', {
path: '/users/current',
});
Migration guide

Breaking Changes:

v0.2 Controller.fetch, async getHeaders, Collections

· 6 min read
Nathaniel Tucker
Creator of Reactive Data Client

Collections enable Arrays and Objects to be easily extended by pushing or unshifting new members. The namesake comes from Backbone Collections.

Collections are now the default schema for Resource.getList.

import { useController } from '@data-client/react';
import { TodoResource } from './TodoResource';

export default function CreateTodo({ userId }: { userId: number }) {
  const ctrl = useController();
  const handleKeyDown = async e => {
    if (e.key === 'Enter') {
      ctrl.fetch(TodoResource.getList.push, {
        userId,
        title: e.currentTarget.value,
        id: Math.random(),
      });
      e.currentTarget.value = '';
    }
  };
  return (
    <div className="listItem nogap">
      <label>
        <input type="checkbox" name="new" checked={false} disabled />
        <input type="text" onKeyDown={handleKeyDown} />
      </label>
    </div>
  );
}
Live Preview

Upgrading is quite simple, as @data-client/rest/next and @data-client/react/next were introduced to allow incremental adoption of the new APIs changed in this release. This makes the actual upgrade a simple import rename.

Other highlights include

For all details, keep reading: