Skip to content

Commit

Permalink
wip: package.json and uncellify renaming
Browse files Browse the repository at this point in the history
  • Loading branch information
xikimay committed Apr 4, 2024
1 parent dc779b7 commit ad3ec29
Show file tree
Hide file tree
Showing 7 changed files with 90 additions and 231 deletions.
49 changes: 9 additions & 40 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,52 +1,21 @@
{
"name": "@okcontract/cells",
"version": "0.2.3",
"description": "Simplified reactive functional programming for the web",
"private": false,
"main": "dist/cells.umd.cjs",
"module": "dist/cells.js",
"description": "High-level Store",
"main": "src/index.ts",
"type": "module",
"exports": {
".": {
"import": "./dist/cells.js",
"require": "./dist/cells.umd.cjs",
"types": "./dist/index.d.ts"
}
},
"files": [
"dist/",
"assets/",
"README.md",
"LICENSE"
],
"dependencies": {
"@okcontract/graph": "0.1.3"
},
"dependencies": {},
"devDependencies": {
"@biomejs/biome": "^1.5.3",
"@types/node": "^20.11.5",
"@vitest/coverage-v8": "^1.3.1",
"happy-dom": "^13.0.2",
"immer": "^10.0.4",
"terser": "^5.26.0",
"typescript": "^5.3.3",
"vite": "^5.0.12",
"vitest": "^1.3.1"
"immer": "^10.0.2"
},
"scripts": {
"build": "npm run format && vite build",
"test": "vitest run",
"coverage": "vitest run --coverage",
"definitions": "tsc --project tsconfig.build.json",
"prepublishOnly": "npm test && npm run build && npm run check && npm run definitions",
"check": "npx @biomejs/biome check src",
"format": "npx @biomejs/biome format src --write && npx @biomejs/biome check src --apply",
"formatReadme": "prettier README.md --prose-wrap always --print-width 78 -w"
"build": "vite build",
"test": "vitest run --passWithNoTests --test-timeout=10000"
},
"repository": {
"type": "git",
"url": "git+https://github.com/okcontract/cells.git"
"url": "git+https://github.com/hbbio/lambdascript.git"
},
"author": "Henri Binsztok",
"license": "MIT"
}
"license": "UNLICENSED"
}
54 changes: 27 additions & 27 deletions src/array.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import {
sort
} from "./array";
import type { AnyCell } from "./cell";
import { cellify, uncellify } from "./cellify";
import { _cellify, _uncellify } from "./cellify";
import { delayed } from "./promise";
import { SheetProxy } from "./proxy";
import { Sheet } from "./sheet";
Expand All @@ -32,25 +32,25 @@ test("mapArray", async () => {
expect(sheet.stats.count).toBe(8); // +4 cells

// initial value
await expect(uncellify(m)).resolves.toEqual([2, 3, 4]);
await expect(_uncellify(m)).resolves.toEqual([2, 3, 4]);
expect(sheet.stats.count).toBe(8); // unchanged

// update one cell
(await l.get())[0].set(4);
await expect(uncellify(m)).resolves.toEqual([5, 3, 4]);
await expect(_uncellify(m)).resolves.toEqual([5, 3, 4]);
expect(sheet.stats.count).toBe(8); // @unchanged

// add one cell
l.update((arr) => [...arr, proxy.new(5)]);
await expect(uncellify(m)).resolves.toEqual([5, 3, 4, 6]);
await expect(_uncellify(m)).resolves.toEqual([5, 3, 4, 6]);
expect(sheet.stats.count).toBe(10); // +1 original cell, +1 new mapped

// get one cell
expect(await (await m.get())[3].get()).toBe(6);

// delete one cell
l.update((arr) => [...arr.slice(0, 1), ...arr.slice(1 + 1)]);
await expect(uncellify(m)).resolves.toEqual([5, 4, 6]);
await expect(_uncellify(m)).resolves.toEqual([5, 4, 6]);
expect(await (await m.get())[2].get()).toBe(6);
expect(sheet.stats.count).toBe(10); // @unchanged
});
Expand All @@ -63,16 +63,16 @@ test("mapArrayCell function change", async () => {
const fn = proxy.new((v: AnyCell<number>) => v.map((v) => v + 1));
const m = mapArrayCell(proxy, l, fn);
expect(sheet.stats.count).toBe(9); // +4 cells
await expect(uncellify(m)).resolves.toEqual([2, 3, 4]);
await expect(_uncellify(m)).resolves.toEqual([2, 3, 4]);

// update one cell
(await l.get())[0].set(4);
await expect(uncellify(m)).resolves.toEqual([5, 3, 4]);
await expect(_uncellify(m)).resolves.toEqual([5, 3, 4]);
expect(sheet.stats.count).toBe(9); // @unchanged

// function change
fn.set((v: AnyCell<number>) => v.map((v) => v - 1));
await expect(uncellify(m)).resolves.toEqual([3, 1, 2]);
await expect(_uncellify(m)).resolves.toEqual([3, 1, 2]);
expect(sheet.stats.count).toBe(12); // +3 new mapped cells
});

