Skip to content

Commit

Permalink
fix(table): fix Table.Builder modifyAt not updating values in some cases
Browse files Browse the repository at this point in the history
  • Loading branch information
Arvid Nicolaas committed Dec 25, 2023
1 parent 265baea commit ccde660
Show file tree
Hide file tree
Showing 20 changed files with 204 additions and 124 deletions.
4 changes: 4 additions & 0 deletions deno_dist/actor/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@
All notable changes to this project will be documented in this file.
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.

## [0.13.1](https://github.com/rimbu-org/rimbu/compare/@rimbu/actor@0.13.0...@rimbu/actor@0.13.1) (2023-12-09)

**Note:** Version bump only for package @rimbu/actor

# [0.13.0](https://github.com/rimbu-org/rimbu/compare/@rimbu/actor@0.12.0...@rimbu/actor@0.13.0) (2023-07-29)

### Bug Fixes
Expand Down
4 changes: 4 additions & 0 deletions deno_dist/bimap/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@
All notable changes to this project will be documented in this file.
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.

## [1.1.1](https://github.com/rimbu-org/rimbu/compare/@rimbu/bimap@1.1.0...@rimbu/bimap@1.1.1) (2023-12-09)

**Note:** Version bump only for package @rimbu/bimap

# [1.1.0](https://github.com/rimbu-org/rimbu/compare/@rimbu/bimap@1.0.0...@rimbu/bimap@1.1.0) (2023-07-29)

### Bug Fixes
Expand Down
4 changes: 4 additions & 0 deletions deno_dist/bimultimap/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@
All notable changes to this project will be documented in this file.
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.

## [1.1.1](https://github.com/rimbu-org/rimbu/compare/@rimbu/bimultimap@1.1.0...@rimbu/bimultimap@1.1.1) (2023-12-09)

**Note:** Version bump only for package @rimbu/bimultimap

# [1.1.0](https://github.com/rimbu-org/rimbu/compare/@rimbu/bimultimap@1.0.0...@rimbu/bimultimap@1.1.0) (2023-07-29)

### Bug Fixes
Expand Down
4 changes: 4 additions & 0 deletions deno_dist/channel/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@
All notable changes to this project will be documented in this file.
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.

## [0.1.1](https://github.com/rimbu-org/rimbu/compare/@rimbu/channel@0.1.0...@rimbu/channel@0.1.1) (2023-12-09)

**Note:** Version bump only for package @rimbu/channel

# 0.1.0 (2023-07-29)

### Bug Fixes
Expand Down
4 changes: 4 additions & 0 deletions deno_dist/collection-types/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@
All notable changes to this project will be documented in this file.
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.

## [1.1.1](https://github.com/rimbu-org/rimbu/compare/@rimbu/collection-types@1.1.0...@rimbu/collection-types@1.1.1) (2023-12-09)

**Note:** Version bump only for package @rimbu/collection-types

# [1.1.0](https://github.com/rimbu-org/rimbu/compare/@rimbu/collection-types@1.0.0...@rimbu/collection-types@1.1.0) (2023-07-29)

### Bug Fixes
Expand Down
4 changes: 4 additions & 0 deletions deno_dist/core/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@
All notable changes to this project will be documented in this file.
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.

## [1.1.1](https://github.com/rimbu-org/rimbu/compare/@rimbu/core@1.1.0...@rimbu/core@1.1.1) (2023-12-09)

**Note:** Version bump only for package @rimbu/core

# [1.1.0](https://github.com/rimbu-org/rimbu/compare/@rimbu/core@1.0.0...@rimbu/core@1.1.0) (2023-07-29)

### Features
Expand Down
6 changes: 6 additions & 0 deletions deno_dist/graph/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,12 @@
All notable changes to this project will be documented in this file.
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.

## [1.1.1](https://github.com/rimbu-org/rimbu/compare/@rimbu/graph@1.1.0...@rimbu/graph@1.1.1) (2023-12-09)

### Bug Fixes

