Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "data-monorepo",
"version": "0.9.69",
"version": "0.9.70",
"private": true,
"scripts": {
"build": "pnpm -r run build",
Expand Down
2 changes: 1 addition & 1 deletion packages/data-gpu-samples/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "data-gpu-samples",
"version": "0.9.69",
"version": "0.9.70",
"description": "WebGPU samples built on @adobe/data-gpu",
"type": "module",
"private": true,
Expand Down
2 changes: 1 addition & 1 deletion packages/data-gpu/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@adobe/data-gpu",
"version": "0.9.69",
"version": "0.9.70",
"description": "Adobe data WebGPU plugins and types for graphics and compute",
"type": "module",
"private": false,
Expand Down
2 changes: 1 addition & 1 deletion packages/data-lit-tictactoe/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "data-lit-tictactoe",
"version": "0.9.69",
"version": "0.9.70",
"description": "Tic-Tac-Toe sample - Lit web components with @adobe/data-lit and AgenticService",
"type": "module",
"private": true,
Expand Down
2 changes: 1 addition & 1 deletion packages/data-lit-todo/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "data-lit-todo",
"version": "0.9.69",
"version": "0.9.70",
"description": "Todo sample app demonstrating @adobe/data with Lit",
"type": "module",
"private": true,
Expand Down
2 changes: 1 addition & 1 deletion packages/data-lit/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@adobe/data-lit",
"version": "0.9.69",
"version": "0.9.70",
"description": "Adobe data Lit bindings - hooks, elements, decorators",
"type": "module",
"private": false,
Expand Down
2 changes: 1 addition & 1 deletion packages/data-p2p-tictactoe/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "data-p2p-tictactoe",
"version": "0.9.69",
"version": "0.9.70",
"description": "Serverless P2P tic-tac-toe — WebRTC DataChannel + @adobe/data-sync",
"type": "module",
"private": true,
Expand Down
2 changes: 1 addition & 1 deletion packages/data-persistence/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@adobe/data-persistence",
"version": "0.9.69",
"version": "0.9.70",
"description": "Worker-based incremental persistence layer for @adobe/data ECS over OPFS (browser) and node:fs (server).",
"type": "module",
"sideEffects": false,
Expand Down
2 changes: 1 addition & 1 deletion packages/data-react-hello/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "data-react-hello",
"version": "0.9.69",
"version": "0.9.70",
"description": "Hello World sample - click counter using @adobe/data-react",
"type": "module",
"private": true,
Expand Down
2 changes: 1 addition & 1 deletion packages/data-react-pixie/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "data-react-pixie",
"version": "0.9.69",
"version": "0.9.70",
"description": "PixiJS React sample - ECS sprites (bunny, fox) with @adobe/data-react",
"type": "module",
"private": true,
Expand Down
2 changes: 1 addition & 1 deletion packages/data-react/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@adobe/data-react",
"version": "0.9.69",
"version": "0.9.70",
"description": "Adobe data React bindings — hooks and context for ECS database",
"type": "module",
"private": false,
Expand Down
2 changes: 1 addition & 1 deletion packages/data-solid-dashboard/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "data-solid-dashboard",
"version": "0.9.69",
"version": "0.9.70",
"description": "Mini dashboard sample — multiple components sharing one @adobe/data ECS database with SolidJS",
"type": "module",
"private": true,
Expand Down
2 changes: 1 addition & 1 deletion packages/data-solid/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@adobe/data-solid",
"version": "0.9.69",
"version": "0.9.70",
"description": "Adobe data SolidJS bindings — context and provider for ECS database",
"type": "module",
"private": false,
Expand Down
2 changes: 1 addition & 1 deletion packages/data-sync/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@adobe/data-sync",
"version": "0.9.69",
"version": "0.9.70",
"description": "Multi-user real-time synchronisation for @adobe/data ECS — server, client, and in-process loopback.",
"type": "module",
"sideEffects": false,
Expand Down
2 changes: 1 addition & 1 deletion packages/data/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@adobe/data",
"version": "0.9.69",
"version": "0.9.70",
"description": "Adobe data oriented programming library",
"type": "module",
"sideEffects": false,
Expand Down
20 changes: 19 additions & 1 deletion packages/data/src/observe/with-batch.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// © 2026 Adobe. MIT License. See /LICENSE for details.
import { describe, it, expect, vi } from 'vitest';
import { describe, it, expect } from 'vitest';
import { withBatch } from './with-batch.js';
import { createState } from './create-state.js';

Expand Down Expand Up @@ -118,4 +118,22 @@ describe('withBatch', () => {
unsubscribe1();
unsubscribe2();
});

it('should not drop a batched undefined value', async () => {
const [source, setSource] = createState<number | undefined>(1);
const batched = withBatch(source);

const values: (number | undefined)[] = [];
const unsubscribe = batched((value) => values.push(value));

expect(values).toEqual([1]);

setSource(undefined);

await new Promise(resolve => setTimeout(resolve, 0));

expect(values).toEqual([1, undefined]);

unsubscribe();
});
});
15 changes: 8 additions & 7 deletions packages/data/src/observe/with-batch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,19 @@ import { Observe } from "./index.js";
*/
export function withBatch<T>(observable: Observe<T>): Observe<T> {
return (observer) => {
let pendingValue: T | undefined;
let pendingValue: T;
let hasPendingValue = false;
let isScheduled = false;
let hasInitialValue = false;

const scheduleNotification = () => {
if (!isScheduled) {
isScheduled = true;
queueMicrotask(() => {
if (pendingValue !== undefined) {
observer(pendingValue);
pendingValue = undefined;
if (hasPendingValue) {
const value = pendingValue;
hasPendingValue = false;
observer(value);
}
isScheduled = false;
});
Expand All @@ -27,19 +29,18 @@ export function withBatch<T>(observable: Observe<T>): Observe<T> {

const unobserve = observable((value) => {
if (!hasInitialValue) {
// Emit initial value immediately
observer(value);
hasInitialValue = true;
} else {
// Batch subsequent values
pendingValue = value;
hasPendingValue = true;
scheduleNotification();
}
});

return () => {
unobserve();
pendingValue = undefined;
hasPendingValue = false;
isScheduled = false;
hasInitialValue = false;
};
Expand Down
43 changes: 43 additions & 0 deletions packages/data/src/observe/with-deduplicate-data.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
// © 2026 Adobe. MIT License. See /LICENSE for details.
import { describe, it, expect } from 'vitest';
import { withDeduplicateData } from './with-deduplicate-data.js';
import { Observe } from './index.js';

describe('withDeduplicateData', () => {
it('should emit first value', () => {
const source: Observe<number> = (observer) => {
observer(1);
return () => {};
};
const values: number[] = [];
withDeduplicateData(source)((v) => values.push(v));
expect(values).toEqual([1]);
});

it('should deduplicate consecutive equal values', () => {
const source: Observe<number> = (observer) => {
observer(1);
observer(1);
observer(2);
observer(2);
return () => {};
};
const values: number[] = [];
withDeduplicateData(source)((v) => values.push(v));
expect(values).toEqual([1, 2]);
});

// Defensive: T extends Data excludes undefined at compile time, but runtime
// guards should hold even if undefined arrives via any/generics.
it('should deduplicate consecutive undefined values (defensive)', () => {
const source = ((observer: (v: null) => void) => {
(observer as (v: unknown) => void)(undefined);
(observer as (v: unknown) => void)(undefined);
return () => {};
}) satisfies Observe<null>;

const values: (null | undefined)[] = [];
withDeduplicateData(source)((v: any) => values.push(v));
expect(values).toEqual([undefined]);
});
});
6 changes: 4 additions & 2 deletions packages/data/src/observe/with-deduplicate-data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,12 @@ export function withDeduplicateData<T extends Data>(
observable: Observe<T>
): Observe<T> {
return (observer) => {
let lastValue: T | undefined = undefined;
let notified = false;
let lastValue: T;
return observable((value) => {
const notify = lastValue === undefined || !equals(lastValue, value);
const notify = !notified || !equals(lastValue, value);
if (notify) {
notified = true;
lastValue = value;
observer(value);
}
Expand Down
7 changes: 4 additions & 3 deletions packages/data/src/observe/with-filter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@
import { Observe } from "./index.js";

/**
* Creates a new Observe function that converts the original observe functions notify values into a new value at each notification,
* optionally returning undefined to filter out the value.
* Creates a new Observe function that converts values, using `undefined` (or `void`) as the skip signal.
* U must not include `undefined` — if the filter can legitimately produce `undefined` as a value,
* use `withMap` instead and handle absent values downstream.
*/
export function withFilter<T, U>(
export function withFilter<T, U extends {} | null>(
observable: Observe<T>,
filter: (value: T) => U | undefined | void
): Observe<U> {
Expand Down
16 changes: 16 additions & 0 deletions packages/data/src/observe/with-filter.type-test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// © 2026 Adobe. MIT License. See /LICENSE for details.

import { fromConstant } from "./from-constant.js";
import { withFilter } from "./with-filter.js";

// Valid uses: U is non-undefined
function _testValidUses() {
withFilter(fromConstant(1), (v) => v > 0 ? v : null);
withFilter(fromConstant("a"), (v) => v.length > 0 ? v : undefined);
withFilter(fromConstant(1), (v) => v > 0 ? v : undefined);
}

// Invalid: undefined is the skip sentinel; U must not include undefined.
// Explicit annotation with U = number | undefined must be rejected.
// @ts-expect-error — U explicitly includes undefined, which is disallowed
withFilter<number, number | undefined>(fromConstant(1), (v) => v > 0 ? v : undefined);