Expand All @@ -86,27 +86,27 @@ test("mapArray async", async () => {
expect(sheet.stats.count).toBe(8); // +4 cells

// initial value
await expect(uncellify(m)).resolves.toEqual([2, 3, 4]);
await expect(_uncellify(m)).resolves.toEqual([2, 3, 4]);
expect(sheet.stats.count).toBe(8); // unchanged

// update one cell
(await l.get())[0].set(4);
await proxy.working.wait();
await expect(uncellify(m)).resolves.toEqual([5, 3, 4]);
await expect(_uncellify(m)).resolves.toEqual([5, 3, 4]);
expect(sheet.stats.count).toBe(8); // @unchanged

// add one cell
l.update((arr) => [...arr, proxy.new(5)]);
await proxy.working.wait();
await expect(uncellify(m)).resolves.toEqual([5, 3, 4, 6]);
await expect(_uncellify(m)).resolves.toEqual([5, 3, 4, 6]);
expect(sheet.stats.count).toBe(10); // +1 original cell, +1 new mapped

// get one cell
expect(await (await m.get())[3].get()).toBe(6);

// delete one cell
l.update((arr) => [...arr.slice(0, 1), ...arr.slice(1 + 1)]);
await expect(uncellify(m)).resolves.toEqual([5, 4, 6]);
await expect(_uncellify(m)).resolves.toEqual([5, 4, 6]);
expect(await (await m.get())[2].get()).toBe(6);
expect(sheet.stats.count).toBe(10); // @unchanged
});
Expand Down Expand Up @@ -161,18 +161,18 @@ test("sort array", async () => {
const l = proxy.new([1, 5, 3].map((v) => proxy.new(v)));
const s = sort(proxy, l);

await expect(uncellify(s)).resolves.toEqual([1, 3, 5]);
await expect(_uncellify(s)).resolves.toEqual([1, 3, 5]);
expect(sheet.stats.count).toBe(6); // 3+1 array +1 sorted +1 pointer

// update one cell
(await l.get())[0].set(4);
await expect(uncellify(s)).resolves.toEqual([3, 4, 5]);
await expect(_uncellify(s)).resolves.toEqual([3, 4, 5]);
expect(sheet.stats.count).toBe(6); // @unchanged

// add one cell
l.update((arr) => [...arr, proxy.new(1)]);
await expect(uncellify(l)).resolves.toEqual([4, 5, 3, 1]);
await expect(uncellify(s)).resolves.toEqual([1, 3, 4, 5]);
await expect(_uncellify(l)).resolves.toEqual([4, 5, 3, 1]);
await expect(_uncellify(s)).resolves.toEqual([1, 3, 4, 5]);
expect(sheet.stats.count).toBe(8); // +1 original cell +1 sorted pointer
});

Expand All @@ -189,18 +189,18 @@ test("filter array", async () => {

// we wait before expecting
await proxy.working.wait();
await expect(uncellify(f)).resolves.toEqual([5, 3]);
await expect(_uncellify(f)).resolves.toEqual([5, 3]);
// the removed cell is not deleted ("garbage collected" at proxy level)
expect(sheet.stats.count).toBe(7); // unchanged

// update one cell
(await l.get())[0].set(4);
await expect(uncellify(f)).resolves.toEqual([4, 5, 3]);
await expect(_uncellify(f)).resolves.toEqual([4, 5, 3]);
expect(sheet.stats.count).toBe(7); // unchanged

// change predicate
pred.set((v) => v > 3);
await expect(uncellify(f)).resolves.toEqual([4, 5]);
await expect(_uncellify(f)).resolves.toEqual([4, 5]);
expect(sheet.stats).toEqual({ size: 7, count: 8 }); // one pointer updated
});

