-
Notifications
You must be signed in to change notification settings - Fork 7
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
feat(infinite-scroll): add custom trigger #285
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
customTrigger
應該調整命名為hasCustomTrigger
,使其有更明確的 boolean 值意涵- loaderElement 可以是
customTriggerRef.current
或loaderRef.current
,簡化 useEffect 的處理,同時讓在hasCustomTrigger
為true
的情況下,也可以支援手動載入
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
> | ||
{Object.entries(ExampleType).map(([key, type]) => { | ||
return ( | ||
<button |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
可以增加 active 效果,以作為辨識
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
修改在 fed01b6
| loader | `ReactNode` | `false` | The loader element to be displayed during data loading | | ||
|
||
| customTrigger | `boolean` | `false` | Wether the custom trigger ref will provided throught children callback to set up trigger point | |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
will be provided
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
修改在 ed41865
@@ -44,6 +44,13 @@ You should ensurce T in `initialList`, `fetchListInPage` and `children` that rep | |||
1. no more data | |||
2. amount of items reached `Math.min(amountOfElements, pageAmount * pageSize)` | |||
|
|||
### Trigger loadmore | |||
- Default (customTrigger: false) | |||
- This component will insert a loading `<div/>` to trigger intersection which means it only starts to load more at the end of the showing list |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This component appends an element which triggers load-more effect at the end of the element list by default
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
修改在 ed41865
- Default (customTrigger: false) | ||
- This component will insert a loading `<div/>` to trigger intersection which means it only starts to load more at the end of the showing list | ||
- Custom Trigger (customTrigger: true) | ||
- Set the prop `customTrigger` to `true` and use the `customTriggerRef` as the second param from the `children` callback to set to the desired elemnt as trigger point. (check [custom-trigger-example](./dev/components/custom-trigger-example.tsx)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the second parameter -> the second augument
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
修改在 ed41865
- Default (customTrigger: false) | ||
- This component will insert a loading `<div/>` to trigger intersection which means it only starts to load more at the end of the showing list | ||
- Custom Trigger (customTrigger: true) | ||
- Set the prop `customTrigger` to `true` and use the `customTriggerRef` as the second param from the `children` callback to set to the desired elemnt as trigger point. (check [custom-trigger-example](./dev/components/custom-trigger-example.tsx)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
to set to the desired elemnt as trigger point -> to designate element as trigger point
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
修改在 ed41865
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- 不建議在此 package 的 dev dependecy 加上
styled-component
,應該讓這個 package 盡可能沒有 styling 的行為,如果要用上 styled-component,可以放在 root (ver: 5.3.5) hasCustomTrigger
為true
的情況下,isAutoFetch
必須為true
的話,可以用 ts-xor 來定義 props,讓使用端清楚這限制
@@ -18,5 +18,5 @@ | |||
"outDir": "dist", | |||
"declarationMap": true | |||
}, | |||
"include": ["src/**/*"] | |||
"include": ["src/**/*", "dev/**/*"] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
這邊要改的話,記得調整 package.json 的內容,因為輸出 type 的結構有變
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
感謝提醒,先拿掉好了,修改在 b49ee49
/** Wether the custom trigger ref will provided throught children callback to set up trigger point */ | ||
hasCustomTrigger?: boolean | ||
} | ||
} & XOR<CustomTrigger, AutoFetch> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
我會弄成以下樣子
XOR<{
hasCustomTrigger: true
isAuthFetch?: true
}, {
hasCustomTrigger?: false
isAuthFetch?: boolean
}>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
修改在 ae7aac3
package.json
Outdated
@@ -52,6 +52,8 @@ | |||
"lint-staged": "^12.4.2", | |||
"prettier": "^2", | |||
"regenerator-runtime": "^0.13.9", | |||
"styled-components": "^6.1.11", | |||
"ts-xor": "^1.3.0", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ts-xor
應該放到 package 的 dev dependecy,而非 root,這樣使用端在安裝後,才能夠正確解析 prop type
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
修改在 bf19928
package.json
Outdated
@@ -52,6 +52,8 @@ | |||
"lint-staged": "^12.4.2", | |||
"prettier": "^2", | |||
"regenerator-runtime": "^0.13.9", | |||
"styled-components": "^6.1.11", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
可以先固定在 5.3.5
的版本,畢竟其他套件也是用這個版本
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
修改在 bf19928
- fix styled-components version to 5.3.5 - move ts-xor package into infinite-scroll-list package
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM 👏
記得更新一下 CHANGELOG
喔對了,package 自己的 package.json 也要更新一下版號 |
Notable Change
Follow-up
After PR approved, new npm package will be pushed with new version.