Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
M
Molstar
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Michal Malý
Molstar
Commits
8a7c5f19
Commit
8a7c5f19
authored
6 years ago
by
David Sehnal
Browse files
Options
Downloads
Patches
Plain Diff
mol-state: improved cell state transition
parent
29583413
No related branches found
No related tags found
No related merge requests found
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/mol-state/state.ts
+28
-13
28 additions, 13 deletions
src/mol-state/state.ts
src/mol-state/tree/transient.ts
+4
-0
4 additions, 0 deletions
src/mol-state/tree/transient.ts
with
32 additions
and
13 deletions
src/mol-state/state.ts
+
28
−
13
View file @
8a7c5f19
...
...
@@ -296,15 +296,16 @@ async function update(ctx: UpdateContext) {
roots
=
findUpdateRoots
(
ctx
.
cells
,
ctx
.
tree
);
}
let
newCellStates
:
StateTree
.
CellStates
;
if
(
!
ctx
.
editInfo
)
{
newCellStates
=
ctx
.
tree
.
cellStatesSnapshot
();
syncOldStates
(
ctx
);
}
// Init empty cells where not present
// this is done in "pre order", meaning that "parents" will be created 1st.
const
addedCells
=
initCells
(
ctx
,
roots
);
// Ensure cell states stay consistent
if
(
!
ctx
.
editInfo
)
{
syncStates
(
ctx
);
}
// Notify additions of new cells.
for
(
const
cell
of
addedCells
)
{
ctx
.
parent
.
events
.
cell
.
created
.
next
({
state
:
ctx
.
parent
,
ref
:
cell
.
transform
.
ref
,
cell
});
...
...
@@ -327,6 +328,11 @@ async function update(ctx: UpdateContext) {
await
updateSubtree
(
ctx
,
root
);
}
// Sync cell states
if
(
!
ctx
.
editInfo
)
{
syncNewStates
(
ctx
,
newCellStates
!
);
}
let
newCurrent
:
StateTransform
.
Ref
|
undefined
=
ctx
.
newCurrent
;
// Raise object updated events
for
(
const
update
of
ctx
.
results
)
{
...
...
@@ -386,16 +392,25 @@ function findDeletes(ctx: UpdateContext): Ref[] {
return
deleteCtx
.
deletes
;
}
function
syncStatesVisitor
(
n
:
StateTransform
,
tree
:
StateTree
,
ctx
:
{
oldState
:
StateTree
.
CellStates
,
newState
:
StateTree
.
CellStates
,
changes
:
StateTransform
.
Ref
[]
})
{
if
(
!
ctx
.
oldState
.
has
(
n
.
ref
))
return
;
const
changed
=
StateObjectCell
.
isStateChange
(
ctx
.
oldState
.
get
(
n
.
ref
)
!
,
ctx
.
newState
.
get
(
n
.
ref
)
!
);
(
tree
as
TransientTree
).
updateCellState
(
n
.
ref
,
ctx
.
newState
.
get
(
n
.
ref
));
function
syncOldStatesVisitor
(
n
:
StateTransform
,
tree
:
StateTree
,
oldState
:
StateTree
.
CellStates
)
{
if
(
oldState
.
has
(
n
.
ref
))
{
(
tree
as
TransientTree
).
updateCellState
(
n
.
ref
,
oldState
.
get
(
n
.
ref
));
}
}
function
syncOldStates
(
ctx
:
UpdateContext
)
{
StateTree
.
doPreOrder
(
ctx
.
tree
,
ctx
.
tree
.
root
,
ctx
.
oldTree
.
cellStates
,
syncOldStatesVisitor
);
}
function
syncNewStatesVisitor
(
n
:
StateTransform
,
tree
:
StateTree
,
ctx
:
{
newState
:
StateTree
.
CellStates
,
changes
:
StateTransform
.
Ref
[]
})
{
if
(
ctx
.
newState
.
has
(
n
.
ref
))
{
const
changed
=
(
tree
as
TransientTree
).
updateCellState
(
n
.
ref
,
ctx
.
newState
.
get
(
n
.
ref
));
if
(
changed
)
{
ctx
.
changes
.
push
(
n
.
ref
);
}
}
function
syncStates
(
ctx
:
UpdateContext
)
{
StateTree
.
doPreOrder
(
ctx
.
tree
,
ctx
.
tree
.
root
,
{
newState
:
ctx
.
tree
.
cellStates
,
oldState
:
ctx
.
oldTree
.
cellStates
,
changes
:
ctx
.
stateChanges
},
syncStatesVisitor
);
}
function
syncNewStates
(
ctx
:
UpdateContext
,
newState
:
StateTree
.
CellStates
)
{
StateTree
.
doPreOrder
(
ctx
.
tree
,
ctx
.
tree
.
root
,
{
newState
,
changes
:
ctx
.
stateChanges
},
syncNewStatesVisitor
);
}
function
setCellStatus
(
ctx
:
UpdateContext
,
ref
:
Ref
,
status
:
StateObjectCell
.
Status
,
errorText
?:
string
)
{
...
...
This diff is collapsed.
Click to expand it.
src/mol-state/tree/transient.ts
+
4
−
0
View file @
8a7c5f19
...
...
@@ -49,6 +49,10 @@ class TransientTree implements StateTree {
get
root
()
{
return
this
.
transforms
.
get
(
StateTransform
.
RootRef
)
!
}
cellStatesSnapshot
()
{
return
this
.
cellStates
.
asImmutable
();
}
asTransient
()
{
return
this
.
asImmutable
().
asTransient
();
}
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment