can/map/define doesn't work more than one level deep. #1346

Closed
imjoshdean opened this Issue Nov 30, 2014 · 5 comments

Comments

Projects
None yet
4 participants
@imjoshdean
Contributor

imjoshdean commented Nov 30, 2014

This is a big problem with an easy fix. As it stands the define plugin only works one level deep; however, I've run into a lot of people express desire to have it work multiple levels deep. @akagomez and I already have this working with the following syntax:

var DefinedMap = can.Map.extend({
    define: {
        id: {
            type: 'number',
            value: 0
        },
        name: {
            define: {
                first: {
                    type: 'string',
                    value: 'First'
                },
                last: {
                    type: 'string',
                    value: 'Last'
                }
            }
        }
    }
});

Just as all Map instances have a define property, all nested objects should have one as well which define it's attributes as well.

Pretty excited to get this committed. Need to write a test and docs first though.

@zkat

This comment has been minimized.

Show comment
Hide comment
@zkat

zkat Nov 30, 2014

Contributor

+1

Contributor

zkat commented Nov 30, 2014

+1

@Bajix

This comment has been minimized.

Show comment
Hide comment
@Bajix

Bajix Dec 1, 2014

This is actually pretty easy to implement: if define is present, make a constructor and make it Type.

I can't help but wonder though, if this offers any advantage over just using Type. It actually makes things a little bit awkward, as you can't do instanceof tests, and it encourages insane nesting.

Bajix commented Dec 1, 2014

This is actually pretty easy to implement: if define is present, make a constructor and make it Type.

I can't help but wonder though, if this offers any advantage over just using Type. It actually makes things a little bit awkward, as you can't do instanceof tests, and it encourages insane nesting.

@imjoshdean

This comment has been minimized.

Show comment
Hide comment
@imjoshdean

imjoshdean Dec 1, 2014

Contributor

@Bajix The advantage it offers is a simpler and obvious syntax. We can already use type...if we extend a map. For lack of a better phrase...that's pretty poopy. I don't want to have to go through that trouble just to define an object within my map.

Contributor

imjoshdean commented Dec 1, 2014

@Bajix The advantage it offers is a simpler and obvious syntax. We can already use type...if we extend a map. For lack of a better phrase...that's pretty poopy. I don't want to have to go through that trouble just to define an object within my map.

@Bajix

This comment has been minimized.

Show comment
Hide comment
@Bajix

Bajix Dec 1, 2014

Fair enough. I can put together a PR for this if someone wants to assign it to me.

Bajix commented Dec 1, 2014

Fair enough. I can put together a PR for this if someone wants to assign it to me.

@imjoshdean

This comment has been minimized.

Show comment
Hide comment
@imjoshdean

imjoshdean Dec 1, 2014

Contributor

No need, I forgot to assign this to myself. @akagomez and I already worked on this, he is going to work on the doc updates.

Contributor

imjoshdean commented Dec 1, 2014

No need, I forgot to assign this to myself. @akagomez and I already worked on this, he is going to work on the doc updates.

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