temporary hack to avoid excessive observers

This commit is contained in:
Nolan Lawson 2018-02-11 20:12:15 -08:00
parent 2a86425c90
commit c8c7c03864
2 changed files with 22 additions and 16 deletions

View file

@ -138,12 +138,9 @@
&& timelineValue !== $firstTimelineItemId
&& timelineValue
},
itemIdsToAdd: (timeline, $currentInstance, $timelines) => {
return ($timelines &&
$timelines[$currentInstance] &&
$timelines[$currentInstance][timeline] &&
$timelines[$currentInstance][timeline].itemIdsToAdd) || []
},
itemIdsToAdd: ($itemIdsToAdd) => $itemIdsToAdd,
// hack to avoid getting called too often
itemIdsToAddStringified: (itemIdsToAdd) => JSON.stringify(itemIdsToAdd),
headerProps: (itemIdsToAdd) => {
return {
count: (itemIdsToAdd && itemIdsToAdd.length) || 0,
@ -207,7 +204,9 @@
this.store.setForTimeline(instanceName, timelineName, {shouldShowHeader: true})
}
}
this.observe('itemIdsToAdd', itemIdsToAdd => {
this.observe('itemIdsToAddStringified', itemIdsToAddStringified => {
let itemIdsToAdd = typeof itemIdsToAddStringified === 'undefined' ? undefined :
JSON.parse(itemIdsToAddStringified)
if (itemIdsToAdd && itemIdsToAdd.length) {
scheduleIdleTask(handleItemIdsToAdd)
}

View file

@ -33,24 +33,29 @@
export default {
oncreate () {
this.observe('showFooter', showFooter => {
this.store.setForRealm({showFooter: showFooter})
})
this.observe('showHeader', showHeader => {
this.store.setForRealm({showHeader: showHeader})
})
this.observe('items', (items) => {
mark('set items')
this.store.setForRealm({items: items})
stop('set items')
this.fireScrollToBottom = throttle(() => {
this.fire('scrollToBottom')
}, SCROLL_EVENT_THROTTLE)
this.fireScrollToTop = throttle(() => {
this.fire('scrollToTop')
}, SCROLL_EVENT_THROTTLE)
this.observe('showFooter', showFooter => {
mark('set showFooter')
this.store.setForRealm({showFooter: showFooter})
mark('set showFooter')
})
this.observe('showHeader', showHeader => {
mark('set showHeader')
this.store.setForRealm({showHeader: showHeader})
stop('set showHeader')
})
this.observe('itemsStringified', (itemsStringified) => {
let items = typeof itemsStringified === 'undefined' ? undefined :
JSON.parse(itemsStringified)
mark('set items')
this.store.setForRealm({items: items})
stop('set items')
})
this.observe('allVisibleItemsHaveHeight', allVisibleItemsHaveHeight => {
if (allVisibleItemsHaveHeight) {
this.fire('initializedVisibleItems')
@ -91,7 +96,9 @@
},
distanceFromTop: ($scrollTop) => $scrollTop,
// TODO: bug in svelte store, shouldn't need to do this
allVisibleItemsHaveHeight: ($allVisibleItemsHaveHeight) => $allVisibleItemsHaveHeight
allVisibleItemsHaveHeight: ($allVisibleItemsHaveHeight) => $allVisibleItemsHaveHeight,
// hack to avoid getting called too often
itemsStringified: (items) => JSON.stringify(items)
}
}
</script>