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
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Michal Malý
Molstar
Commits
45822b2f
Commit
45822b2f
authored
6 years ago
by
David Sehnal
Browse files
Options
Downloads
Patches
Plain Diff
mol-state: StateBuilder.To.insert
parent
ae1920fa
No related branches found
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
src/mol-state/state/builder.ts
+21
-0
21 additions, 0 deletions
src/mol-state/state/builder.ts
src/mol-state/transform.ts
+5
-1
5 additions, 1 deletion
src/mol-state/transform.ts
src/mol-state/tree/transient.ts
+8
-0
8 additions, 0 deletions
src/mol-state/tree/transient.ts
with
34 additions
and
1 deletion
src/mol-state/state/builder.ts
+
21
−
0
View file @
45822b2f
...
@@ -69,6 +69,27 @@ namespace StateBuilder {
...
@@ -69,6 +69,27 @@ namespace StateBuilder {
return
new
To
(
this
.
state
,
t
.
ref
,
this
.
root
);
return
new
To
(
this
.
state
,
t
.
ref
,
this
.
root
);
}
}
/**
* Inserts a new transform that does not change the object type and move the original children to it.
*/
insert
<
T
extends
StateTransformer
<
A
,
A
,
any
>>
(
tr
:
T
,
params
?:
StateTransformer
.
Params
<
T
>
,
options
?:
Partial
<
StateTransform
.
Options
>
,
initialCellState
?:
Partial
<
StateObjectCell
.
State
>
):
To
<
StateTransformer
.
To
<
T
>>
{
// cache the children
const
children
=
this
.
state
.
tree
.
children
.
get
(
this
.
ref
).
toArray
();
// add the new node
const
t
=
tr
.
apply
(
this
.
ref
,
params
,
options
);
this
.
state
.
tree
.
add
(
t
,
initialCellState
);
// move the original children to the new node
for
(
const
c
of
children
)
{
this
.
state
.
tree
.
changeParent
(
c
,
t
.
ref
);
}
this
.
editInfo
.
count
++
;
this
.
editInfo
.
lastUpdate
=
t
.
ref
;
return
new
To
(
this
.
state
,
t
.
ref
,
this
.
root
);
}
update
<
T
extends
StateTransformer
<
any
,
A
,
any
>>
(
transformer
:
T
,
params
:
(
old
:
StateTransformer
.
Params
<
T
>
)
=>
StateTransformer
.
Params
<
T
>
):
Root
update
<
T
extends
StateTransformer
<
any
,
A
,
any
>>
(
transformer
:
T
,
params
:
(
old
:
StateTransformer
.
Params
<
T
>
)
=>
StateTransformer
.
Params
<
T
>
):
Root
update
(
params
:
any
):
Root
update
(
params
:
any
):
Root
update
<
T
extends
StateTransformer
<
any
,
A
,
any
>>
(
paramsOrTransformer
:
T
,
provider
?:
(
old
:
StateTransformer
.
Params
<
T
>
)
=>
StateTransformer
.
Params
<
T
>
)
{
update
<
T
extends
StateTransformer
<
any
,
A
,
any
>>
(
paramsOrTransformer
:
T
,
provider
?:
(
old
:
StateTransformer
.
Params
<
T
>
)
=>
StateTransformer
.
Params
<
T
>
)
{
...
...
This diff is collapsed.
Click to expand it.
src/mol-state/transform.ts
+
5
−
1
View file @
45822b2f
...
@@ -48,10 +48,14 @@ namespace Transform {
...
@@ -48,10 +48,14 @@ namespace Transform {
}
}
}
}
export
function
withParams
<
T
>
(
t
:
Transform
,
params
:
any
):
Transform
{
export
function
withParams
(
t
:
Transform
,
params
:
any
):
Transform
{
return
{
...
t
,
params
,
version
:
UUID
.
create22
()
};
return
{
...
t
,
params
,
version
:
UUID
.
create22
()
};
}
}
export
function
withParent
(
t
:
Transform
,
parent
:
Ref
):
Transform
{
return
{
...
t
,
parent
,
version
:
UUID
.
create22
()
};
}
export
function
createRoot
(
props
?:
Props
):
Transform
{
export
function
createRoot
(
props
?:
Props
):
Transform
{
return
create
(
RootRef
,
StateTransformer
.
ROOT
,
{},
{
ref
:
RootRef
,
props
});
return
create
(
RootRef
,
StateTransformer
.
ROOT
,
{},
{
ref
:
RootRef
,
props
});
}
}
...
...
This diff is collapsed.
Click to expand it.
src/mol-state/tree/transient.ts
+
8
−
0
View file @
45822b2f
...
@@ -90,6 +90,14 @@ class TransientTree implements StateTree {
...
@@ -90,6 +90,14 @@ class TransientTree implements StateTree {
this
.
childMutations
.
set
(
parent
,
set
);
this
.
childMutations
.
set
(
parent
,
set
);
}
}
changeParent
(
ref
:
StateTransform
.
Ref
,
newParent
:
StateTransform
.
Ref
)
{
ensurePresent
(
this
.
transforms
,
ref
);
const
old
=
this
.
transforms
.
get
(
ref
);
this
.
removeChild
(
old
.
parent
,
ref
);
this
.
addChild
(
newParent
,
ref
);
}
add
(
transform
:
StateTransform
,
initialState
?:
Partial
<
StateObjectCell
.
State
>
)
{
add
(
transform
:
StateTransform
,
initialState
?:
Partial
<
StateObjectCell
.
State
>
)
{
const
ref
=
transform
.
ref
;
const
ref
=
transform
.
ref
;
...
...
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