mirror of
https://github.com/atom/atom.git
synced 2026-01-25 14:59:03 -05:00
Allow telepath to manage serialization of non-telepathic pane items
This is the first step in converting Pane into a telepath model. We skip interaction with the deserializer for items and allow telepath to handle everything. There's actually a preexisting replication error in moveItem that I'm going to leave until we drop out a Pane model.
This commit is contained in:
@@ -44,7 +44,7 @@
|
||||
"season": "0.14.0",
|
||||
"semver": "1.1.4",
|
||||
"space-pen": "2.0.2",
|
||||
"telepath": "0.76.0",
|
||||
"telepath": "0.77.0",
|
||||
"temp": "0.5.0",
|
||||
"underscore-plus": "0.6.1"
|
||||
},
|
||||
|
||||
@@ -34,24 +34,22 @@ class Pane extends View
|
||||
@items = []
|
||||
if args[0] instanceof TelepathicObject
|
||||
@state = args[0]
|
||||
@items = _.compact @state.get('items').map (item) ->
|
||||
item = atom.deserializers.deserialize(item)
|
||||
item?.created?()
|
||||
item
|
||||
@items = _.compact(@state.get('items').getValues())
|
||||
item?.created?() for item in @getItems()
|
||||
else
|
||||
@items = args
|
||||
@state = atom.create
|
||||
deserializer: 'Pane'
|
||||
items: @items.map (item) -> item.getState?() ? item.serialize()
|
||||
items: @items
|
||||
|
||||
@handleItemEvents(item) for item in @items
|
||||
|
||||
@subscribe @state.get('items'), 'changed', ({index, removedValues, insertedValues, siteId}) =>
|
||||
return if siteId is @state.siteId
|
||||
for itemState in removedValues
|
||||
for item in removedValues
|
||||
@removeItemAtIndex(index, updateState: false)
|
||||
for itemState, i in insertedValues
|
||||
@addItem(atom.deserializers.deserialize(itemState), index + i, updateState: false)
|
||||
for item, i in insertedValues
|
||||
@addItem(itemState, index + i, updateState: false)
|
||||
|
||||
@subscribe @state, 'changed', ({newValues, siteId}) =>
|
||||
return if siteId is @state.siteId
|
||||
@@ -185,7 +183,7 @@ class Pane extends View
|
||||
addItem: (item, index=@getActiveItemIndex()+1, options={}) ->
|
||||
return if _.include(@items, item)
|
||||
|
||||
@state.get('items').splice(index, 0, item.getState?() ? item.serialize()) if options.updateState ? true
|
||||
@state.get('items').splice(index, 0, item) if options.updateState ? true
|
||||
@items.splice(index, 0, item)
|
||||
@trigger 'pane:item-added', [item, index]
|
||||
@handleItemEvents(item)
|
||||
@@ -289,7 +287,7 @@ class Pane extends View
|
||||
oldIndex = @items.indexOf(item)
|
||||
@items.splice(oldIndex, 1)
|
||||
@items.splice(newIndex, 0, item)
|
||||
@state.get('items').insert(newIndex, item.getState?() ? item.serialize())
|
||||
@state.get('items').insert(newIndex, item)
|
||||
@trigger 'pane:item-moved', [item, newIndex]
|
||||
|
||||
# Public: Moves the given item to another pane.
|
||||
@@ -353,7 +351,7 @@ class Pane extends View
|
||||
# Private:
|
||||
serialize: ->
|
||||
state = @state.clone()
|
||||
state.set('items', item.serialize() for item, index in @items)
|
||||
state.set('items', @items)
|
||||
state.set('focused', @is(':has(:focus)'))
|
||||
state
|
||||
|
||||
|
||||
Reference in New Issue
Block a user