looking at constructor.construct in facet.js, the high-level sequence is as follows:
- wrap the instance (calls schema.onWrap)
- set the default properties from the schema
- call construct from the schema if it exists
- do __noSuchMethod__ handling
- call instance.initialize for backward compat
- return instance
the question i have is why aren't the first 2 steps reversed? wouldn't it be better to pass the instance to onWrap with the defaults already set? is there something that i'm missing that would make this insecure or something? is the current order intentional?
the difficulty i'm having is that onWrap gets called in a number of different cases but the object passed to onWrap is in various states of "completeness" depending on when onWrap is called. eg when called from construct.get, the object is "complete" but when called from constructor.construct, the object has not had the default values applied yet and so is "incomplete". i'm trying to find a hook that allows me to transform "complete" instances and onWrap seems like it should be what i want to use.
looking at it some more, maybe wrapping should be the last thing before returning? this gives everything else a chance to contribute to the instance and then finally wrap it just before letting it out of our hands. it also seems that everywhere else that wrap is used, its basically the last thing in the chain before letting the instance out into the wild.
thanks,
ben...