Expand All @@ -217,11 +217,11 @@ test("filterPredicateCell array", async () => {

// we wait before expecting
await proxy.working.wait();
await expect(uncellify(f)).resolves.toEqual([5, 3]);
await expect(_uncellify(f)).resolves.toEqual([5, 3]);

pred.set((v: AnyCell<number>) => v.map((_v) => _v > 3));
await proxy.working.wait();
await expect(uncellify(f)).resolves.toEqual([5]);
await expect(_uncellify(f)).resolves.toEqual([5]);
expect(sheet.stats).toEqual({ size: 11, count: 15 }); // we should not recreate mapped cells
});

Expand Down Expand Up @@ -259,20 +259,20 @@ test("sort array remapped", async () => {
Promise.resolve(0)
);

await expect(uncellify(s)).resolves.toEqual([1, 3, 5]);
await expect(_uncellify(s)).resolves.toEqual([1, 3, 5]);
expect(sheet.stats).toEqual({ size: 9, count: 9 }); // 3+1 array +1 sorted +1 pointer +1 sum +1 pointer
await expect(sum.get()).resolves.toBe(9);

// update one cell
(await l.get())[0].set(4);
await expect(uncellify(s)).resolves.toEqual([3, 4, 5]);
await expect(_uncellify(s)).resolves.toEqual([3, 4, 5]);
await expect(sum.get()).resolves.toBe(12);
expect(sheet.stats).toEqual({ size: 9, count: 10 }); // size unchanged, one pointer changed

// add one cell
l.update((arr) => [...arr, proxy.new(1)]);
await expect(uncellify(l)).resolves.toEqual([4, 5, 3, 1]);
await expect(uncellify(s)).resolves.toEqual([1, 3, 4, 5]);
await expect(_uncellify(l)).resolves.toEqual([4, 5, 3, 1]);
await expect(_uncellify(s)).resolves.toEqual([1, 3, 4, 5]);
await expect(sum.get()).resolves.toBe(13);
expect(sheet.stats).toEqual({ size: 10, count: 13 }); // +1 original cell, changed 2 pointers
});
Expand Down Expand Up @@ -300,7 +300,7 @@ test("basic find", async () => {
test("mapArrayRec array", async () => {
const sheet = new Sheet();
const proxy = new SheetProxy(sheet);
const arr = cellify(proxy, [1, 2, [3, [4]]]) as CellArray<number>;
const arr = _cellify(proxy, [1, 2, [3, [4]]]) as CellArray<number>;
const fl = mapArrayRec(proxy, arr, (x) => x + 1);
await expect(uncellify(fl)).resolves.toEqual([2, 3, [4, [5]]]);
await expect(_uncellify(fl)).resolves.toEqual([2, 3, [4, [5]]]);
});
10 changes: 5 additions & 5 deletions src/cell.ts
Original file line number Diff line number Diff line change
Expand Up @@ -962,11 +962,11 @@ export class MapCell<V, NF extends boolean> extends Cell<V, true, NF> {
false,
false
);
// this.sheet._debug &&
console.warn(
"cancelled",
simplifier({ paramsResults, firstCanceled, cell: this.id })
);
this.sheet._debug &&
console.warn(
"cancelled",
simplifier({ paramsResults, firstCanceled, cell: this.id })
);
return cancelComputation;
}
// set to CellError when depending on an Error
Expand Down
12 changes: 6 additions & 6 deletions src/cellify.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ import { expect, test } from "vitest";
import {
type Cellified,
type Uncellified,
cellify,
uncellify
_cellify,
_uncellify
} from "./cellify";
import { SheetProxy } from "./proxy";
import { Sheet } from "./sheet";
Expand Down Expand Up @@ -37,16 +37,16 @@ test("fix point", async () => {

for (let i = 0; i < tests.length; i++) {
const v = tests[i];
const c = cellify(proxy, v);
const u = await uncellify(c);
const c = _cellify(proxy, v);
const u = await _uncellify(c);
expect(u).toEqual(v);
}
});

test("cellify one", async () => {
test("_cellify one", async () => {
const sheet = new Sheet();
const proxy = new SheetProxy(sheet);
const res = cellify(proxy, { a: 1 });
const res = _cellify(proxy, { a: 1 });
const cell = await res.get();
await expect(cell.a.get()).resolves.toBe(1);
});

0 comments on commit ad3ec29

Please sign in to comment.