Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
F
frama-c
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Container Registry
Model registry
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
pub
frama-c
Commits
bfe943bc
"src/plugins/e-acsl/tests/bts/oracle/gen_bts1324.c" did not exist on "361a4fa8bea76e9397d0b50fb08674ca2c4ae236"
Commit
bfe943bc
authored
4 years ago
by
Loïc Correnson
Browse files
Options
Downloads
Patches
Plain Diff
[dome] Local & Global states
parent
a75b4445
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
ivette/src/dome/src/renderer/data/states.ts
+46
-3
46 additions, 3 deletions
ivette/src/dome/src/renderer/data/states.ts
ivette/src/frama-c/states.ts
+3
-3
3 additions, 3 deletions
ivette/src/frama-c/states.ts
with
49 additions
and
6 deletions
ivette/src/dome/src/renderer/data/states.ts
+
46
−
3
View file @
bfe943bc
...
...
@@ -17,8 +17,49 @@ import * as JSON from './json';
const
UPDATE
=
'
dome.states.update
'
;
/** State interface. */
export
type
State
<
A
>
=
[
A
,
(
update
:
A
)
=>
void
];
/** State field of an object state. */
export
function
key
<
A
,
K
extends
keyof
A
>
(
state
:
State
<
A
>
,
key
:
K
,
):
State
<
A
[
K
]
>
{
const
[
props
,
setProps
]
=
state
;
return
[
props
[
key
],
(
value
:
A
[
K
])
=>
{
const
newProps
=
Object
.
assign
({},
props
);
newProps
[
key
]
=
value
;
setProps
(
newProps
);
}];
}
/** State index of an array state. */
export
function
index
<
A
>
(
state
:
State
<
A
[]
>
,
index
:
number
,
):
State
<
A
>
{
const
[
array
,
setArray
]
=
state
;
return
[
array
[
index
],
(
value
:
A
)
=>
{
const
newArray
=
array
.
slice
();
newArray
[
index
]
=
value
;
setArray
(
newArray
);
}];
}
/** Log state updates in the console. */
export
function
debug
<
A
>
(
msg
:
string
,
st
:
State
<
A
>
):
State
<
A
>
{
const
[
value
,
setValue
]
=
st
;
return
[
value
,
(
v
)
=>
{
console
.
log
(
msg
,
v
);
setValue
(
v
);
}];
}
/** Purely local value. No hook, no events, just a ref. */
export
function
local
<
A
>
(
init
:
A
):
State
<
A
>
{
const
ref
=
{
current
:
init
};
return
[
ref
.
current
,
(
v
)
=>
ref
.
current
=
v
];
}
/** Cross-component State. */
export
class
State
<
A
>
{
export
class
Global
State
<
A
>
{
private
value
:
A
;
private
emitter
:
Emitter
;
...
...
@@ -53,8 +94,10 @@ export class State<A> {
}
/** React Hook, similar to `React.useState()`. */
export
function
useState
<
A
>
(
s
:
State
<
A
>
):
[
A
,
(
update
:
A
)
=>
void
]
{
/** React Hook, similar to `React.useState()`.
Assignments to the global state also update _all_
its associated hooks and listeners. */
export
function
useGlobalState
<
A
>
(
s
:
GlobalState
<
A
>
):
State
<
A
>
{
const
[
current
,
setCurrent
]
=
React
.
useState
<
A
>
(
s
.
getValue
);
React
.
useEffect
(()
=>
{
s
.
on
(
setCurrent
);
...
...
This diff is collapsed.
Click to expand it.
ivette/src/frama-c/states.ts
+
3
−
3
View file @
bfe943bc
...
...
@@ -13,7 +13,7 @@ import React from 'react';
import
*
as
Dome
from
'
dome
'
;
import
*
as
Json
from
'
dome/data/json
'
;
import
{
Order
}
from
'
dome/data/compare
'
;
import
*
as
GlobalState
s
from
'
dome/data/states
'
;
import
{
GlobalState
,
use
GlobalState
}
from
'
dome/data/states
'
;
import
{
useModel
}
from
'
dome/table/models
'
;
import
{
CompactModel
}
from
'
dome/table/arrays
'
;
import
*
as
Server
from
'
./server
'
;
...
...
@@ -534,7 +534,7 @@ function reducer(s: Selection, action: SelectionActions): Selection {
}
}
const
GlobalSelection
=
new
GlobalState
s
.
State
<
Selection
>
({
const
GlobalSelection
=
new
GlobalState
<
Selection
>
({
current
:
undefined
,
prevSelections
:
[],
nextSelections
:
[],
...
...
@@ -544,7 +544,7 @@ const GlobalSelection = new GlobalStates.State<Selection>({
Current selection.
*/
export
function
useSelection
():
[
Selection
,
(
a
:
SelectionActions
)
=>
void
]
{
const
[
selection
,
setSelection
]
=
GlobalState
s
.
useState
(
GlobalSelection
);
const
[
selection
,
setSelection
]
=
use
GlobalState
(
GlobalSelection
);
function
update
(
action
:
SelectionActions
)
{
const
nextSelection
=
reducer
(
selection
,
action
);
...
...
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