Ticket #2137 (closed feature: fixed)

Opened 4 years ago

Last modified 3 years ago

Handler class constructor optimization

Reported by: dziastinux Owned by: tschaub
Priority: critical Milestone: 2.10 Release
Component: Handler Version: SVN
Keywords: Cc: dziastinux@…
State: Complete

Description

Recently I was analyzing how handlers work and found interesting block of code:

/openlayers/lib/OpenLayers/Handler.js:

102 	    initialize: function(control, callbacks, options) {
103 	        OpenLayers.Util.extend(this, options);
104 	        this.control = control;
105 	        this.callbacks = callbacks;
106 	        if (control.map) {
107 	            this.setMap(control.map);
108 	        }
109 	
110 	        OpenLayers.Util.extend(this, options);
111 	       
112 	        this.id = OpenLayers.Util.createUniqueID(this.CLASS_NAME + "_");
113 	    },

For my opinion code at line 110 is redundant. Correct me if I am wrong.

Attachments

2137.0.patch Download (450 bytes) - added by fredj 3 years ago.
remove redundant OpenLayers.Util.extend(this, options) in initialize
2137.1.patch Download (434 bytes) - added by fredj 3 years ago.
2137.2.patch Download (2.4 KB) - added by fredj 3 years ago.
call setMap with options.map or control.map.
2137.3.patch Download (3.0 KB) - added by fredj 3 years ago.
add a comment in the class constructor

Change History

  Changed 4 years ago by crschmidt

  • milestone changed from 2.8 Release to 2.9 Release

Changed 3 years ago by fredj

remove redundant OpenLayers.Util.extend(this, options) in initialize

  Changed 3 years ago by fredj

  • state set to Review
  • version changed from 2.7 to SVN

tests still pass

follow-up: ↓ 4   Changed 3 years ago by elemoine

fredj, with your patch handlers whose setMap method relies on options being set in the instance will be broken. So removing the second extend statement may make more sense.

Changed 3 years ago by fredj

in reply to: ↑ 3   Changed 3 years ago by fredj

Replying to elemoine:

fredj, with your patch handlers whose setMap method relies on options being set in the instance will be broken. So removing the second extend statement may make more sense.

You're right: attachment:"2137.1.patch" Download removes the second Util.extend.

Tests still pass.

  Changed 3 years ago by elemoine

  • state changed from Review to Commit

  Changed 3 years ago by fredj

  • status changed from new to closed
  • state changed from Commit to Complete
  • resolution set to fixed

(In [10408]) remove redundant OpenLayers.Util.extend. r=elemoine (closes #2137)

  Changed 3 years ago by fredj

  • status changed from closed to reopened
  • state Complete deleted
  • resolution fixed deleted

Regression with Overview Map:

The map is not correctly recentered

  Changed 3 years ago by fredj

With the overview map control, the map is passed in the options argument and in the control argument.

With r10408, the second Util.extend was removed: the handler map is taken from the control, not from the options.

  Changed 3 years ago by elemoine

  • priority changed from minor to critical

Changed 3 years ago by fredj

call setMap with options.map or control.map.

  Changed 3 years ago by fredj

  • state set to Review

  Changed 3 years ago by elemoine

Your patch looks good fredj. I'd like to see a comment above the declaration of the map property of the Handler class saying that providing a map option will make the constructor call setMap, and that the handler user is responsible for making sure setMap isn't called again on the handler. What do you think?

Changed 3 years ago by fredj

add a comment in the class constructor

  Changed 3 years ago by elemoine

  • state changed from Review to Commit

  Changed 3 years ago by fredj

  • status changed from reopened to closed
  • state changed from Commit to Complete
  • resolution set to fixed

(In [10434]) fix OverviewMap regression. r=elemoine (closes #2137)

Note: See TracTickets for help on using tickets.