Skip to content
This repository was archived by the owner on Dec 15, 2022. It is now read-only.

Commit c886a0b

Browse files
as-ciiAntonio Scandurra
authored andcommitted
Update documentation for new MarkerLayer.onDidUpdate behavior
1 parent 6e326b5 commit c886a0b

File tree

4 files changed

+49
-46
lines changed

4 files changed

+49
-46
lines changed

spec/display-marker-layer-spec.coffee

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -140,26 +140,26 @@ describe "DisplayMarkerLayer", ->
140140
markerLayer.onDidUpdate (event) -> events.push({
141141
created: Array.from(event.created),
142142
updated: Array.from(event.updated),
143-
invalidated: Array.from(event.invalidated),
143+
touched: Array.from(event.touched),
144144
destroyed: Array.from(event.destroyed)
145145
})
146146

147147
events = []
148148
marker = markerLayer.markScreenRange([[0, 4], [1, 4]], {invalidate: 'inside'})
149149
expect(events).toEqual([
150-
{created: [marker.id], updated: [], invalidated: [], destroyed: []}
150+
{created: [marker.id], updated: [], touched: [], destroyed: []}
151151
])
152152

153153
events = []
154154
marker.setScreenRange([[0, 5], [1, 0]])
155155
expect(events).toEqual([
156-
{created: [], updated: [marker.id], invalidated: [], destroyed: []}
156+
{created: [], updated: [marker.id], touched: [], destroyed: []}
157157
])
158158

159159
events = []
160160
buffer.insert([0, 8], 'foo')
161161
expect(events).toEqual([
162-
{created: [], updated: [], invalidated: [marker.id], destroyed: []}
162+
{created: [], updated: [], touched: [marker.id], destroyed: []}
163163
])
164164

165165
events = []
@@ -168,10 +168,9 @@ describe "DisplayMarkerLayer", ->
168168

169169
events = []
170170
marker.destroy()
171-
expect(events.length).toBe(1)
172-
expect(Array.from(events[0].created)).toEqual []
173-
expect(Array.from(events[0].updated)).toEqual []
174-
expect(Array.from(events[0].destroyed)).toEqual [marker.id]
171+
expect(events).toEqual([
172+
{created: [], updated: [], touched: [], destroyed: [marker.id]}
173+
])
175174

176175
it "allows markers to be copied", ->
177176
buffer = new TextBuffer(text: '\ta\tbc\tdef\tg\n\th')

spec/marker-layer-spec.coffee

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ describe "MarkerLayer", ->
183183
layer.onDidUpdate (event) -> events.push({
184184
created: Array.from(event.created),
185185
updated: Array.from(event.updated),
186-
invalidated: Array.from(event.invalidated),
186+
touched: Array.from(event.touched),
187187
destroyed: Array.from(event.destroyed)
188188
})
189189

@@ -195,8 +195,8 @@ describe "MarkerLayer", ->
195195
marker3 = layer.markRange([[4, 0], [4, 5]])
196196

197197
expect(events).toEqual([
198-
{created: [marker1.id, marker2.id], updated: [], invalidated: [], destroyed: []},
199-
{created: [marker3.id], updated: [], invalidated: [], destroyed: []}
198+
{created: [marker1.id, marker2.id], updated: [], touched: [], destroyed: []},
199+
{created: [marker3.id], updated: [], touched: [], destroyed: []}
200200
])
201201

202202
events = []
@@ -206,7 +206,7 @@ describe "MarkerLayer", ->
206206
marker3.destroy()
207207

208208
expect(events).toEqual([
209-
{created: [], updated: [marker1.id, marker2.id], invalidated: [], destroyed: [marker3.id]}
209+
{created: [], updated: [marker1.id, marker2.id], touched: [], destroyed: [marker3.id]}
210210
])
211211

212212
events = []
@@ -216,17 +216,17 @@ describe "MarkerLayer", ->
216216
buffer.insert([1, 5], 'zzz')
217217

