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
dbb9d5a3
Commit
dbb9d5a3
authored
7 years ago
by
David Sehnal
Browse files
Options
Downloads
Patches
Plain Diff
Added ValueBox/Cell to mol-util
parent
d4ed6cc7
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/mol-util/index.ts
+1
-0
1 addition, 0 deletions
src/mol-util/index.ts
src/mol-util/value-cell.ts
+24
-0
24 additions, 0 deletions
src/mol-util/value-cell.ts
with
25 additions
and
0 deletions
src/mol-util/index.ts
+
1
−
0
View file @
dbb9d5a3
...
@@ -10,6 +10,7 @@ import StringBuilder from './string-builder'
...
@@ -10,6 +10,7 @@ import StringBuilder from './string-builder'
import
UUID
from
'
./uuid
'
import
UUID
from
'
./uuid
'
import
Mask
from
'
./mask
'
import
Mask
from
'
./mask
'
export
*
from
'
./value-cell
'
export
{
BitFlags
,
StringBuilder
,
UUID
,
Mask
}
export
{
BitFlags
,
StringBuilder
,
UUID
,
Mask
}
export
function
arrayEqual
<
T
>
(
arr1
:
T
[],
arr2
:
T
[])
{
export
function
arrayEqual
<
T
>
(
arr1
:
T
[],
arr2
:
T
[])
{
...
...
This diff is collapsed.
Click to expand it.
src/mol-util/value-cell.ts
0 → 100644
+
24
−
0
View file @
dbb9d5a3
/**
* Copyright (c) 2018 mol* contributors, licensed under MIT, See LICENSE file for more info.
*
* @author David Sehnal <david.sehnal@gmail.com>
*/
/** A mutable value cell. */
interface
ValueCell
<
T
>
{
value
:
T
}
/** Create a mutable value cell. */
function
ValueCell
<
T
>
(
value
:
T
):
ValueCell
<
T
>
{
return
{
value
};
}
/** An immutable value box that also holds a version of the attribute. */
interface
ValueBox
<
T
>
{
readonly
version
:
number
,
readonly
value
:
T
}
/** Create a new box with the specified value and version = 0 */
function
ValueBox
<
T
>
(
value
:
T
):
ValueBox
<
T
>
/** Create a new box by updating the value of an old box and incrementing the version number. */
function
ValueBox
<
T
>
(
box
:
ValueBox
<
T
>
,
value
:
T
):
ValueBox
<
T
>
function
ValueBox
<
T
>
(
boxOrValue
:
T
|
ValueBox
<
T
>
,
value
?:
T
):
ValueBox
<
T
>
{
if
(
arguments
.
length
===
2
)
return
{
version
:
(
boxOrValue
as
ValueBox
<
T
>
).
version
+
1
,
value
:
value
!
};
return
{
version
:
0
,
value
:
boxOrValue
as
T
};
}
export
{
ValueCell
,
ValueBox
};
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