- fix @rimbu/channel not working in Deno ddue to wrong transpilation ([91f9144](https://github.com/rimbu-org/rimbu/commit/91f9144c4a35f28266b6154110db63dafb3dbd22))

# [1.1.0](https://github.com/rimbu-org/rimbu/compare/@rimbu/graph@1.0.0...@rimbu/graph@1.1.0) (2023-07-29)

### Bug Fixes
Expand Down
7 changes: 7 additions & 0 deletions deno_dist/hashed/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,13 @@
All notable changes to this project will be documented in this file.
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.

## [1.1.1](https://github.com/rimbu-org/rimbu/compare/@rimbu/hashed@1.1.0...@rimbu/hashed@1.1.1) (2023-12-09)

### Bug Fixes

- fix @rimbu/channel not working in Deno ddue to wrong transpilation ([91f9144](https://github.com/rimbu-org/rimbu/commit/91f9144c4a35f28266b6154110db63dafb3dbd22))
- **hashed:** fix HashMap using === instead of context.eq for get, addEntry and modifyAt ([ace8d5b](https://github.com/rimbu-org/rimbu/commit/ace8d5b352bca79af3e3d21d01341011561b9e2b))

# [1.1.0](https://github.com/rimbu-org/rimbu/compare/@rimbu/hashed@1.0.0...@rimbu/hashed@1.1.0) (2023-07-29)

### Bug Fixes
Expand Down
6 changes: 6 additions & 0 deletions deno_dist/list/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,12 @@
All notable changes to this project will be documented in this file.
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.

## [1.1.1](https://github.com/rimbu-org/rimbu/compare/@rimbu/list@1.1.0...@rimbu/list@1.1.1) (2023-12-09)

### Bug Fixes

- fix @rimbu/channel not working in Deno ddue to wrong transpilation ([91f9144](https://github.com/rimbu-org/rimbu/commit/91f9144c4a35f28266b6154110db63dafb3dbd22))

# [1.1.0](https://github.com/rimbu-org/rimbu/compare/@rimbu/list@1.0.0...@rimbu/list@1.1.0) (2023-07-29)

### Bug Fixes
Expand Down
4 changes: 4 additions & 0 deletions deno_dist/multimap/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@
All notable changes to this project will be documented in this file.
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.

## [1.1.1](https://github.com/rimbu-org/rimbu/compare/@rimbu/multimap@1.1.0...@rimbu/multimap@1.1.1) (2023-12-09)

**Note:** Version bump only for package @rimbu/multimap

# [1.1.0](https://github.com/rimbu-org/rimbu/compare/@rimbu/multimap@1.0.0...@rimbu/multimap@1.1.0) (2023-07-29)

### Bug Fixes
Expand Down
4 changes: 4 additions & 0 deletions deno_dist/multiset/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@
All notable changes to this project will be documented in this file.
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.

## [1.1.1](https://github.com/rimbu-org/rimbu/compare/@rimbu/multiset@1.1.0...@rimbu/multiset@1.1.1) (2023-12-09)

**Note:** Version bump only for package @rimbu/multiset

# [1.1.0](https://github.com/rimbu-org/rimbu/compare/@rimbu/multiset@1.0.0...@rimbu/multiset@1.1.0) (2023-07-29)

### Bug Fixes
Expand Down
4 changes: 4 additions & 0 deletions deno_dist/ordered/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@
All notable changes to this project will be documented in this file.
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.

## [1.1.1](https://github.com/rimbu-org/rimbu/compare/@rimbu/ordered@1.1.0...@rimbu/ordered@1.1.1) (2023-12-09)

**Note:** Version bump only for package @rimbu/ordered

# [1.1.0](https://github.com/rimbu-org/rimbu/compare/@rimbu/ordered@1.0.0...@rimbu/ordered@1.1.0) (2023-07-29)

### Bug Fixes
Expand Down
6 changes: 6 additions & 0 deletions deno_dist/proximity/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,12 @@
All notable changes to this project will be documented in this file.
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.

## [1.1.1](https://github.com/rimbu-org/rimbu/compare/@rimbu/proximity@1.1.0...@rimbu/proximity@1.1.1) (2023-12-09)

### Bug Fixes

- fix @rimbu/channel not working in Deno ddue to wrong transpilation ([91f9144](https://github.com/rimbu-org/rimbu/commit/91f9144c4a35f28266b6154110db63dafb3dbd22))

# [1.1.0](https://github.com/rimbu-org/rimbu/compare/@rimbu/proximity@1.0.0...@rimbu/proximity@1.1.0) (2023-07-29)

### Bug Fixes
Expand Down
4 changes: 4 additions & 0 deletions deno_dist/reactor/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@
All notable changes to this project will be documented in this file.
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.

## [0.13.1](https://github.com/rimbu-org/rimbu/compare/@rimbu/reactor@0.13.0...@rimbu/reactor@0.13.1) (2023-12-09)

**Note:** Version bump only for package @rimbu/reactor

# [0.13.0](https://github.com/rimbu-org/rimbu/compare/@rimbu/reactor@0.12.0...@rimbu/reactor@0.13.0) (2023-07-29)

### Features
Expand Down
7 changes: 7 additions & 0 deletions deno_dist/sorted/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,13 @@
All notable changes to this project will be documented in this file.
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.

## [1.1.1](https://github.com/rimbu-org/rimbu/compare/@rimbu/sorted@1.1.0...@rimbu/sorted@1.1.1) (2023-12-09)

### Bug Fixes

- **sorted:** fix sortedset and sortedmap builders not correctly clearing their source when modified ([196cb90](https://github.com/rimbu-org/rimbu/commit/196cb90cf712c4412fb539c6c78d147a475a8d8a))
- **sorted:** sortedSet remove should not use reference equality ([b340d70](https://github.com/rimbu-org/rimbu/commit/b340d7086adc31e8b7878dc06c40c14b01e717b3)), closes [#189](https://github.com/rimbu-org/rimbu/issues/189)

# [1.1.0](https://github.com/rimbu-org/rimbu/compare/@rimbu/sorted@1.0.0...@rimbu/sorted@1.1.0) (2023-07-29)

### Bug Fixes
Expand Down
6 changes: 6 additions & 0 deletions deno_dist/stream/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,12 @@
All notable changes to this project will be documented in this file.
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.

## [1.1.1](https://github.com/rimbu-org/rimbu/compare/@rimbu/stream@1.1.0...@rimbu/stream@1.1.1) (2023-12-09)

### Bug Fixes

- fix @rimbu/channel not working in Deno ddue to wrong transpilation ([91f9144](https://github.com/rimbu-org/rimbu/commit/91f9144c4a35f28266b6154110db63dafb3dbd22))

# [1.1.0](https://github.com/rimbu-org/rimbu/compare/@rimbu/stream@1.0.0...@rimbu/stream@1.1.0) (2023-07-29)

### Bug Fixes
Expand Down
4 changes: 4 additions & 0 deletions deno_dist/table/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@
All notable changes to this project will be documented in this file.
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.

## [1.1.1](https://github.com/rimbu-org/rimbu/compare/@rimbu/table@1.1.0...@rimbu/table@1.1.1) (2023-12-09)

**Note:** Version bump only for package @rimbu/table

# [1.1.0](https://github.com/rimbu-org/rimbu/compare/@rimbu/table@1.0.0...@rimbu/table@1.1.0) (2023-07-29)

### Bug Fixes
Expand Down
115 changes: 53 additions & 62 deletions deno_dist/table/custom/implementation/base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -269,48 +269,41 @@ export class TableNonEmpty<
): TpR['normal'] {
let newSize = this.size;

const { ifNew, ifExists } = options;
const newRowMap = this.rowMap.modifyAt(row, {
ifNew: (none) => {
const { ifNew } = options;

const passOptions: {
ifNew?: (none: Token) => RMap.NonEmpty<C, V> | Token;
ifExists?: (
currentEntry: RMap.NonEmpty<C, V>,
remove: typeof Token
) => typeof Token | RMap.NonEmpty<C, V>;
} = {};

if (undefined !== ifNew) {
passOptions.ifNew = (none): RMap.NonEmpty<C, V> | Token => {
const value = OptLazyOr<V, Token>(ifNew, Token);
if (undefined === ifNew) {
return none;
}
const value = OptLazyOr<V, Token>(ifNew, none);

if (Token === value) return none;
if (none === value) {
return none;
}

newSize++;

return this.context.columnContext.of([column, value]);
};
}

if (undefined !== ifExists) {
passOptions.ifExists = (
columns: RMap.NonEmpty<C, V>,
remove: Token
): typeof columns | typeof remove => {
const newColumns = columns.modifyAt(column, options);
},
ifExists: (row, remove) => {
const newRow = row.modifyAt(column, options);

if (newColumns === columns) return columns;
if (newRow === row) {
return row;
}

if (newColumns.nonEmpty()) {
newSize += newColumns.size - columns.size;
return newColumns;
if (!newRow.nonEmpty()) {
return remove;
}

newSize -= columns.size;
return remove;
};
}
newSize += newRow.size - row.size;

return this.copyE(this.rowMap.modifyAt(row, passOptions as any), newSize);
return newRow;
},
});

return this.copyE(newRowMap, newSize);
}

updateAt<UR, UC>(
Expand Down Expand Up @@ -741,48 +734,46 @@ export class TableBuilder<

let changed = false;

const { ifNew, ifExists } = options;
this.rowMap.modifyAt(row, {
ifNew: (none) => {
const { ifNew } = options;

const passOptions: {
ifNew?: (none: Token) => RMap.Builder<C, V> | Token;
ifExists?: (
currentValue: RMap.Builder<C, V>,
remove: typeof Token
) => typeof Token | RMap.Builder<C, V>;
} = {};
if (undefined === ifNew) {
return none;
}

if (undefined !== ifNew) {
passOptions.ifNew = (none): RMap.Builder<C, V> | Token => {
const columnBuilder = this.context.columnContext.builder<C, V>();
changed = columnBuilder.modifyAt(column, options);
const newValue = OptLazyOr<V, Token>(ifNew, none);

if (!changed) return none;
if (newValue === none) {
return none;
}

this._size++;
const rowMap = this.context.columnContext.builder<C, V>();

return columnBuilder;
};
}
rowMap.set(column, newValue);

if (undefined !== ifExists) {
passOptions.ifExists = (
columnBuilder,
remove
): RMap.Builder<C, V> | typeof remove => {
const preSize = columnBuilder.size;
changed = true;
this._size++;

changed = columnBuilder.modifyAt(column, options);
return rowMap;
},
ifExists: (curMap, remove) => {
const preSize = curMap.size;
changed = curMap.modifyAt(column, options);

this._size += columnBuilder.size - preSize;
if (changed) {
const postSize = curMap.size;

if (columnBuilder.isEmpty) return remove;
return columnBuilder;
};
}
this._size += postSize - preSize;

this.rowMap.modifyAt(row, passOptions);
if (postSize <= 0) {
return remove;
}
}

if (changed) this.source = undefined;
return curMap;
},
});

return changed;
};
Expand Down
Loading

0 comments on commit ccde660

Please sign in to comment.