-
Notifications
You must be signed in to change notification settings - Fork 2.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add "data" event #3255
Add "data" event #3255
Conversation
Benchmarksmap-loadmaster 24f2135: 119 ms style-loadmaster 24f2135: 109 ms buffermaster 24f2135: 961 ms fpsmaster 24f2135: 60 fps frame-durationmaster 24f2135: 6.9 ms, 0% > 16ms query-pointmaster 24f2135: 1.04 ms query-boxmaster 24f2135: 85.34 ms geojson-setdata-smallmaster 24f2135: 13 ms geojson-setdata-large |
Can you post a full rundown of the new taxonomy -- what are the valid combinations of event types and |
Below is the type specification for the interface DataEvent {
type: 'dataloading' | 'data';
dataType: (
'geoJSON' |
'tileJSON' |
'style' |
'sprite' |
'image' |
'video' |
'tile'
);
} The The |
But there's also |
What's the rationale for having separate |
The plan is to have I originally had planned to do so in this PR but the diff size was larger than I liked.
The rationale was to have a |
@@ -53,6 +53,7 @@ function ImageSource(id, options, dispatcher) { | |||
|
|||
this.image = image; | |||
this._loaded = true; | |||
this.fire('data', {type: 'image'}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
type
⇢ dataType
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed
@@ -17,6 +17,7 @@ function RasterTileSource(id, options, dispatcher) { | |||
return this.fire('error', err); | |||
} | |||
util.extend(this, tileJSON); | |||
this.fire('data', {type: 'tileJSON'}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
type
⇢ dataType
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed
@@ -7,7 +7,9 @@ module.exports = function(source, numCalls, geojson, cb) { | |||
var startTime = null; | |||
var times = []; | |||
|
|||
source.on('tile.load', function tileCounter() { | |||
source.on('data', function tileCounter(event) { | |||
if (event.dataType !== 'tile') return; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does this event binding need to distinguish between "tile loading" and "tile unloading"?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think so. I will refactor to make this benchmark utility more robust.
function Style(stylesheet, animationLoop, options) { | ||
this.animationLoop = animationLoop || new AnimationLoop(); | ||
function Style(stylesheet, map, options) { | ||
this.map = map; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've been trying to reduce or eliminate the dependency of other class on Map
. The dependency here is required by Source#on{Add,Remove}(map)
-- we should work towards eliminating those two methods.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Removing the dependency was my first instinct as well. Unfortunately it wasn't straightforward to do so and will require a standalone PR.
Even though the dependency is undesirable, it is a real dependency and should be passed explicitly and simply. As our code is architected, Source
s need to know about the state of Camera
(which is a mixin on Map
). I see #2741 as the proper long-term fix.
@@ -197,23 +197,11 @@ var Map = module.exports = function(options) { | |||
this.style.update(this._classes, {transition: false}); | |||
}); | |||
|
|||
this.on('style.change', function() { | |||
this.on('data', function() { | |||
this._update(true); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not every data
event should trigger _update(true)
-- that triggers updating and recalculating, which is necessary only in certain cases.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good catch. Fortunately it looks like filtering on event.dataType === 'style'
is equivalent to listening to the style.change
event.
All feedback addressed, ready for a second pass of 👀 @jfirebaugh |
map.on('source.load', this._update.bind(this)); | ||
map.on('source.change', this._update.bind(this)); | ||
map.on('source.remove', this._update.bind(this)); | ||
map.on('data', this._update.bind(this)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add a dataType === 'source'
guard in _update
so that it doesn't mutate the DOM more frequently than it did before.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
Thank you for the review @jfirebaugh 🙇 |
* source.change -> data * source.load -> sourceload & data * style.change -> data * style.load -> data, styleload * tile.add -> dataloading * tile.load -> data * tile.remove -> data * Unrename "source.load" and "style.load" * source.add & source.remove -> data * layer.add & layer.remove -> data * Remove isDataRemoved flag * Add documentation for "data" event * Fix setDataPerf benchmark utility * Minor doc fix * Add docs for dataloading event * merge 'sprite' and 'style' into 'style' * merge all several types into 'source' * Refactor "set data perf" benchmark utility * Ensure "Map#_update(true)" is only called after style mutations * Ensure Attribution#_update is only called for "data[dataType=source]" events * Attach Source, not SourceCache, to data events
is there a 'unload' function? |
@strech345 Not right now. Defining what it means for a tile to become "unloaded" isn't easy. Is a tile unloaded
|
@lucaswoj it the same question like for the loading. So i think it should be a equivalent to the dataloading |
This PR consolidates various undocumented data lifecycle events into the new
data
anddataloading
events.source.change
withdata
source.load
withdata
style.change
withdata
style.load
withdata
tile.add
withdataloading
tile.load
withdata
tile.remove
withdata
source.add
withdata
source.remove
withdata
layer.add
withdata
layer.remove
withdata
data
eventdataloading
eventgeoJSON
,tileJSON
,image
, andvideo
types into asource
typesprite
into thestyle
typeHaving an event per resource type per possible mutation produced a complex taxonomy of events. Understanding, documenting, and using these events was difficult. Most users did not require the level of granularity exposed by this taxonomy. Some use cases required listening to many different events.
The unified
data
event is easy to understand, document, and use. Users who require more granularity may inspect theMapDataEvent
object.cc @jfirebaugh @lbud @mollymerp @mapsam @mourner
Launch Checklist