-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support init
or setup
returning something other than new instance
#30
Conversation
5aa7e69
to
69a5b1d
Compare
Fixed acc to feedback. Need to add docs... |
949a352
to
45d4bc9
Compare
45d4bc9
to
24fa65b
Compare
* var item = myStore[params.id]; | ||
* | ||
* // Merge new data to the existing instance: | ||
* Object.keys( params ).forEach(function( key ){ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could probably use Object.assign
here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed.
* } | ||
* }, | ||
* init: function(params){ | ||
* this.id = params.id; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Might use Object.assign
here too.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed.
* this.name = params.name; | ||
* | ||
* // Save to cache store: | ||
* myStore[this.id] = this; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should almost certainly be done in setup
. init
is usually left for people inheriting from Item
to use for their particular Item
type.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed.
* @function can-construct.ReturnValue ReturnValue | ||
* @parent can-construct.static | ||
* | ||
* A constructor function which `value` property will be used as a value for a new instance. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Too much detail for a description. It shouldn't care at all about the value
property. Maybe something like:
Use to overwrite the return value of
new Constructor(...)
.
* A constructor function which `value` property will be used as a value for a new instance. | ||
* | ||
* @signature `new Construct.ReturnValue( value )` | ||
* |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The signature should talk about how this works. Also, the example code below should be put in the signature.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed.
* | ||
* @signature `new Construct.ReturnValue( value )` | ||
* | ||
* @param {*} value A value to be used for a new instance instead of a new object. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the value
MUST be an Object type. If someone tries to return a number, it won't work.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also, indent 2 spaces @param
and other nested @
tags.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed.
* arguments to [can-construct::init init]. The following example always makes | ||
* @return {Array|undefined|can-construct.ReturnValue} If an array is returned, the array's items are passed as | ||
* arguments to [can-construct::init init]. If [can-construct.ReturnValue] is returned then the value that passed to it | ||
* will be used as a value for a new instance. The following example always makes |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Change:
If [can-construct.ReturnValue] is returned then the value that passed to it
will be used as a value for a new instance.
To something more like:
If a [can-construct.ReturnValue] instance is returned, the ReturnValue
instance's
value will be returned as the result of calling new Constructor()
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed.
3350f68
to
87b671e
Compare
init
or setup
returning something other than new instance
Allow to return special
new Construct.ReturnValue( value )
fromsetup
method, so that this value will be returned as the result ofnew Construct( ... )
: