Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add show level and hide level in react-kit #23

Merged
merged 2 commits into from
Sep 28, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ node_modules
dist
es6
.DS_Store
.vscode
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@bhoos/react-kit",
"version": "2.0.6",
"version": "2.0.7",
"description": "Bhoos React Library",
"main": "dist/index.js",
"module": "es6/index.js",
Expand Down
17 changes: 13 additions & 4 deletions src/transition/TransitionController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,7 @@ export class TransitionController<State, Action> {
// Continue with the remaining actions only
if (this.queue.length && !this.shouldHoldAction()) {
this.startDispatch(this.queue.shift(), prevState);
this.backLogs.forEach(cb => cb());
}
});
}
Expand Down Expand Up @@ -321,13 +322,21 @@ export class TransitionController<State, Action> {
return value;
}

useBackLog(max: number) {
const [backlog, setBackLog] = useState(this.queue.length > max);
useBackLog(showLevel: number, hideLevel?: number) {
const [backlog, setBackLog] = useState(this.queue.length >= showLevel);
if (hideLevel === undefined) hideLevel = showLevel;

useEffect(() => {
return subscribe(this.backLogs, () => {
setBackLog(this.queue.length > max);
setBackLog((prevVisible) => {
if (prevVisible) {
return this.queue.length >= hideLevel;
} else {
return this.queue.length >= showLevel;
}
});
});
}, [max]);
}, [showLevel, hideLevel]);

return backlog;
}
Expand Down