Ticket #2529629 (accepted enhancement)

Reporter


Logan Bowers
Opened: 12/12/10
Last modified: 09/19/12
Status: accepted
Type: enhancement

Owner


Satyen Desai
Target Release: BACKLOG
Priority: P3 (normal)
Summary: Allow User-defined configuration in ATTRS
Description:

We have several Widget objects that get serialized and recreated on each page as the user navigates around the site. Some of the ATTRS on the widget need to be saved so that we can recreate the
widget on the next page load, e.g.:

var ChatWindow = Y.Base.create('chatWindow', Y.Widget, [], {
//Implementation...

function widgetState(w) {
var attrs = w._getAttrCfg(),
config = {};

Y.each(attrs, function(attr, name) {
if(attr.serialize) { config[name] = w.get(name); } // <-- BROKEN, always undefined
});
return config;
}
}, {
ATTRS: {
chat_id: {
writeOnce: true,
serialize: true //value is saved between page loads
},
unreadCount: {
value: 0,
serialize: false //Not saved between page loads
}
}
});

//This should create a duplicate of oldChatWindow
var newChatWindow = new ChatWindow(oldChatWindow.widgetState());

In the production code, we call oldChatWindow.widgetState() and store the config in sessionStorage for viewing on the next page. The problem is, however, that _getAttrCfg() does not retain all the
configuration properties of the attributes, only the ones it cares about. It would be very useful if the Attribute module retained all of the configuration parameters.

Type: enhancement Observed in Version: development master
Component: Attribute Severity: S3 (normal)
Assigned To: Satyen Desai Target Release: BACKLOG
Location: Priority: P3 (normal)
Tags: Relates To:
Browsers: N/A
URL:
Test Information:

Observed in build yui3-2929

Change History

Logan Bowers

YUI Contributor

Posted: 12/12/10

BTW, I'm working around the issue by twiddling Base._ATTR_CFG array (e.g. Y.Base._ATTR_CFG.push("serialize");). It would be nice to have a sanctioned way to do this. Is there any reason to only copy blessed config attributes? Are there any cases where the config has properties that shouldn't be copied?

Satyen Desai

YUI Developer

Posted: 01/24/11
  • milestone changed to 3.NEXT
  • priority changed to P3 (normal)
  • status changed from new to accepted

So, serialization of Widgets in general, is on our roadmap for this year [ don't know where it falls yet ]. I'd be interested in hearing what your experiences are in serializing them, and if you have any implementation you'd like to roll back in to Attribute/Base/Widget to support serialization, before we start from scratch.

Logan Bowers

YUI Contributor

Posted: 02/14/11

In our implementation of serialization, we have a mixin that defines a method, configState(). The method is defined to return an Object literal (JSON-able) that can be used as config to reconstruct the Widget. It does this by traversing the Object hierarchy, collecting the current values of all ATTRS that are marked "serialized: true" and calling a method, _configState(config) {} that each class in the hierarchy can optionally define to manipulate the config object if special processing is needed.

Absent from our mixin is any notion of what to actually do with storing/loading the config object which has thus far been completely ad-hoc in our codebase (and a bit of a code blight). I'm not sure there are any good solutions on this front, however.

I'll try to get you some easy-to-read example code in the next week or two and maybe some more detailed comments.

Brian J. Miller

YUI Contributor

Posted: 10/12/11

I think this would be very useful beyond the serialization use case. I've come across a number of places where user/developer definable properties of the attribute would be useful. I'd really like to see full fledged traits (and will open a ticket specific to that), but one simple use case I've found for simple properties is for defining which attributes should be kept when doing toJSON in Y.Model's toJSON. It would be nice to be able to do,

ATTRS: {
some_attr_foo: { value: null, toJSON: false }
}

To select attributes that should not be included when doing a "sync" operation.

Jenny Donnelly

YUI Developer

Posted: 09/19/12
  • milestone changed from 3.NEXT to BACKLOG

Moving from 3.NEXT to BACKLOG.