fix node removal with no parent caused by focus changes

This commit is contained in:
Nolan Lawson 2018-03-04 12:55:45 -08:00
parent 456c865a09
commit 562a58f030
3 changed files with 51 additions and 41 deletions

View File

@ -60,21 +60,4 @@ export function instanceComputations (store) {
return list ? list.title : '' return list ? list.title : ''
} }
) )
store.compute('numberOfNotifications',
['timelines', 'currentInstance', 'currentTimeline'],
(timelines, currentInstance, currentTimeline) => {
return currentTimeline !== 'notifications' &&
timelines &&
timelines[currentInstance] &&
timelines[currentInstance].notifications &&
timelines[currentInstance].notifications.itemIdsToAdd &&
timelines[currentInstance].notifications.itemIdsToAdd.length
}
)
store.compute('hasNotifications',
['numberOfNotifications'],
(numberOfNotifications) => !!numberOfNotifications
)
} }

View File

@ -1,23 +1,45 @@
function computeForTimeline (store, key) { function computeForTimeline (store, key, defaultValue) {
store.compute(key, ['currentTimelineData'], (currentTimelineData) => currentTimelineData[key]) store.compute(key,
['currentInstance', 'currentTimeline', `timelineData_${key}`],
(currentInstance, currentTimeline, root) => {
let instanceData = root && root[currentInstance]
return (currentTimeline && instanceData && currentTimeline in instanceData) ? instanceData[currentTimeline] : defaultValue
})
} }
export function timelineComputations (store) { export function timelineComputations (store) {
store.compute('currentTimelineData', ['currentInstance', 'currentTimeline', 'timelines'], computeForTimeline(store, 'timelineItemIds', null)
(currentInstance, currentTimeline, timelines) => { computeForTimeline(store, 'runningUpdate', false)
return ((timelines && timelines[currentInstance]) || {})[currentTimeline] || {} computeForTimeline(store, 'initialized', false)
computeForTimeline(store, 'lastFocusedElementSelector', null)
computeForTimeline(store, 'ignoreBlurEvents', false)
computeForTimeline(store, 'itemIdsToAdd', null)
computeForTimeline(store, 'showHeader', false)
computeForTimeline(store, 'shouldShowHeader', false)
store.compute('firstTimelineItemId', ['timelineItemIds'], (timelineItemIds) => {
return timelineItemIds && timelineItemIds[0]
})
store.compute('lastTimelineItemId', ['timelineItemIds'], (timelineItemIds) => {
return timelineItemIds && timelineItemIds[timelineItemIds.length - 1]
}) })
computeForTimeline(store, 'timelineItemIds') store.compute('numberOfNotifications',
computeForTimeline(store, 'runningUpdate') [`timelineData_itemIdsToAdd`, 'currentInstance', 'currentTimeline'],
computeForTimeline(store, 'initialized') (root, currentInstance, currentTimeline) => {
computeForTimeline(store, 'lastFocusedElementSelector') return (
computeForTimeline(store, 'ignoreBlurEvents') currentTimeline !== 'notifications' &&
computeForTimeline(store, 'itemIdsToAdd') root &&
computeForTimeline(store, 'showHeader') root[currentInstance] &&
computeForTimeline(store, 'shouldShowHeader') root[currentInstance].notifications &&
root[currentInstance].notifications.length
) || 0
}
)
store.compute('firstTimelineItemId', ['timelineItemIds'], (timelineItemIds) => timelineItemIds && timelineItemIds.length && timelineItemIds[0]) store.compute('hasNotifications',
store.compute('lastTimelineItemId', ['timelineItemIds'], (timelineItemIds) => timelineItemIds && timelineItemIds.length && timelineItemIds[timelineItemIds.length - 1]) ['numberOfNotifications'],
(numberOfNotifications) => !!numberOfNotifications
)
} }

View File

@ -1,16 +1,21 @@
export function timelineMixins (Store) { export function timelineMixins (Store) {
Store.prototype.setForTimeline = function (instanceName, timelineName, obj) { Store.prototype.setForTimeline = function (instanceName, timelineName, obj) {
let timelines = this.get('timelines') || {} let valuesToSet = {}
let timelineData = timelines[instanceName] || {} for (let key of Object.keys(obj)) {
timelineData[timelineName] = Object.assign(timelineData[timelineName] || {}, obj) let rootKey = `timelineData_${key}`
timelines[instanceName] = timelineData let root = this.get(rootKey) || {}
this.set({timelines: timelines}) let instanceData = root[instanceName] = root[instanceName] || {}
instanceData[timelineName] = obj[key]
valuesToSet[rootKey] = root
}
this.set(valuesToSet)
} }
Store.prototype.getForTimeline = function (instanceName, timelineName, key) { Store.prototype.getForTimeline = function (instanceName, timelineName, key) {
let timelines = this.get('timelines') || {} let rootKey = `timelineData_${key}`
let timelineData = timelines[instanceName] || {} let root = this.get(rootKey)
return (timelineData[timelineName] || {})[key] return root && root[instanceName] && root[instanceName][timelineName]
} }
Store.prototype.setForCurrentTimeline = function (obj) { Store.prototype.setForCurrentTimeline = function (obj) {