Ticket #992 (closed feature: fixed)

Opened 6 years ago

Last modified 6 years ago

Allow applyDefaults() to return the modified object

Reported by: fredj Owned by:
Priority: minor Milestone: 2.6 Release
Component: Util Version: SVN
Keywords: Cc:
State:

Description

OpenLayers.Util.applyDefaults(to, from) doesn't return the modified object (since r1255).

I know it's redundant to return it but can be useful in the case to 'to' object in anonymous, for example:

var my_style = OpenLayers.Util.applyDefaults({strokeColor: '#00ff00', 
                                              strokeOpacity: 0.4 }, 
                                              OpenLayers.Feature.Vector.style['default']);

Attachments

applyDefaults_return.patch Download (1.4 KB) - added by fredj 6 years ago.
return the 'to' object, unit tests

Change History

Changed 6 years ago by fredj

return the 'to' object, unit tests

  Changed 6 years ago by fredj

  • keywords review added

follow-up: ↓ 3   Changed 6 years ago by crschmidt

  • milestone set to 2.6 Release

Good for discussion after 2.5.

in reply to: ↑ 2   Changed 6 years ago by elemoine

Replying to crschmidt:

Good for discussion after 2.5.

fredj's patch makes sense to me. OpenLayers.Util.applyDefaults() should return the destination value, just like OpenLayers.Util.extend() does. Does anyone have a strong opinion against that? If not, I think we can commit this back to trunk.

  Changed 6 years ago by euzuro

patch makes sense to me too. eric if you can confirm that all tests are passing in ie/ff, then totally go ahead and approve/apply it :-)

  Changed 6 years ago by crschmidt

My only concern was that I seem to recall we used to *do* this, and then we stopped, because we had a mix of code depending half on the return value, half ont the values being updated in place. I seem to recall Erik being the one who complained about that :) If he's happy, Im' happy.

follow-up: ↓ 7   Changed 6 years ago by euzuro

jaja. this does seem like the kind of thing that i'd complain about. as eric puts it, though, it seems to make sense to me. if we return a value in extend(), we might as well return one in applyDefaults() as well.

In theory, I think it's confusing, because the user might think s/he's getting a *new* object back.... but still. i think consistency is more important.

in reply to: ↑ 6 ; follow-up: ↓ 8   Changed 6 years ago by elemoine

Replying to euzuro:

jaja. this does seem like the kind of thing that i'd complain about. as eric puts it, though, it seems to make sense to me. if we return a value in extend(), we might as well return one in applyDefaults() as well.

yeah, and there's is this anonymous dest object thing mentioned by fredj.

In theory, I think it's confusing, because the user might think s/he's getting a *new* object back.... but still. i think consistency is more important.

Tests pass on FF. As usual I don't have IE handy. I'll let fredj run the tests on IE.

in reply to: ↑ 7   Changed 6 years ago by fredj

Replying to elemoine:

Replying to euzuro:

jaja. this does seem like the kind of thing that i'd complain about. as eric puts it, though, it seems to make sense to me. if we return a value in extend(), we might as well return one in applyDefaults() as well.

yeah, and there's is this anonymous dest object thing mentioned by fredj.

In theory, I think it's confusing, because the user might think s/he's getting a *new* object back.... but still. i think consistency is more important.

Tests pass on FF. As usual I don't have IE handy. I'll let fredj run the tests on IE.

All tests pass on IE 6

  Changed 6 years ago by elemoine

  • keywords review removed
  • status changed from new to closed
  • resolution set to fixed

(In [5162]) Make OpenLayers.Util.applyDefaults() return the modified object. To be consistent with OpenLayers.Util.Extend() and be able to use anonymous object as the 'to' object. Thanks fredj for the patch and tests. Thanks euzuro and crschmidt for the reviews. (closes #992)

Note: See TracTickets for help on using tickets.