Skip to content
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

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

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

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

imjoshdean opened this issue Nov 30, 2014 · 5 comments

Comments

@imjoshdean
Copy link
Contributor

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
Copy link
Contributor

zkat commented Nov 30, 2014

+1

@Bajix
Copy link

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
Copy link
Contributor Author

@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
Copy link

Bajix commented Dec 1, 2014

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

@imjoshdean
Copy link
Contributor Author

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
Projects
None yet
Development

No branches or pull requests

4 participants