218218
expect(events).toEqual([
219-
{created: [], updated: [], invalidated: [marker1.id], destroyed: []},
220-
{created: [], updated: [], invalidated: [marker1.id], destroyed: []}
219+
{created: [], updated: [], touched: [marker1.id], destroyed: []},
220+
{created: [], updated: [], touched: [marker1.id], destroyed: []}
221221
])
222222

223223
events = []
224224
buffer.undo()
225225
buffer.undo()
226226

227227
expect(events).toEqual([
228-
{created: [], updated: [], invalidated: [marker1.id], destroyed: []},
229-
{created: [], updated: [], invalidated: [marker1.id], destroyed: []}
228+
{created: [], updated: [], touched: [marker1.id], destroyed: []},
229+
{created: [], updated: [], touched: [marker1.id], destroyed: []}
230230
])
231231

232232
events = []
@@ -240,8 +240,8 @@ describe "MarkerLayer", ->
240240
buffer.insert([4, 3], 'fff')
241241

242242
expect(events).toEqual([
243-
{created: [], updated: [], invalidated: [marker1.id, marker2.id], destroyed: []},
244-
{created: [], updated: [], invalidated: [marker2.id], destroyed: []}
243+
{created: [], updated: [], touched: [marker1.id, marker2.id], destroyed: []},
244+
{created: [], updated: [], touched: [marker2.id], destroyed: []}
245245
])
246246

247247
events = []
@@ -252,8 +252,8 @@ describe "MarkerLayer", ->
252252
marker2.clearTail()
253253

254254
expect(events).toEqual([
255-
{created: [], updated: [], invalidated: [marker2.id], destroyed: []},
256-
{created: [], updated: [marker1.id, marker2.id], invalidated: [], destroyed: []}
255+
{created: [], updated: [], touched: [marker2.id], destroyed: []},
256+
{created: [], updated: [marker1.id, marker2.id], touched: [], destroyed: []}
257257
])
258258

259259
events = []
@@ -262,7 +262,7 @@ describe "MarkerLayer", ->
262262
marker2.destroy()
263263

264264
expect(events).toEqual([
265-
{created: [], updated: [], invalidated: [], destroyed: [marker1.id, marker2.id]}
265+
{created: [], updated: [], touched: [], destroyed: [marker1.id, marker2.id]}
266266
])
267267

268268
describe "::copy", ->

src/display-marker-layer.coffee

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -34,19 +34,21 @@ class DisplayMarkerLayer
3434
onDidDestroy: (callback) ->
3535
@emitter.on('did-destroy', callback)
3636

37-
# Public: Subscribe to be notified asynchronously whenever markers are
38-
# created, updated, or destroyed on this layer. *Prefer this method for
39-
# optimal performance when interacting with layers that could contain large
40-
# numbers of markers.*
37+
# Public: Subscribe to be notified whenever markers are created, updated,
38+
# touched (moved because of a textual change), or destroyed on this layer.
39+
# *Prefer this method for optimal performance when interacting with layers
40+
# that could contain large numbers of markers.*
4141
#
4242
# * `callback` A {Function} that will be called with no arguments when changes
4343
# occur on this layer.
4444
#
45-
# Subscribers are notified once, asynchronously when any number of changes
46-
# occur in a given tick of the event loop. You should re-query the layer
47-
# to determine the state of markers in which you're interested in. It may
48-
# be counter-intuitive, but this is much more efficient than subscribing to
49-
# events on individual markers, which are expensive to deliver.
45+
# Subscribers are notified once when any number of changes occur in this
46+
# {MarkerLayer}. The notification gets scheduled either at the end of a
47+
# transaction, or synchronously when a marker changes and no transaction is
48+
# present. You should re-query the layer to determine the state of markers in
49+
# which you're interested in: it may be counter-intuitive, but this is much
50+
# more efficient than subscribing to events on individual markers, which are
51+
# expensive to deliver.
5052
#
5153
# Returns a {Disposable}.
5254
onDidUpdate: (callback) ->

src/marker-layer.coffee

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ class MarkerLayer
3333

