Skip to content

Commit d20a3bf

Browse files
committed
Revert some naming, etc.
1 parent a1f26d0 commit d20a3bf

10 files changed

Lines changed: 32 additions & 35 deletions

File tree

src/core/layer.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -61,11 +61,11 @@ export abstract class Layer {
6161

6262
public onEvent(_: EventContext): void {}
6363

64-
// Synchronous attach/detach. The source must be opened before a layer is attached
65-
// (see ChunkManager.viewFor) so creating the layer's view needs no async step.
66-
public attach(_context: IdetikContext): void {}
64+
// called when a layer is added to a viewport
65+
public onAttached(_context: IdetikContext): void {}
6766

68-
public detach(): void {}
67+
// called when a layer is removed from a viewport
68+
public onDetached(_context: IdetikContext): void {}
6969

7070
public get objects() {
7171
return this.objects_;

src/core/viewport.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ export class Viewport {
2929
public readonly events: EventDispatcher;
3030
public cameraControls?: CameraControls;
3131

32-
// Carried only to relay to `layer.attach` / `layer.detach`.
32+
// Carried only to relay to `layer.onAttached` / `layer.onDetached`.
3333
// To be removed when the chunk-infrastructure refactor folds chunk management
3434
// into the source and the attach lifecycle goes away.
3535
private readonly context_: IdetikContext;
@@ -72,7 +72,7 @@ export class Viewport {
7272

7373
public addLayer(layer: Layer): void {
7474
this.layers_.push(layer);
75-
layer.attach(this.context_);
75+
layer.onAttached(this.context_);
7676
}
7777

7878
public removeLayer(layer: Layer): void {
@@ -81,12 +81,12 @@ export class Viewport {
8181
throw new Error(`Layer to remove not found: ${layer}`);
8282
}
8383
this.layers_.splice(index, 1);
84-
layer.detach();
84+
layer.onDetached(this.context_);
8585
}
8686

8787
public removeAllLayers(): void {
8888
for (const layer of this.layers_) {
89-
layer.detach();
89+
layer.onDetached(this.context_);
9090
}
9191
this.layers_ = [];
9292
}

src/data/chunk.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,6 @@ export type SliceCoordinates = {
9999
};
100100

101101
export type ChunkSource = {
102-
/** The source's loader. Sources are opened by their factory, so this is synchronous. */
103102
getLoader(): ChunkLoader;
104103
};
105104

src/data/chunk_manager.ts

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,8 @@ export class ChunkManager {
2525
return chunkMemoryStats();
2626
}
2727

28-
/**
29-
* Creates a view for a source. The source is opened by its factory
30-
* (`OmeZarrImageSource.fromHttp(...)` / `fromFileSystem(...)`), so this is synchronous.
31-
*/
32-
public viewFor(
28+
/** Adds a view onto `source`'s store, creating the store on first use. */
29+
public addView(
3330
source: ChunkSource,
3431
policy: ImageSourcePolicy
3532
): ChunkStoreView {
@@ -38,7 +35,7 @@ export class ChunkManager {
3835
store = new ChunkStore(source.getLoader());
3936
this.stores_.set(source, store);
4037
}
41-
return store.createView(policy);
38+
return store.addView(policy);
4239
}
4340

4441
public update() {

src/data/chunk_store.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ export class ChunkStore {
126126
return this.loader_.loadChunkData(chunk, signal);
127127
}
128128

129-
public createView(policy: ImageSourcePolicy): ChunkStoreView {
129+
public addView(policy: ImageSourcePolicy): ChunkStoreView {
130130
const view = new ChunkStoreView(this, policy);
131131
this.views_.push(view);
132132
this.hasHadViews_ = true;

src/data/ome_zarr/image_source.ts

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -38,12 +38,9 @@ export class OmeZarrImageSource {
3838
private readonly loader_: OmeZarrImageLoader;
3939

4040
/**
41-
* Construct only via a static factory (`fromHttp`/`fromFileSystem`). A factory must
42-
* fully open the data up front — e.g. via {@link openLoader}, which resolves to a
43-
* ready loader or throws — and pass that loader in. The constructor therefore always
44-
* receives an opened loader, so a source instance is never in a half-open state
45-
* (`getLoader`/`getDimensions` cannot fail). To add a new factory, open the loader
46-
* first, then `new OmeZarrImageSource({ location, version, loader })`.
41+
* Private: construct via a static factory (`fromHttp`/`fromFileSystem`). Factories open
42+
* the loader up front and pass it in, so a source's loader is non-null.
43+
* errors opening a source surface early, and `getLoader`/`getDimensions` always succeed
4744
*/
4845
private constructor(props: OmeZarrImageSourceProps) {
4946
this.location = props.location;
@@ -96,7 +93,6 @@ export class OmeZarrImageSource {
9693
return this.getDimensions().c?.lods[0].size ?? 1;
9794
}
9895

99-
/** The source's loader, for synchronous view creation by the chunk manager. */
10096
public getLoader(): OmeZarrImageLoader {
10197
return this.loader_;
10298
}

src/layers/image_layer.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -73,13 +73,13 @@ export class ImageLayer extends Layer implements ChannelsEnabled {
7373
this.onPickValue_ = onPickValue;
7474
}
7575

76-
public attach(context: IdetikContext): void {
76+
public onAttached(context: IdetikContext): void {
7777
if (this.chunkStoreView_) {
7878
throw new Error(
7979
"ImageLayer cannot be attached to multiple viewports simultaneously."
8080
);
8181
}
82-
this.chunkStoreView_ = context.chunkManager.viewFor(
82+
this.chunkStoreView_ = context.chunkManager.addView(
8383
this.source_,
8484
this.policy_
8585
);
@@ -100,7 +100,7 @@ export class ImageLayer extends Layer implements ChannelsEnabled {
100100
}
101101
}
102102

103-
public detach(): void {
103+
public onDetached(_context: IdetikContext): void {
104104
if (!this.chunkStoreView_) return;
105105
this.releaseAndRemoveChunks(this.visibleChunks_.keys());
106106
this.clearObjects();

src/layers/label_layer.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,13 +66,13 @@ export class LabelLayer extends Layer {
6666
this.outlineSelected_ = outlineSelected;
6767
}
6868

69-
public attach(context: IdetikContext): void {
69+
public onAttached(context: IdetikContext): void {
7070
if (this.chunkStoreView_) {
7171
throw new Error(
7272
"LabelLayer cannot be attached to multiple viewports simultaneously."
7373
);
7474
}
75-
this.chunkStoreView_ = context.chunkManager.viewFor(
75+
this.chunkStoreView_ = context.chunkManager.addView(
7676
this.source_,
7777
this.policy_
7878
);
@@ -86,7 +86,7 @@ export class LabelLayer extends Layer {
8686
}
8787
}
8888

89-
public detach(): void {
89+
public onDetached(_context: IdetikContext): void {
9090
if (!this.chunkStoreView_) return;
9191
this.releaseAndRemoveChunks(this.visibleChunks_.keys());
9292
this.clearObjects();

src/layers/volume_layer.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -130,8 +130,13 @@ export class VolumeLayer extends Layer implements ChannelsEnabled {
130130
return volume;
131131
}
132132

133-
public attach(context: IdetikContext): void {
134-
this.chunkStoreView_ = context.chunkManager.viewFor(
133+
public onAttached(context: IdetikContext): void {
134+
if (this.chunkStoreView_) {
135+
throw new Error(
136+
"VolumeLayer cannot be attached to multiple viewports simultaneously."
137+
);
138+
}
139+
this.chunkStoreView_ = context.chunkManager.addView(
135140
this.source_,
136141
this.sourcePolicy_
137142
);
@@ -142,7 +147,7 @@ export class VolumeLayer extends Layer implements ChannelsEnabled {
142147
);
143148
}
144149

145-
public detach(): void {
150+
public onDetached(_context: IdetikContext): void {
146151
if (!this.chunkStoreView_) return;
147152
for (const volume of this.currentVolumes_.values()) {
148153
this.releaseAndRemoveVolume(volume);

test/chunk_store_view.test.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ describe("ChunkStoreView disposal", () => {
99
const loader = createMockLoader();
1010
const store = new ChunkStore(loader);
1111
const policy = createNoPrefetchPolicy();
12-
const view = store.createView(policy);
12+
const view = store.addView(policy);
1313
const viewport = createTestViewport();
1414

1515
// mark some chunks as visible/needed
@@ -44,8 +44,8 @@ describe("ChunkStoreView disposal", () => {
4444
const store = new ChunkStore(loader);
4545
const policy = createNoPrefetchPolicy();
4646

47-
const view1 = store.createView(policy);
48-
const view2 = store.createView(policy);
47+
const view1 = store.addView(policy);
48+
const view2 = store.addView(policy);
4949
const viewport = createTestViewport();
5050

5151
// Both views mark same chunks as needed

0 commit comments

Comments
 (0)