Ticket #1855 (new feature)

Opened 5 years ago

Last modified 3 years ago

introduce OpenLayers.Array.getBy

Reported by: bartvde Owned by:
Priority: minor Milestone: 2.13 Release
Component: Util Version: 2.7
Keywords: Cc:
State: Needs More Work

Description

> On a side note, should the getBy function of Map.js not be a Util one?

In that case it'd look like:

function(obj, array, property, match) {
    var test = (typeof match.test == "function");
    var found = OpenLayers.Array.filter(obj[array], function(item) {
        return item[property] == match || (test && match.test(item[property]));
    });
    return found;
}

Given that Map.getBy is an API method it should remain. However it
could rely on the getBy function defined in Util.js:

getBy: function(array, property, match) {
    return OpenLayers.Util.getBy(this, array, property, match)
},

I'm +1 on adding a  getStrategyByClass method to the Layer.Vector
class and on adding a GetBy function to Util.js.

Thanks Bart,
--
Eric

Attachments

getBy.patch Download (1.6 KB) - added by crschmidt 4 years ago.

Change History

Changed 5 years ago by bartvde

Comment by Tim on the ML:

Since the obj and array args are only used there in obj[array], it 
doesn't make sense to have two args.

So, this breaks down into a function that filters an array for items 
that have a matching property.

Instead of an OpenLayers.Util.getBy function, this sounds more like an 
OpenLayers.Array.getItemsByProperty function - or something.

If people prefer the less literal util name, that's fine by me.

Tim

Changed 4 years ago by crschmidt

(In [9082]) add OpenLayers.Array.getBy. (See #1855)

Changed 4 years ago by crschmidt

Changed 4 years ago by crschmidt

  • state set to Review

Changed 4 years ago by ahocevar

  • owner set to ahocevar
  • status changed from new to assigned

Changed 4 years ago by tschaub

  • summary changed from introduce OpenLayers.Util.getBy to introduce OpenLayers.Array.getBy

Is it weird to anyone else that the other getBy style functions return an array and this one returns a single item from an array? Might be good to get a comment from Bart (or anyone else who sees the need for this).

Changed 4 years ago by bartvde

Hey Tim, I agree with your comment, it is a bit weird and inconsistent.

Changed 4 years ago by crschmidt

  • state changed from Review to Needs More Work
  • milestone changed from 2.8 Release to 2.9 Release

Okay, then; patch is no good, bumping to 2.9.

Changed 4 years ago by ahocevar

  • owner ahocevar deleted
  • status changed from assigned to new

Changed 3 years ago by fredj

  • milestone changed from 2.10 Release to 2.11 Release

patch not ready for review

Note: See TracTickets for help on using tickets.