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

define::set doc issues #1047

Closed
justinbmeyer opened this Issue Jun 4, 2014 · 4 comments

Comments

Projects
None yet
4 participants
@justinbmeyer
Contributor

justinbmeyer commented Jun 4, 2014

http://canjs.com/docs/can.Map.prototype.define.set.html

  • - code highlighting isn't working
  • - code examples are too wide
  • - merge example might not work
@shcarrico

This comment has been minimized.

Show comment
Hide comment
@shcarrico

shcarrico Jun 4, 2014

Contributor

http://jsfiddle.net/shcarrico/bkE57/9/

The above fiddle works for merged properties, but it is pretty different than the docs.

I think we need to improve this behavior. It is a valid thing to define a default value, then construct a map with said defaults, then set a value, and need to merge. If I had bound to the info property, for instance, i would always want to merge the value instead of replacing it, as otherwise my handlers will all have to be re-bound.

Contributor

shcarrico commented Jun 4, 2014

http://jsfiddle.net/shcarrico/bkE57/9/

The above fiddle works for merged properties, but it is pretty different than the docs.

I think we need to improve this behavior. It is a valid thing to define a default value, then construct a map with said defaults, then set a value, and need to merge. If I had bound to the info property, for instance, i would always want to merge the value instead of replacing it, as otherwise my handlers will all have to be re-bound.

@justinbmeyer

This comment has been minimized.

Show comment
Hide comment
@justinbmeyer

justinbmeyer Jun 4, 2014

Contributor

@shcarrico How would you improve the behavior?

On:

If I had bound to the info property, for instance, i would always want to merge the value instead of replacing it, as otherwise my handlers will all have to be re-bound.

One should typically write alice.attr("info").attr(data), to avoid rebinding, like in JS you would need to write:

$.extend(alice.info, data)

To avoid replacing .info all together.

Contributor

justinbmeyer commented Jun 4, 2014

@shcarrico How would you improve the behavior?

On:

If I had bound to the info property, for instance, i would always want to merge the value instead of replacing it, as otherwise my handlers will all have to be re-bound.

One should typically write alice.attr("info").attr(data), to avoid rebinding, like in JS you would need to write:

$.extend(alice.info, data)

To avoid replacing .info all together.

@justinbmeyer

This comment has been minimized.

Show comment
Hide comment
@justinbmeyer

justinbmeyer Jun 4, 2014

Contributor

Also, when you say:

It is a valid thing to define a default value, then construct a map with said defaults, then set a value, and need to merge.

It's nice to be able to have a setter syntax merge. But similar to JS, it might be confusing if someone did:

alice.info = data

and that extended instead of set.

I think maybe the problem is that: .attr(PROP, Object) merges by default, but .attr(PROP, Map) sets. If this is true (not 100% sure), then the problem might be that .attr's nature is ambiguous which is why making it extend might seem valid.

Contributor

justinbmeyer commented Jun 4, 2014

Also, when you say:

It is a valid thing to define a default value, then construct a map with said defaults, then set a value, and need to merge.

It's nice to be able to have a setter syntax merge. But similar to JS, it might be confusing if someone did:

alice.info = data

and that extended instead of set.

I think maybe the problem is that: .attr(PROP, Object) merges by default, but .attr(PROP, Map) sets. If this is true (not 100% sure), then the problem might be that .attr's nature is ambiguous which is why making it extend might seem valid.

@daffl daffl added the documentation label May 14, 2015

@daffl daffl modified the milestones: 2.2.6, 2.2.7 May 14, 2015

@daffl daffl removed this from the 2.2.7 milestone Jul 24, 2015

@alexisabril

This comment has been minimized.

Show comment
Hide comment
@alexisabril

alexisabril Sep 14, 2015

Contributor

I think maybe the problem is that: .attr(PROP, Object) merges by default, but .attr(PROP, Map) sets.

Both calls will set: http://jsbin.com/gozadi/edit?js,console

Contributor

alexisabril commented Sep 14, 2015

I think maybe the problem is that: .attr(PROP, Object) merges by default, but .attr(PROP, Map) sets.

Both calls will set: http://jsbin.com/gozadi/edit?js,console

@alexisabril alexisabril self-assigned this Sep 14, 2015

alexisabril added a commit that referenced this issue Sep 14, 2015

@alexisabril alexisabril modified the milestone: 2.3.0 Sep 14, 2015

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment