enyo.Model constructor and parse

Currently, enyo.Model has the following code in constructor:


		// ensure we have a unique identifier that could potentially
		// be used in remote systems
		this.euid = this.euid || utils.uid('m');

		// if necessary we need to parse the incoming attributes
		attrs = attrs? parse? this.parse(attrs): attrs: null;

		// ensure we have the updated attributes
		this.attributes = this.attributes? defaults? utils.mixin({}, [defaults, this.attributes]): utils.clone(this.attributes, true): defaults? utils.clone(defaults, true): {};
		attrs && utils.mixin(this.attributes, attrs);
		this.previous = utils.clone(this.attributes);

		// now we need to ensure we have a store and register with it
		this.store = this.store || Store;

Shouldn't the following code:

		// now we need to ensure we have a store and register with it
		this.store = this.store || Store;
be ABOVE the following lines:

		// if necessary we need to parse the incoming attributes
		attrs = attrs? parse? this.parse(attrs): attrs: null;
Just in case the parse function needs access to the store to find existing models?

Comments

  • I don't think (though I'm not sure) that parse was intended to be used that way. I've only seen it used to convert a data structures between the stored format and the enyo/Model format.

    Do you have a use case for this?
  • When you have nested / related structures in your data, it is useful to check whether a model for the nested / related object has already been created. If it has, point to that; otherwise, create a new model for the nested / related object.

    In order to do that, the parse function would need access to the Store. I could add a reference to Store in parse but it would make more sense to use the one in the constructor.

    I can provide some code if that helps. Or maybe I'm just thinking about this in the wrong way?!
Sign In or Register to comment.