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
5420e310
Commit
5420e310
authored
3 years ago
by
Loïc Correnson
Committed by
David Bühler
2 years ago
Browse files
Options
Downloads
Patches
Plain Diff
[dome] fix settings hooks
parent
e9d8ccd7
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/renderer/data/settings.ts
+13
-10
13 additions, 10 deletions
ivette/src/dome/renderer/data/settings.ts
ivette/src/dome/renderer/dome.tsx
+2
-6
2 additions, 6 deletions
ivette/src/dome/renderer/dome.tsx
with
15 additions
and
16 deletions
ivette/src/dome/renderer/data/settings.ts
+
13
−
10
View file @
5420e310
...
...
@@ -248,26 +248,29 @@ function useSettings<A>(
D
:
Driver
,
K
?:
string
,
):
State
<
A
>
{
// Lo
ad valu
e
const
loader
=
()
=>
(
// Lo
cal Stat
e
const
[
value
,
setValue
]
=
React
.
useState
<
A
>
(
()
=>
(
JSON
.
jCatch
(
S
.
decoder
,
S
.
defaultValue
)(
D
.
load
(
K
))
);
// Local state
const
[
value
,
setValue
]
=
React
.
useState
<
A
>
(
loader
);
// Emit update event
));
// Foreign Settings Update
React
.
useEffect
(()
=>
{
const
event
=
D
.
evt
;
const
callback
=
()
=>
setValue
(
loader
());
SysEmitter
.
on
(
event
,
callback
);
return
()
=>
{
SysEmitter
.
off
(
event
,
callback
);
};
const
onUpdate
=
()
=>
{
const
fromSettings
=
JSON
.
jCatch
(
S
.
decoder
,
undefined
)(
D
.
load
(
K
));
if
(
fromSettings
!==
undefined
)
setValue
(
fromSettings
);
};
SysEmitter
.
on
(
event
,
onUpdate
);
return
()
=>
{
SysEmitter
.
off
(
event
,
onUpdate
);
};
});
// Update
s
//
Hooked Settings
Update
const
updateValue
=
React
.
useCallback
((
newValue
:
A
)
=>
{
if
(
!
isEqual
(
value
,
newValue
))
{
setValue
(
newValue
);
if
(
K
)
D
.
save
(
K
,
S
.
encoder
(
newValue
));
}
},
[
S
,
D
,
K
,
value
]);
// Hook
return
[
value
,
updateValue
];
}
...
...
This diff is collapsed.
Click to expand it.
ivette/src/dome/renderer/dome.tsx
+
2
−
6
View file @
5420e310
...
...
@@ -173,7 +173,7 @@ export function useEvent<A>(
return
()
=>
evt
.
off
(
callback
);
}
return
undefined
;
});
}
,
[
evt
,
callback
]
);
}
// --------------------------------------------------------------------------
...
...
@@ -704,11 +704,7 @@ export function useFlipSettings(
const
[
state
,
setState
]
=
Settings
.
useWindowSettings
(
key
,
Json
.
jBoolean
,
defaultValue
,
);
const
flipState
=
React
.
useCallback
(
()
=>
setState
(
!
state
),
[
state
,
setState
],
);
return
[
state
,
flipState
];
return
[
state
,
()
=>
setState
(
!
state
)];
}
/** Number window settings helper. Default is `0` unless specified. */
...
...
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