Skip to content
Snippets Groups Projects
Commit b40df2f1 authored by Alexander Rose's avatar Alexander Rose
Browse files

sequence, on state tree change improvments

parent 884cb0d9
Branches
Tags
No related merge requests found
......@@ -513,6 +513,11 @@ namespace Structure {
return areEquivalent(a.parent || a, b.parent || b)
}
/** Check if the structures or their parents are equal */
export function areParentsEqual(a: Structure, b: Structure) {
return (a.parent || a) === (b.parent || b)
}
export class ElementLocationIterator implements Iterator<StructureElement> {
private current = StructureElement.create();
private unitIndex = 0;
......
......@@ -128,7 +128,9 @@ export class SequenceView extends PluginUIComponent<{ }, SequenceViewState> {
this.subscribe(this.plugin.state.behavior.currentObject, o => {
const current = this.plugin.state.dataState.cells.get(o.ref)!;
this.spine.current = current
if (!Structure.areParentsEqual(this.state.structure, this.getStructure())) {
this.setState(this.getInitialState())
}
});
this.subscribe(this.plugin.events.state.object.updated, ({ ref, state }) => {
......
......@@ -36,15 +36,15 @@ namespace StateTreeSpine {
getRootOfType<T extends StateObject.Ctor>(t: T): StateObject.From<T> | undefined {
if (!this._current) return void 0;
let cell = this._current;
let cell = this._current; // check current first
let ret: StateObjectCell | undefined = void 0;
while (true) {
cell = this.cells.get(cell.transform.parent)!;
if (!cell.obj) return void 0;
if (cell.obj.type === t.type) {
ret = cell;
}
if (cell.transform.ref === StateTransform.RootRef) return ret ? ret.obj as StateObject.From<T> : void 0;
cell = this.cells.get(cell.transform.parent)!; // assign parent for next check
}
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment