Ticket #2529337 (closed enhancement)

Reporter


Eduardo Lundgren
Opened: 09/19/10
Last modified: 08/1/12
Status: closed
Type: enhancement
Resolution: fixed

Owner


Satyen Desai
Target Release: 3.6.0
Priority: P3 (normal)
Summary: Attribute valueFn being called unnecessarily when HTML_PARSER find a Node or NodeList
Description:

Attribute valueFn being called unecessarly when HTML_PARSER find a Node or NodeList.

If some Node or NodeList is found there is no reason to the default value of the attribute be initialized. For instance:

ATTRS: {
myTitleNode: {
valueFn: function() {
return Y.Node.create('<div class="my-title"></div>');
}
}
}

HTML_PARSER: {
myTitleNode: '.my-title'
}

If the HTML_PARSER for myTitleNode query find something the valueFn of the respective attribute is called unnecessarily.

The HTML_PARSER value should prevent this to be called and a performance gain might happen.

On the method _getAttrInitVal on Attribute.js could check if there is a simple value for that attribute before call the sugar valueFn:

...
if (valFn) {
if (!Y.Lang.isValue(initValues.simple[attr])) {
val = valFn.call(this);
}
}

...

Type: enhancement Observed in Version: 3.2.0
Component: Widget Severity: S3 (normal)
Assigned To: Satyen Desai Target Release: 3.6.0
Location: Library Code Priority: P3 (normal)
Tags: Relates To:
Browsers: N/A
URL:
Test Information:

Change History

Satyen Desai

YUI Developer

Posted: 09/20/10
  • location changed to Library Code
  • milestone changed to 3.NEXT
  • priority changed to P3 (normal)
  • status changed from new to accepted

Marking 3.NEXT for now as discussed. May get it into 3.3. however, depending on how other work pans out, or if it's a major impact in terms of performance.

Satyen Desai

YUI Developer

Posted: 01/24/11
  • milestone changed from 3.NEXT to 3.4.0

Satyen Desai

YUI Developer

Posted: 07/27/11
  • milestone changed from 3.4.0 to 3.5.0

These are backlog bugs which didn't make it into any of the 3.4.0 sprints. Marking as 3.5.0 backlog for evaluation going into 3.5.0 sprint 1

Satyen Desai

YUI Developer

Posted: 11/8/11
  • estimated changed from 0 to 1.5
  • remaining changed from 0 to 1.5
  • sprint changed to sprint 1

Satyen Desai

YUI Developer

Posted: 11/8/11

Need to move to Sprint 2

Satyen Desai

YUI Developer

Posted: 11/8/11
  • sprint changed from sprint 1 to sprint 2

Satyen Desai

YUI Developer

Posted: 11/8/11

Need to move to Sprint 2

Satyen Desai

YUI Developer

Posted: 12/12/11
  • sprint changed from sprint 2 to sprint 3

Satyen Desai

YUI Developer

Posted: 01/31/12
  • milestone changed from 3.5.0 to 3.6.0

Need to move out of 3.5.0 Sprint 3 - Only 50% allocation this sprint.

Satyen Desai

YUI Developer

Posted: 04/4/12
  • sprint changed from sprint 3 to sprint 1

Satyen Desai

YUI Developer

Posted: 04/4/12

As part of this optimization, I will also be looking at allowing value to override valueFn, if value comes from a subclass (https://github.com/yui/yui3/wiki/Attribute-Wishlist)

Satyen Desai

YUI Developer

Posted: 05/8/12
  • sprint changed from sprint 1 to sprint 2

Need to move to Sprint 2, since Sprint 1 ended up going mostly towards 3.5.1

Satyen Desai

YUI Developer

Posted: 05/19/12

Here's the fix for this issue and the test, on my github fork, if you want to take a look.

https://github.com/sdesai/yui3/blob/master/build/attribute-complex/attribute-complex.js#L75
https://github.com/sdesai/yui3/blob/master/src/attribute/tests/attribute-tests.js#L1308

Not closing this out yet because:

a) Want to add a Widget HTML_PARSER test, although it should amount to the same scenario as tested above.
b) Want to also roll in the value from a subclass is allowed to override valueFn from a superclass behavior.

Satyen Desai

YUI Developer

Posted: 05/19/12
  • completed changed from 0 to 1
  • remaining changed from 1.5 to 1

Satyen Desai

YUI Developer

Posted: 05/19/12
  • completed changed from 1 to 1.5
  • remaining changed from 1 to 0.2

Also provided the solution required Y.App : to allow value in a subclass overide valueFn defined higher up in the hierarchy. Will merge into master after a little more testing

Satyen Desai

YUI Developer

Posted: 05/19/12

Commited to my github fork. Will merge to master after testing a couple of the examples. Unit tests pass.

https://github.com/sdesai/yui3/blob/master/src/base/tests/base-core-tests.js#L457

Satyen Desai

YUI Developer

Posted: 06/1/12
  • resolution changed to fixed
  • status changed from accepted to checkedin

Optimized valueFn handling, so that valueFn is not called if user provides a value.

This was true for AttributeCore already, but this optimization was missed for
Attribute.

Also refactored tests into separate HTML and JS files, moving towards travis
testable structure.

See #2529337 Not closing the bug out yet, since I also want to add the ability
for ATTRS "value" from a subclass to override "valueFn" from a superclass (Y.View
use case)
View Commit: c4c58a0fd46d6aad149b8b4ae6b1dca1a23f6f9e

Satyen Desai

YUI Developer

Posted: 06/1/12
  • completed changed from 1.5 to 2
  • remaining changed from 0.2 to 0

Jenny Donnelly

YUI Developer

Posted: 08/1/12
  • status changed from checkedin to closed

Shipped in 3.6.0. Marking closed/fixed.