3434
constructor: (@delegate, @id, options) ->
3535
@maintainHistory = options?.maintainHistory ? false
36-
@destroyInvalidatedMarkers = options?.destroyInvalidatedMarkers ? false
36+
@destroytouchedMarkers = options?.destroytouchedMarkers ? false
3737
@persistent = options?.persistent ? false
3838
@emitter = new Emitter
3939
@index = new MarkerIndex
@@ -42,7 +42,7 @@ class MarkerLayer
4242
@createdMarkers = new Set
4343
@destroyedMarkers = new Set
4444
@updatedMarkers = new Set
45-
@invalidatedMarkers = new Set
45+
@touchedMarkers = new Set
4646
@setDisableDidUpdateEvent(false)
4747
@destroyed = false
4848
@emitCreateMarkerEvents = false
@@ -208,19 +208,21 @@ class MarkerLayer
208208
Section: Event subscription
209209
###
210210

211-
# Public: Subscribe to be notified asynchronously whenever markers are
212-
# created, updated, or destroyed on this layer. *Prefer this method for
213-
# optimal performance when interacting with layers that could contain large
214-
# numbers of markers.*
211+
# Public: Subscribe to be notified whenever markers are created, updated,
212+
# touched (moved because of a textual change), or destroyed on this layer.
213+
# *Prefer this method for optimal performance when interacting with layers
214+
# that could contain large numbers of markers.*
215215
#
216216
# * `callback` A {Function} that will be called with no arguments when changes
217217
# occur on this layer.
218218
#
219-
# Subscribers are notified once, asynchronously when any number of changes
220-
# occur in a given tick of the event loop. You should re-query the layer
221-
# to determine the state of markers in which you're interested in. It may
222-
# be counter-intuitive, but this is much more efficient than subscribing to
223-
# events on individual markers, which are expensive to deliver.
219+
# Subscribers are notified once when any number of changes occur in this
220+
# {MarkerLayer}. The notification gets scheduled either at the end of a
221+
# transaction, or synchronously when a marker changes and no transaction is
222+
# present. You should re-query the layer to determine the state of markers in
223+
# which you're interested in: it may be counter-intuitive, but this is much
224+
# more efficient than subscribing to events on individual markers, which are
225+
# expensive to deliver.
224226
#
225227
# Returns a {Disposable}.
226228
onDidUpdate: (callback) ->
@@ -255,9 +257,9 @@ class MarkerLayer
255257
invalidated = @index.splice(start, oldExtent, newExtent)
256258
invalidated.touch.forEach (id) =>
257259
marker = @markersById[id]
258-
@invalidatedMarkers.add(id)
260+
@touchedMarkers.add(id)
259261
if invalidated[marker.getInvalidationStrategy()]?.has(id)
260-
if @destroyInvalidatedMarkers
262+
if @destroytouchedMarkers
261263
marker.destroy()
262264
else
263265
marker.valid = false
@@ -380,11 +382,11 @@ class MarkerLayer
380382
emitDidUpdateEvent: ->
381383
return if @didUpdateEventDisabled
382384

383-
if @createdMarkers.size > 0 or @destroyedMarkers.size > 0 or @invalidatedMarkers.size > 0 or @updatedMarkers.size > 0
384-
event = {created: @createdMarkers, destroyed: @destroyedMarkers, invalidated: @invalidatedMarkers, updated: @updatedMarkers}
385+
if @createdMarkers.size > 0 or @destroyedMarkers.size > 0 or @touchedMarkers.size > 0 or @updatedMarkers.size > 0
386+
event = {created: @createdMarkers, destroyed: @destroyedMarkers, touched: @touchedMarkers, updated: @updatedMarkers}
385387
@createdMarkers = new Set
386388
@destroyedMarkers = new Set
387-
@invalidatedMarkers = new Set
389+
@touchedMarkers = new Set
388390
@updatedMarkers = new Set
389391
@emitter.emit 'did-update', event
390392

0 commit comments

Comments
 (0)