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

[do not merge] Experiments with virtual-list #20

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
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
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@
"lit-html": "^0.9.0",
"pwa-helpers": "PolymerLabs/pwa-helpers",
"redux-thunk": "^2.2.0",
"reselect": "^3.0.1"
"reselect": "^3.0.1",
"virtual-list": "github:PolymerLabs/virtual-list#master"
},
"devDependencies": {
"polyserve": "^0.25.2"
Expand Down
21 changes: 14 additions & 7 deletions src/components/hn-item.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
*/

import { LitElement, html } from '../../node_modules/@polymer/lit-element/lit-element.js';
import { repeat } from '../../node_modules/lit-html/lib/repeat.js';
import { verticalList } from '../../node_modules/virtual-list/lit-html/lit-list.js';
import Layout from '../../node_modules/virtual-list/layouts/layout-1d.js';
import { unsafeHTML } from '../../node_modules/lit-html/lib/unsafe-html.js';
import { connect } from '../../node_modules/pwa-helpers/connect-mixin.js';
import { fetchItem, fetchItemIfNeeded } from '../actions/items.js';
Expand All @@ -29,6 +30,12 @@ store.addReducers({

store.dispatch(loadFavorites());

const layout = new Layout({
itemSize: {
y: 2000
}
});

export class HnItemElement extends connect(store)(LitElement) {
render({ favorites, item }) {
const comments = item.comments || [];
Expand All @@ -40,21 +47,21 @@ export class HnItemElement extends connect(store)(LitElement) {
border-bottom: 1px solid #e5e5e5;
}
</style>
<hn-loading-button
loading="${item.isFetching}"
on-click="${() => store.dispatch(fetchItem(item))}">
</hn-loading-button>
<div hidden="${item.failure}">
<hn-summary
item="${item}"
isFavorite="${favorites && item && favorites[item.id]}">
</hn-summary>
<div hidden="${!item.content}">${unsafeHTML(item.content)}</div>
${repeat(comments, (comment) => html`
${verticalList(comments, (comment) => html`
<hn-comment id="${comment.id}" comment="${comment}" itemId="${item.id}"></hn-comment>
`)}
`, layout)}
</div>
${item.failure ? html`<p>Item not found</p>` : ''}
<hn-loading-button
loading="${item.isFetching}"
on-click="${() => store.dispatch(fetchItem(item))}">
</hn-loading-button>
`;
}

Expand Down
16 changes: 9 additions & 7 deletions src/components/hn-list.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
*/

import { LitElement, html } from '../../node_modules/@polymer/lit-element/lit-element.js';
import { repeat } from '../../node_modules/lit-html/lib/repeat.js';
import { verticalList } from '../../node_modules/virtual-list/lit-html/lit-list.js';
import { connect } from '../../node_modules/pwa-helpers/connect-mixin.js';
import { fetchList, fetchListIfNeeded } from '../actions/lists.js';
import { loadFavorites } from '../actions/favorites.js';
Expand Down Expand Up @@ -41,6 +41,14 @@ export class HnListElement extends connect(store)(LitElement) {
margin: 0 8px 8px 0;
}
</style>
<div>
${verticalList(items, (item) => html`
<hn-summary
item="${item}"
isFavorite="${favorites && item && favorites[item.id]}">
</hn-summary>
`)}
</div>
${
list.id !== 'favorites' ?
html`
Expand All @@ -51,12 +59,6 @@ export class HnListElement extends connect(store)(LitElement) {
` :
null
}
${repeat(items, (item) => html`
<hn-summary
item="${item}"
isFavorite="${favorites && item && favorites[item.id]}">
</hn-summary>
`)}
${
list.id !== 'favorites' && items.length ?
html`
Expand Down