Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Rex Dri
Rex Dri
Commits
3f021561
Verified
Commit
3f021561
authored
Apr 12, 2020
by
Florent Chehab
Browse files
fix(hooks): more cleaning shared*
parent
ce477414
Changes
3
Hide whitespace changes
Inline
Side-by-side
frontend/src/hooks/useSharedReducer.js
View file @
3f021561
...
...
@@ -17,11 +17,8 @@ function useSharedReducer(key, reducer, initialState) {
setSharedState
(
state
);
},
[
state
,
setSharedState
]);
const
dispatchOut
=
useCallback
(
action
=>
{
// built-in support for action that take dispatch as argument
if
(
typeof
action
===
"
function
"
)
{
action
(
dispatchOut
);
}
else
{
const
dispatchNotFunction
=
useCallback
(
action
=>
{
if
(
process
.
env
.
NODE_ENV
!==
"
production
"
)
{
const
{
type
}
=
action
;
...
...
@@ -40,8 +37,28 @@ function useSharedReducer(key, reducer, initialState) {
);
}
dispatch
(
action
);
}
},
[]);
},
[
dispatch
]
);
const
dispatchFunction
=
useCallback
(
action
=>
{
action
(
dispatchNotFunction
);
},
[
dispatchNotFunction
]
);
const
dispatchOut
=
useCallback
(
action
=>
{
// built-in support for action that take dispatch as argument
if
(
typeof
action
===
"
function
"
)
{
dispatchFunction
(
action
);
}
else
{
dispatchNotFunction
(
action
);
}
},
[
dispatchFunction
,
dispatchNotFunction
]
);
// make sure to return the saved state to prevent bugs when directly accessing the saved data
return
useMemo
(()
=>
[
sharedState
,
dispatchOut
],
[
sharedState
,
dispatchOut
]);
...
...
frontend/src/hooks/useSharedState.js
View file @
3f021561
...
...
@@ -5,7 +5,7 @@ import useOnBeforeComponentMount from "./useOnBeforeComponentMount";
/**
* @type {Map<string, Set.<function>>}
*/
export
const
listenersByKey
=
new
Map
();
const
listenersByKey
=
new
Map
();
/**
* Hook that provides a sharedState : when the setState is used in one component,
...
...
frontend/src/hooks/wrappers/useSingleApiData.js
View file @
3f021561
...
...
@@ -51,8 +51,13 @@ function useSingleApiData(
const
isLoading
=
!
apiDataIsUsable
(
data
);
const
latestData
=
getLatestRead
(
data
).
data
;
if
(
!
data
.
isReading
)
{
// make sure performRead is triggered (it seems not te be triggered sometimes)
if
(
data
.
isInvalidated
===
true
)
performRead
(
params
);
}
return
{
hasError
,
isLoading
,
latestData
,
data
,
setParams
};
},
[
data
,
setParams
]);
},
[
data
,
params
,
setParams
]);
}
export
default
useSingleApiData
;
Write
Preview
Supports
Markdown
0%
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!
Cancel
Please
register
or
sign in
to comment