Skip to content

Commit

Permalink
Change Protocol/Script registry to object
Browse files Browse the repository at this point in the history
  • Loading branch information
probins committed Feb 9, 2012
1 parent e7eae00 commit f08119b
Showing 1 changed file with 25 additions and 18 deletions.
43 changes: 25 additions & 18 deletions lib/OpenLayers/Protocol/Script.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,20 +54,12 @@ OpenLayers.Protocol.Script = OpenLayers.Class(OpenLayers.Protocol, {
callback: null,

/**
* APIProperty: scope
* {Object} Optional ``this`` object for the callback. Read-only, set
* through the options passed to the constructor.
* APIProperty: callbackTemplate
* {String} Template for creating a unique callback function name
* for the registry. Should include ${id}.
* Default is "OpenLayers.Protocol.Script.registry[${id}]".
*/
scope: null,

/**
* APIProperty: format
* {<OpenLayers.Format>} Format for parsing features. Default is an
* <OpenLayers.Format.GeoJSON> format. If an alternative is provided,
* the format's read method must take an object and return an array
* of features.
*/
format: null,
callbackTemplate: "OpenLayers.Protocol.Script.registry[${id}]",

/**
* APIProperty: callbackKey
Expand All @@ -88,6 +80,22 @@ OpenLayers.Protocol.Script = OpenLayers.Class(OpenLayers.Protocol, {
*/
callbackPrefix: "",

/**
* APIProperty: scope
* {Object} Optional ``this`` object for the callback. Read-only, set
* through the options passed to the constructor.
*/
scope: null,

/**
* APIProperty: format
* {<OpenLayers.Format>} Format for parsing features. Default is an
* <OpenLayers.Format.GeoJSON> format. If an alternative is provided,
* the format's read method must take an object and return an array
* of features.
*/
format: null,

/**
* Property: pendingRequests
* {Object} References all pending requests. Property names are script
Expand Down Expand Up @@ -212,7 +220,7 @@ OpenLayers.Protocol.Script = OpenLayers.Class(OpenLayers.Protocol, {
*/
createRequest: function(url, params, callback) {
var id = OpenLayers.Protocol.Script.register(callback);
var name = "OpenLayers.Protocol.Script.registry[" + id + "]";
var name = OpenLayers.String.format(this.callbackTemplate, {id: id});
params = OpenLayers.Util.extend({}, params);
params[this.callbackKey] = this.callbackPrefix + name;
url = OpenLayers.Util.urlAppend(
Expand Down Expand Up @@ -333,7 +341,7 @@ OpenLayers.Protocol.Script = OpenLayers.Class(OpenLayers.Protocol, {
(function() {
var o = OpenLayers.Protocol.Script;
var counter = 0;
o.registry = [];
o.registry = {};

/**
* Function: OpenLayers.Protocol.Script.register
Expand All @@ -345,12 +353,11 @@ OpenLayers.Protocol.Script = OpenLayers.Class(OpenLayers.Protocol, {
* that is the JSON returned by the service.
*
* Returns:
* {Number} An identifier for retreiving the registered callback.
* {Number} An identifier for retrieving the registered callback.
*/
o.register = function(callback) {
var id = ++counter;
var id = "c"+(++counter);
o.registry[id] = function() {
o.unregister(id);
callback.apply(this, arguments);
};
return id;
Expand Down

1 comment on commit f08119b

@tschaub
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change breaks the ArcGIS Cache JSONP example

Please sign in to comment.