Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
P
purescript-gargantext
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
154
Issues
154
List
Board
Labels
Milestones
Merge Requests
3
Merge Requests
3
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
gargantext
purescript-gargantext
Commits
b11509ca
Verified
Commit
b11509ca
authored
Oct 06, 2025
by
Przemyslaw Kaminski
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[utility] add R2.useTraceUpdate and T2.unequalWithLog to make debugging easier
parent
d0784dbc
Pipeline
#7966
canceled with stages
Changes
3
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
47 additions
and
3 deletions
+47
-3
Reactix.js
src/Gargantext/Utils/Reactix.js
+23
-0
Reactix.purs
src/Gargantext/Utils/Reactix.purs
+8
-1
Toestand.purs
src/Gargantext/Utils/Toestand.purs
+16
-2
No files found.
src/Gargantext/Utils/Reactix.js
View file @
b11509ca
...
@@ -71,3 +71,26 @@ export const startTransitionImpl = (t) => (f) => () => {
...
@@ -71,3 +71,26 @@ export const startTransitionImpl = (t) => (f) => () => {
console
.
log
(
'starting transition'
,
t
,
f
);
console
.
log
(
'starting transition'
,
t
,
f
);
return
t
[
1
](()
=>
{
f
()()
});
return
t
[
1
](()
=>
{
f
()()
});
}
}
function
stringify
(
o
)
{
if
(
typeof
(
o
)
==
'function'
)
{
return
String
(
o
);
}
return
JSON
.
stringify
(
o
);
}
export
const
_useTraceUpdate
=
(
react
)
=>
(
props
)
=>
()
=>
{
const
prev
=
react
.
useRef
(
props
);
react
.
useEffect
(()
=>
{
const
changedProps
=
Object
.
entries
(
props
).
reduce
((
ps
,
[
k
,
v
])
=>
{
if
(
prev
.
current
[
k
]
!==
v
)
{
ps
[
k
]
=
[
stringify
(
prev
.
current
[
k
]),
stringify
(
v
)];
}
return
ps
;
},
{});
if
(
Object
.
keys
(
changedProps
).
length
>
0
)
{
console
.
log
(
'Changed props:'
,
changedProps
);
}
prev
.
current
=
props
;
});
}
src/Gargantext/Utils/Reactix.purs
View file @
b11509ca
...
@@ -31,7 +31,7 @@ import React.SyntheticEvent as SE
...
@@ -31,7 +31,7 @@ import React.SyntheticEvent as SE
import Reactix as R
import Reactix as R
import Reactix.DOM.HTML (ElemFactory, createDOM, text)
import Reactix.DOM.HTML (ElemFactory, createDOM, text)
import Reactix.DOM.HTML as H
import Reactix.DOM.HTML as H
import Reactix.React (react)
import Reactix.React (react
, React
)
import Reactix.SyntheticEvent as RE
import Reactix.SyntheticEvent as RE
import Reactix.Utils (currySecond, hook, tuple)
import Reactix.Utils (currySecond, hook, tuple)
import Simple.JSON as JSON
import Simple.JSON as JSON
...
@@ -726,3 +726,10 @@ foreign import startTransitionImpl :: Transition -> (Unit -> Effect Unit) -> Eff
...
@@ -726,3 +726,10 @@ foreign import startTransitionImpl :: Transition -> (Unit -> Effect Unit) -> Eff
startTransition :: Transition -> (Unit -> Effect Unit) -> Effect Unit
startTransition :: Transition -> (Unit -> Effect Unit) -> Effect Unit
startTransition = startTransitionImpl
startTransition = startTransitionImpl
-- | For debugging why your component rerenders
-- https://stackoverflow.com/questions/41004631/trace-why-a-react-component-is-re-rendering
foreign import _useTraceUpdate :: forall a. React -> a -> R.Hooks Unit
useTraceUpdate :: forall a. a -> R.Hooks Unit
useTraceUpdate = _useTraceUpdate react
src/Gargantext/Utils/Toestand.purs
View file @
b11509ca
...
@@ -7,13 +7,17 @@ module Gargantext.Utils.Toestand
...
@@ -7,13 +7,17 @@ module Gargantext.Utils.Toestand
, InitReload(..)
, InitReload(..)
, ready
, ready
, useMemberBox
, useMemberBox
, unequalWithLog
) where
) where
import Prelude (class Ord, Unit, bind, pure, unit, (+))
import Prelude
import Data.Set as Set
import DOM.Simple.Console (log2)
import Data.Set (Set)
import Data.Set (Set)
import Data.Set as Set
import Effect (Effect)
import Effect (Effect)
import Reactix as R
import Reactix as R
import Record (equalFields)
import Toestand as T
import Toestand as T
-- | Reload is a simple counter that can be used to force an update.
-- | Reload is a simple counter that can be used to force an update.
...
@@ -71,3 +75,13 @@ useMemberBox val box = T.useFocused (Set.member val) (toggleSet val) box
...
@@ -71,3 +75,13 @@ useMemberBox val box = T.useFocused (Set.member val) (toggleSet val) box
toggleSet :: forall s. Ord s => s -> Boolean -> Set s -> Set s
toggleSet :: forall s. Ord s => s -> Boolean -> Set s -> Set s
toggleSet val true set = Set.insert val set
toggleSet val true set = Set.insert val set
toggleSet val false set = Set.delete val set
toggleSet val false set = Set.delete val set
-- | Same as T.unequal but will also log, whenever elements are not equal.
-- Useful for debugging.
unequalWithLog :: forall v. Eq v => Show v => String -> T.Change v -> Effect Boolean
unequalWithLog name { new, old } =
if new `notEq` old then do
log2 (name <> " change") $ (show new <> " != " <> show old)
pure true
else
pure false
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment