-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: use haunted to manage incomplete templates
* Render incomplete templates with haunted ** only update first instance when we switch between index 0/1 ** only update last instance when we switch between index last/last-1 ** only render incomplete instance to DOM if hitting an incomplete item *** but keep it! Need to observe 'haunted' since it's ready late. element.__incomplete becomes the actual element to show/hide/render to ** will always be available, since creation, no need to check it * Drop inline-README * Upgraded dependencies. Signed-off-by: Patrik Kullman <[email protected]>
- Loading branch information
1 parent
b9d9488
commit fac0c2b
Showing
9 changed files
with
1,184 additions
and
1,305 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import { useMemo } from 'haunted'; | ||
import { useIncompleteTemplate } from './use-incomplete-template'; | ||
import { useCache } from './use-cache'; | ||
|
||
export const useDataNav = el => { | ||
const incompleteTemplates = useMemo(() => ({ | ||
[el.selected - 1]: useIncompleteTemplate(el.selected - 1, el.items.length), | ||
[el.selected]: useIncompleteTemplate(el.selected, el.items.length), | ||
[el.selected + 1]: useIncompleteTemplate(el.selected + 1, el.items.length) | ||
}), [el.selected, el.items.length]); | ||
return { | ||
cache: useCache(el), | ||
incompleteTemplates | ||
}; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import { | ||
html, useMemo | ||
} from 'haunted'; | ||
import { _ } from '@neovici/cosmoz-i18next'; | ||
|
||
const viewStyle = ` | ||
position: absolute; | ||
top: 0; | ||
right: 0; | ||
bottom: 0; | ||
left: 0; | ||
`, | ||
scrollerContentStyle = ` | ||
display: flex; | ||
flex: 1; | ||
flex-basis: 0.000000001px; | ||
flex-direction: row; | ||
justify-content: center; | ||
align-items: center; | ||
`; | ||
|
||
export const useIncompleteTemplate = (index, length) => { | ||
const atStart = index === 0, | ||
atEnd = index === length - 1; | ||
|
||
return useMemo(() => html` | ||
<cosmoz-bottom-bar-view active incomplete style="${ viewStyle }"> | ||
<div slot="scroller-content" style="${ scrollerContentStyle }"> | ||
<paper-spinner-lite active></paper-spinner-lite> | ||
<div style="margin-left: 10px"> | ||
<h3><span>${ _('Data is updating') }</span></h3> | ||
</div> | ||
</div> | ||
<paper-icon-button ?disabled="${ atStart }" icon="chevron-left" cosmoz-data-nav-select="-1" slot="extra"></paper-icon-button> | ||
<paper-icon-button ?disabled="${ atEnd }" icon="chevron-right" cosmoz-data-nav-select="+1" slot="extra"></paper-icon-button> | ||
</cosmoz-bottom-bar-view> | ||
`, [atStart, atEnd]); | ||
}; |
Oops, something went wrong.