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

View file

@ -33,24 +33,29 @@
export default { export default {
oncreate () { 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.fireScrollToBottom = throttle(() => {
this.fire('scrollToBottom') this.fire('scrollToBottom')
}, SCROLL_EVENT_THROTTLE) }, SCROLL_EVENT_THROTTLE)
this.fireScrollToTop = throttle(() => { this.fireScrollToTop = throttle(() => {
this.fire('scrollToTop') this.fire('scrollToTop')
}, SCROLL_EVENT_THROTTLE) }, 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 => { this.observe('allVisibleItemsHaveHeight', allVisibleItemsHaveHeight => {
if (allVisibleItemsHaveHeight) { if (allVisibleItemsHaveHeight) {
this.fire('initializedVisibleItems') this.fire('initializedVisibleItems')
@ -91,7 +96,9 @@
}, },
distanceFromTop: ($scrollTop) => $scrollTop, distanceFromTop: ($scrollTop) => $scrollTop,
// TODO: bug in svelte store, shouldn't need to do this // 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> </script>