Skip to content

Commit cd115ae

Browse files
authored
Merge pull request #3574 from mwiencek/wbt-0.9
Upgrade weight-balanced-tree to v0.9.0
2 parents 9e80fc4 + dd29c42 commit cd115ae

34 files changed

+280
-133
lines changed

.github/workflows/ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ on:
99
- translations
1010

1111
env:
12-
TESTS_IMAGE_TAG: v-2025-06-12
12+
TESTS_IMAGE_TAG: v-2025-06-16
1313

1414
jobs:
1515
build-tests-image:

eslint.config.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1040,6 +1040,7 @@ export default [
10401040
'root/static/scripts/edit/components/ExternalLinkAttributeDialog.js',
10411041
'root/static/scripts/edit/components/Multiselect.js',
10421042
'root/static/scripts/edit/components/withLoadedTypeInfo.js',
1043+
'root/static/scripts/edit/utility/compactEntityJson.js',
10431044
'root/static/scripts/edit/utility/reducerWithErrorHandling.js',
10441045
'root/static/scripts/edit/utility/subfieldErrors.js',
10451046
'root/static/scripts/guess-case/MB/GuessCase/Main.js',
@@ -1063,7 +1064,6 @@ export default [
10631064
'root/static/scripts/url/edit.js',
10641065
'root/user/UserProfile.js',
10651066
'root/utility/chooseLayoutComponent.js',
1066-
'root/utility/compactEntityJson.js',
10671067
'root/utility/tableColumns.js',
10681068
],
10691069
rules: {

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@
6767
"terser-webpack-plugin": "5.3.14",
6868
"webpack": "5.99.9",
6969
"webpack-node-externals": "3.0.0",
70-
"weight-balanced-tree": "0.7.1",
70+
"weight-balanced-tree": "0.9.0",
7171
"whatwg-fetch": "3.6.20",
7272
"yargs": "3.10.0"
7373
},

root/static/scripts/edit/externalLinks.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,6 @@ import ko from 'knockout';
1414
import * as React from 'react';
1515
import * as ReactDOMClient from 'react-dom/client';
1616

17-
import {
18-
compactEntityJson,
19-
decompactEntityJson,
20-
} from '../../../utility/compactEntityJson.js';
2117
import invariant from '../../../utility/invariant.js';
2218
import {
2319
EMPTY_PARTIAL_DATE,
@@ -60,6 +56,10 @@ import RelationshipPendingEditsWarning
6056
import RemoveButton from './components/RemoveButton.js';
6157
import URLInputPopover from './components/URLInputPopover.js';
6258
import withLoadedTypeInfo from './components/withLoadedTypeInfo.js';
59+
import {
60+
compactEntityJson,
61+
decompactEntityJson,
62+
} from './utility/compactEntityJson.js';
6363
import isPositiveInteger from './utility/isPositiveInteger.js';
6464
import isShortenedUrl from './utility/isShortenedUrl.js';
6565
import {stripAttributes} from './utility/linkPhrase.js';

root/utility/compactEntityJson.js renamed to root/static/scripts/edit/utility/compactEntityJson.js

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ const functionToString: () => string =
2424
Function.prototype.toString;
2525
const objectCtorString: string = functionToString.call(Object);
2626

27+
const UNDEFINED_INDEX = -1;
28+
2729
function _indexValue(
2830
value: mixed,
2931
indexCache: Map<mixed, number>,
@@ -96,10 +98,13 @@ function _indexValue(
9698
}
9799
case 'bigint':
98100
case 'function':
99-
case 'symbol':
100-
case 'undefined': {
101+
case 'symbol': {
101102
throw new Error(`Cannot convert ${typeof value} to JSON`);
102103
}
104+
case 'undefined': {
105+
// Handled via `UNDEFINED_INDEX`.
106+
throw new Error('Unreachable');
107+
}
103108
}
104109

105110
result[index] = compactValue;
@@ -110,7 +115,9 @@ export function compactEntityJson(
110115
value: mixed,
111116
): $ReadOnlyArray<mixed> {
112117
const result: Array<mixed> = [];
113-
_indexValue(value, new Map(), result);
118+
const indexCache = new Map<mixed, number>();
119+
indexCache.set(undefined, UNDEFINED_INDEX);
120+
_indexValue(value, indexCache, result);
114121
return result;
115122
}
116123

@@ -125,6 +132,9 @@ export function decompactEntityJson(
125132
function _decompactIndex(
126133
index: number,
127134
): mixed {
135+
if (index === UNDEFINED_INDEX) {
136+
return undefined;
137+
}
128138
const value = compactedArray[index];
129139
if (typeof value === 'object' && value !== null) {
130140
const resolvedValue = resolved[index];

root/static/scripts/relationship-editor/components/DialogAttributes.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -165,9 +165,9 @@ export function createInitialState(
165165

166166
function getLinkAttributesFromState(
167167
attributesList: DialogAttributesT,
168-
): tree.ImmutableTree<LinkAttrT> | null {
168+
): tree.ImmutableTree<LinkAttrT> {
169169
return attributesList.reduce((
170-
accum: tree.ImmutableTree<LinkAttrT> | null,
170+
accum: tree.ImmutableTree<LinkAttrT>,
171171
attributeState,
172172
) => {
173173
switch (attributeState.control) {
@@ -235,7 +235,7 @@ function getLinkAttributesFromState(
235235
}
236236
}
237237
return accum;
238-
}, null);
238+
}, tree.empty);
239239
}
240240

241241
export function reducer(

root/static/scripts/relationship-editor/components/DialogPreview.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ const createRelationshipTFromState = (
3535
const hasDates = linkType ? linkType.has_dates : true;
3636

3737
return {
38-
attributes: tree.toArray(relationship.attributes),
38+
attributes: tree.toArray(relationship.attributes ?? tree.empty),
3939
backward,
4040
begin_date: hasDates ? relationship.begin_date : null,
4141
editsPending: relationship.editsPending,

root/static/scripts/relationship-editor/components/RelationshipDialogContent.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,9 @@ export function createInitialState(props: PropsT): RelationshipDialogStateT {
182182
return {
183183
attributes: createDialogAttributesState(
184184
linkType,
185-
getAttributeRootIdMap(tree.toArray(relationship.attributes)),
185+
getAttributeRootIdMap(
186+
tree.toArray(relationship.attributes ?? tree.empty),
187+
),
186188
),
187189
backward,
188190
datePeriod: createDialogDatePeriodState(relationship),

root/static/scripts/relationship-editor/components/RelationshipEditor.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ import {
1818
onConflictUseGivenValue,
1919
} from 'weight-balanced-tree/update';
2020

21-
import {decompactEntityJson} from '../../../../utility/compactEntityJson.js';
2221
import {INSTRUMENT_ROOT_ID, VOCAL_ROOT_ID} from '../../common/constants.js';
2322
import MB from '../../common/MB.js';
2423
import {
@@ -32,6 +31,7 @@ import {
3231
hasSessionStorage,
3332
sessionStorageWrapper,
3433
} from '../../common/utility/storage.js';
34+
import {decompactEntityJson} from '../../edit/utility/compactEntityJson.js';
3535
import reducerWithErrorHandling
3636
from '../../edit/utility/reducerWithErrorHandling.js';
3737
import {
@@ -183,9 +183,9 @@ export function createInitialState(
183183
const newState: {...RelationshipEditorStateT} = {
184184
dialogLocation: null,
185185
entity: source,
186-
existingRelationshipsBySource: null,
186+
existingRelationshipsBySource: tree.empty,
187187
reducerError: null,
188-
relationshipsBySource: null,
188+
relationshipsBySource: tree.empty,
189189
};
190190

191191
if (source.relationships) {

root/static/scripts/relationship-editor/components/RelationshipItem.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ component _RelationshipItem(
138138
return bracketedText(
139139
displayLinkAttributesText(getPhraseAndExtraAttributesText(
140140
linkType,
141-
tree.toArray(relationship.attributes),
141+
tree.toArray(relationship.attributes ?? tree.empty),
142142
backward ? 'reverse_link_phrase' : 'link_phrase',
143143
canBeOrdered /* forGrouping */,
144144
)[1]),

0 commit comments

Comments
 (0)